msaf/pymf/sivm.py
def update_w(self):
        """ compute new W """
        EPS = 10**-8
        self.init_sivm()

        # initialize some of the recursively updated distance measures ....
        d_square = np.zeros((self.data.shape[1]))
        d_sum = np.zeros((self.data.shape[1]))
        d_i_times_d_j = np.zeros((self.data.shape[1]))
        distiter = np.zeros((self.data.shape[1]))
        a = np.log(self._maxd)
        a_inc = a.copy()

        for l in range(1, self._num_bases):
            d = self._distance(self.select[l-1])

            # take the log of d (sually more stable that d)
            d = np.log(d + EPS)

            d_i_times_d_j += d * d_sum
            d_sum += d
            d_square += d**2
            distiter = d_i_times_d_j + a*d_sum - (l/2.0) * d_square

            # detect the next best data point
            self.select.append(np.argmax(distiter))

            self._logger.info('cur_nodes: ' + str(self.select))

        # sort indices, otherwise h5py won't work
        self.W = self.data[:, np.sort(self.select)]

        # "unsort" it again to keep the correct order
        self.W = self.W[:, np.argsort(np.argsort(self.select))]
def update_w(self):
        """ compute new W """
        EPS = 10**-8
        self.init_sivm()

        # initialize some of the recursively updated distance measures ....
        d_square = np.zeros((self.data.shape[1]))
        d_sum = np.zeros((self.data.shape[1]))
        d_i_times_d_j = np.zeros((self.data.shape[1]))
        distiter = np.zeros((self.data.shape[1]))
        a = np.log(self._maxd)
        a_inc = a.copy()

        for l in range(1, self._num_bases):
            d = self._distance(self.select[l-1])

            # take the log of d (sually more stable that d)
            d = np.log(d + EPS)

            d_i_times_d_j += d * d_sum
            d_sum += d
            d_square += d**2
            distiter = d_i_times_d_j + a*d_sum - (l/2.0) * d_square

            # detect the next best data point
            self.select.append(np.argmax(distiter))

            self._logger.info('cur_nodes: ' + str(self.select))

        # sort indices, otherwise h5py won't work
        self.W = self.data[:, np.sort(self.select)]

        # "unsort" it again to keep the correct order
        self.W = self.W[:, np.argsort(np.argsort(self.select))]
compute new W