def run(lmd, which, times): num_iter = 1 iptdir = os.path.join(basepath, 'data/bench/' + which) optdir = os.path.join(basepath, bd + '/' + which) if not os.path.isdir(optdir): os.makedirs(optdir) list_nmi = [] list_err = [] first = True list_errmat_expected = [] list_errmat_actual = [] for i in range(1, 11): fmt = '%s.t%02d' % (which, i) log.info(fmt + '...') ipt_edges = os.path.join(iptdir, fmt + '.edges') path_gc = os.path.join(optdir, fmt + '.gc') ipt_comm1 = os.path.join(iptdir, fmt + '.comm1') path_hubs = os.path.join(optdir, fmt + '.hubs.csv') #gc.gen_gc(ipt_edges, path_gc) g = Graph() #sm.create_graph(path_gc, g) sm.create_graph(ipt_edges, g) idx_clst = sm.load_cluster_info(g, ipt_comm1) k = idx_clst.num_indices() log.info('num clusters: %d' % k) if first: lpre = 2.0**32 for i in range(num_iter): UU, HH, LL, XX = core.cdnmf(g.adjmatrix(), k) if LL[-1] < lpre: lpre = LL[-1] U, H, X = UU, HH, XX log.info('%02d -- %.4f %.4f CHANGED!' % (i + 1, LL[-1], lpre)) else: log.info('%02d -- %.4f %.4f' % (i + 1, LL[-1], lpre)) first = False else: X = core.adjust_xpre(gpre, g, X) lpre = 2.0**32 for i in range(num_iter): UU, HH, LL, XX = core.cdnmf_dynamic(g.adjmatrix(), k, X, lmd) if LL[-1] < lpre: lpre = LL[-1] U, H, X = UU, HH, XX log.info('%02d -- %.4f %.4f CHANGED!' % (i + 1, LL[-1], lpre)) else: log.info('%02d -- %.4f %.4f' % (i + 1, LL[-1], lpre)) gpre = cp.deepcopy(g) ''' ce.getcluster_bycore(g, k, U, H) ce.getcluster_rest(g, k) #ce.get_hubs(g, k, U, path_hubs) ''' getcluster_byx(g, X) nmi = sm.compute_nmi(g) list_nmi.append(nmi) e, a = sm.get_errmat(g, k) list_errmat_expected.append(e) list_errmat_actual.append(a) list_err.append(sm.compute_error(g, k)) print '===NMI===\n', len(list_nmi), nmi d = {} d['errmat_expected'] = sm.cell(list_errmat_expected) d['errmat_actual'] = sm.cell(list_errmat_actual) sio.savemat(os.path.join(optdir, 'lmd{}_times{}.mat'.format(lmd, times)), d) print '===RESULT===' for e in enumerate(list_nmi): print '{}: {}'.format(e[0] + 1, e[1]) return list_nmi, list_err
def run(filename, lmd, times): num_iter = 1 if filename != 'syn_T_10_z_4_nC_3_bS_128_aD_16.mat': return None, None ipt = os.path.join(basepath, 'data/syn/' + filename) optdir = os.path.join(basepath, 'data/result/syn/{}'.format(filename[:-4])) if not os.path.isdir(optdir): os.makedirs(optdir) list_nmi = [] list_err = [] first = True list_errmat_expected = [] list_errmat_actual = [] As, list_clsts = load_mat(ipt) for idx in range(10): log.info('%d ...' % idx) A = As[idx] list_clst = list_clsts[idx] g = Graph() idx_clst = sm.load_graph(g, A, list_clst) k = idx_clst.num_indices() log.info('num clusters: %d' % k) if first: lpre = 2.0**32 for i in range(num_iter): UU, HH, LL, XX = core.cdnmf(g.adjmatrix(), k) if LL[-1] < lpre: lpre = LL[-1] U, H, X = UU, HH, XX log.info('%02d -- %.4f %.4f CHANGED!' % (i + 1, LL[-1], lpre)) else: log.info('%02d -- %.4f %.4f' % (i + 1, LL[-1], lpre)) first = False else: X = core.adjust_xpre(gpre, g, X) lpre = 2.0**32 for i in range(num_iter): UU, HH, LL, XX = core.cdnmf_dynamic(g.adjmatrix(), k, X, lmd) if LL[-1] < lpre: lpre = LL[-1] U, H, X = UU, HH, XX log.info('%02d -- %.4f %.4f CHANGED!' % (i + 1, LL[-1], lpre)) else: log.info('%02d -- %.4f %.4f' % (i + 1, LL[-1], lpre)) gpre = cp.deepcopy(g) ''' ce.getcluster_bycore(g, k, U, H) ce.getcluster_rest(g, k) #ce.get_hubs(g, k, U, path_hubs) ''' getcluster_byx(g, X) nmi = sm.compute_nmi(g) list_nmi.append(nmi) e, a = sm.get_errmat(g, k) list_errmat_expected.append(e) list_errmat_actual.append(a) list_err.append(sm.compute_error(g, k)) print '===NMI===\n', len(list_nmi), nmi d = {} d['errmat_expected'] = sm.cell(list_errmat_expected) d['errmat_actual'] = sm.cell(list_errmat_actual) sio.savemat(os.path.join(optdir, 'lmd{}_times{}.mat'.format(lmd, times)), d) print '===RESULT===' for e in enumerate(list_nmi): print '{}: {}'.format(e[0] + 1, e[1]) return list_nmi, list_err