def execute(self, num): dlat = self.lattice.dlat Ik = self.lattice.Ik CM = self.lattice._CM() D = self.lattice.E[:, self.lattice.Kr] print('DEBUG: ', len(dlat), len(Ik), CM.shape, D.shape) clusters, score, elmlist = clusterlattice(dlat, CM, D, Ik, theta=self.theta, num_k=self.num_cluster) samplecount = np.zeros(len(clusters), dtype=np.int16) pdf = score / np.sum(score) candidates = [] for i in range(num): while True: cluster_index = int(np.random.choice(len(pdf), p=pdf)) if samplecount[cluster_index] < len(elmlist[cluster_index]): break elm, dist = elmlist[cluster_index][samplecount[cluster_index]] samplecount[cluster_index] += 1 candidates.append(elm) return candidates
def execute(self, num): dlat = self.lattice.dlat Ik = self.lattice.Ik CM = self.lattice._CM() D = self.lattice.E[:, self.lattice.Kr] print('DEBUG: ', len(dlat), len(Ik), CM.shape, D.shape) cuboids, score, elmlist = clusterlattice(dlat, CM, D, Ik, theta=self.theta, num_k=self.num_cluster) keylist = list(cuboids.keys()) candlist = [cuboids[k] for k in keylist] clu_var = {} for k, v in cuboids.items(): try: ew, ev = LA.eigh(np.cov(D[sorted(v)].T)) clu_var[k] = 10 * np.sum(ew) except LA.LinAlgError: clu_var[k] = 0 clu_size = [len(v) for v in candlist] clu_cent = [np.mean(D[list(v)], axis=0) for v in candlist] # clu_elsc = [sorted({i:LA.norm(D[i]-clu_cent[k]) for i in v}.items(), key=lambda x: x[1]) for v in candlist] clu_totD = [np.sum(D[list(v)]) / len(v) for v in candlist] clu_basc = [ sorted({i: D[i][toidx(keylist[n])].sum() for i in v}.items(), key=lambda x: x[1], reverse=True) for n, v in enumerate(candlist) ] # if print_c: # for i, k in enumerate([x[0] for x in sorted(clu_totD.items(), key=lambda p: p[1], reverse=True)]): # expt, explr = clu_basc[k][0][0], clu_elsc[k][-1][0] # print('%3d. %4d %4.2f %6.2f - %5d (%s) vs %5d (%s)' % (i, clu_size[k], clu_var[k], clu_totD[k], expt, rlab(expt), explr, rlab(explr))) samplecount = np.zeros(len(cuboids), dtype=np.int16) score = clu_totD pdf = score / np.sum(score) candidates = [] for i in range(num): while True: cluster_index = int(np.random.choice(len(pdf), p=pdf)) if samplecount[cluster_index] < len(candlist[cluster_index]): break # elm = candlist[cluster_index][samplecount[cluster_index]] elm, _ = clu_basc[cluster_index][samplecount[cluster_index]] samplecount[cluster_index] += 1 candidates.append(elm) return candidates
def execute(self, num): dlat = self.lattice.dlat Ik = self.lattice.Ik CM = self.lattice._CM() D = self.lattice.E[:, self.lattice.Kr] print("DEBUG: ", len(dlat), len(Ik), CM.shape, D.shape) cuboids, score, elmlist = clusterlattice(dlat, CM, D, Ik, theta=self.theta, num_k=self.num_cluster) keylist = list(cuboids.keys()) candlist = [cuboids[k] for k in keylist] clu_var = {} for k, v in cuboids.items(): try: ew, ev = LA.eigh(np.cov(D[sorted(v)].T)) clu_var[k] = 10 * np.sum(ew) except LA.LinAlgError: clu_var[k] = 0 clu_size = [len(v) for v in candlist] clu_cent = [np.mean(D[list(v)], axis=0) for v in candlist] # clu_elsc = [sorted({i:LA.norm(D[i]-clu_cent[k]) for i in v}.items(), key=lambda x: x[1]) for v in candlist] clu_totD = [np.sum(D[list(v)]) / len(v) for v in candlist] clu_basc = [ sorted({i: D[i][toidx(keylist[n])].sum() for i in v}.items(), key=lambda x: x[1], reverse=True) for n, v in enumerate(candlist) ] # if print_c: # for i, k in enumerate([x[0] for x in sorted(clu_totD.items(), key=lambda p: p[1], reverse=True)]): # expt, explr = clu_basc[k][0][0], clu_elsc[k][-1][0] # print('%3d. %4d %4.2f %6.2f - %5d (%s) vs %5d (%s)' % (i, clu_size[k], clu_var[k], clu_totD[k], expt, rlab(expt), explr, rlab(explr))) samplecount = np.zeros(len(cuboids), dtype=np.int16) score = clu_totD pdf = score / np.sum(score) candidates = [] for i in range(num): while True: cluster_index = int(np.random.choice(len(pdf), p=pdf)) if samplecount[cluster_index] < len(candlist[cluster_index]): break # elm = candlist[cluster_index][samplecount[cluster_index]] elm, _ = clu_basc[cluster_index][samplecount[cluster_index]] samplecount[cluster_index] += 1 candidates.append(elm) return candidates
def execute(self, num): dlat = self.lattice.dlat Ik = self.lattice.Ik CM = self.lattice._CM() D = self.lattice.E[:, self.lattice.Kr] print("DEBUG: ", len(dlat), len(Ik), CM.shape, D.shape) clusters, score, elmlist = clusterlattice(dlat, CM, D, Ik, theta=self.theta, num_k=self.num_cluster) samplecount = np.zeros(len(clusters), dtype=np.int16) pdf = score / np.sum(score) candidates = [] for i in range(num): while True: cluster_index = int(np.random.choice(len(pdf), p=pdf)) if samplecount[cluster_index] < len(elmlist[cluster_index]): break elm, dist = elmlist[cluster_index][samplecount[cluster_index]] samplecount[cluster_index] += 1 candidates.append(elm) return candidates
len(dlat) logging.info('\n\n----------------------') logging.info('SIZE,iset,%d', len(iset)) logging.info('SIZE,dlat,%d', len(dlat)) logging.info('Clustering Lattice:') SKIPCLU = False if SKIPCLU: clu = pickle.load(open('clu.p', 'rb')) score = pickle.load(open('score.p', 'rb')) elmlist = pickle.load(open('elmlist.p', 'rb')) else: clu, score, elmlist = lat.clusterlattice(dlat, CMr, Dm, iset, num_k=num_clu) cluk = list(clu.keys()) clulist = [clu[k] for k in cluk] variance = np.zeros(len(cluk)) for n, k in enumerate(cluk): if len(clulist[n]) == 1: continue cov = np.cov(DS[clulist[n]][:, Km].T) ew, _ = LA.eigh(cov) variance[n] = np.sum(ew) variance2 = np.zeros(len(cluk))
iset = pickle.load(open(home + '/work/latt_intrinsics/iset_%d.p' % support, 'rb')); len(iset) dlat = pickle.load(open(home + '/work/latt_intrinsics/dlat_%d.p' % support, 'rb')); len(dlat) logging.info('\n\n----------------------') logging.info('SIZE,iset,%d', len(iset)) logging.info('SIZE,dlat,%d', len(dlat)) logging.info('Clustering Lattice:') SKIPCLU = False if SKIPCLU: clu = pickle.load(open('clu.p', 'rb')) score = pickle.load(open('score.p', 'rb')) elmlist = pickle.load(open('elmlist.p', 'rb')) else: clu, score, elmlist = lat.clusterlattice(dlat, CMr, Dm, iset, num_k=num_clu) cluk = list(clu.keys()) clulist = [clu[k] for k in cluk] variance = np.zeros(len(cluk)) for n, k in enumerate(cluk): if len(clulist[n]) == 1: continue cov = np.cov(DS[clulist[n]][:,Km].T) ew,_ = LA.eigh(cov) variance[n] = np.sum(ew) variance2 = np.zeros(len(cluk)) for n, k in enumerate(cluk): if len(clulist[n]) == 1: