def update_h(self): # assign samples to best matching centres ... m = 1.75 tmp_dist = dist.pdist(self.W, self.data, metric='l2') + self._EPS self.H[:,:] = 0.0 for i in range(self._num_bases): for k in range(self._num_bases): self.H[i,:] += (tmp_dist[i,:]/tmp_dist[k,:])**(2.0/(m-1)) self.H = np.where(self.H>0, 1.0/self.H, 0)
def _update_h(self): # assign samples to best matching centres ... m = 1.75 tmp_dist = dist.pdist(self.W, self.data, metric='l2') + self._EPS self.H[:,:] = 0.0 for i in range(self._num_bases): for k in range(self._num_bases): self.H[i,:] += (tmp_dist[i,:]/tmp_dist[k,:])**(2.0/(m-1)) self.H = np.where(self.H>0, 1.0/self.H, 0)
def update_w(self): def h(sel, D, k): # compute the volume for a selection of sel columns # and a k-1 simplex (-> k columns have to be selected) mv = np.max(D) # fill the remaining distance by the maximal overall found distance d = np.zeros((k,k)) + mv for i in range(k): d[i,i] = 0.0 for idx_i,i in enumerate(sel): for idx_j,j in enumerate(sel): d[idx_i,idx_j] = D[i, j] return d # compute distance matrix -> required for the volume D = pdist(self.data, self.data) Openset = {} for i in range(self._num_samples): # compute volume for temp selection d = h([i],D,self._num_bases) Openset[tuple([i])] = cmdet(d) Closedset = {} finished = False self._v = [] self.init_sivm() next_sel = np.array([self.select[0]]) niter = 0 while not finished: # add the current selection to closedset Closedset[(tuple(next_sel))] = [] for i in range(D.shape[0]): # create a temp selection tmp_sel = np.array(next_sel).flatten() tmp_sel = np.concatenate((tmp_sel, [i]),axis=0) tmp_sel = np.unique(tmp_sel) tmp_sel = list(tmp_sel) hkey = tuple(tmp_sel) if len(tmp_sel) > len(next_sel) and ( not Closedset.has_key(hkey)) and ( not Openset.has_key(hkey)): # compute volume for temp selection d = h(tmp_sel, D, self._num_bases) # add to openset Openset[hkey] = cmdet(d) # get next best tuple vmax = 0.0 for (k,v) in Openset.iteritems(): if v > vmax: next_sel = k vmax = v self._logger.info('Iter:' + str(niter)) self._logger.info('Current selection:' + str(next_sel)) self._logger.info('Current volume:' + str(vmax)) self._v.append(vmax) # remove next_sel from openset Openset.pop(next_sel) if len(list(next_sel)) == self._num_bases: finished = True niter += 1 # update some values ... self.select = list(next_sel) self.W = self.data[:, self.select]
def _update_w(self): def h(sel, D, k): # compute the volume for a selection of sel columns # and a k-1 simplex (-> k columns have to be selected) mv = np.max(D) # fill the remaining distance by the maximal overall found distance d = np.zeros((k, k)) + mv for i in range(k): d[i, i] = 0.0 for idx_i, i in enumerate(sel): for idx_j, j in enumerate(sel): d[idx_i, idx_j] = D[i, j] return d # compute distance matrix -> required for the volume D = pdist(self.data, self.data) Openset = {} for i in range(self._num_samples): # compute volume for temp selection d = h([i], D, self._num_bases) Openset[tuple([i])] = cmdet(d) Closedset = {} finished = False self._v = [] self.init_sivm() next_sel = np.array([self.select[0]]) niter = 0 while not finished: # add the current selection to closedset Closedset[(tuple(next_sel))] = [] for i in range(D.shape[0]): # create a temp selection tmp_sel = np.array(next_sel).flatten() tmp_sel = np.concatenate((tmp_sel, [i]), axis=0) tmp_sel = np.unique(tmp_sel) tmp_sel = list(tmp_sel) hkey = tuple(tmp_sel) if len(tmp_sel) > len(next_sel) and ( not Closedset.has_key(hkey)) and ( not Openset.has_key(hkey)): # compute volume for temp selection d = h(tmp_sel, D, self._num_bases) # add to openset Openset[hkey] = cmdet(d) # get next best tuple vmax = 0.0 for (k, v) in Openset.iteritems(): if v > vmax: next_sel = k vmax = v self._logger.info('Iter:' + str(niter)) self._logger.info('Current selection:' + str(next_sel)) self._logger.info('Current volume:' + str(vmax)) self._v.append(vmax) # remove next_sel from openset Openset.pop(next_sel) if len(list(next_sel)) == self._num_bases: finished = True niter += 1 # update some values ... self.select = list(next_sel) self.W = self.data[:, self.select]