def main(): # Parameters for Stochastic block model graph # Todal of 1000 nodes node_num = 1000 # Test with two communities community_num = 2 # At each iteration migrate 10 nodes from one community to the another node_change_num = 10 # Length of total time steps the graph will dynamically change length = 7 # output directory for result outdir = './output' intr = './intermediate' if not os.path.exists(outdir): os.mkdir(outdir) if not os.path.exists(intr): os.mkdir(intr) testDataType = 'sbm_cd' # Generate the dynamic graph dynamic_sbm_series = list(sbm.get_community_diminish_series_v2(node_num, community_num, length, 1, # comminity ID to perturb node_change_num)) graphs = [g[0] for g in dynamic_sbm_series] # parameters for the dynamic embedding # dimension of the embedding dim_emb = 8 lookback = 2 # dynAERNN embedding = DynAERNN(d=dim_emb, beta=5, n_prev_graphs=lookback, nu1=1e-6, nu2=1e-6, n_aeunits=[500, 300], n_lstmunits=[500, dim_emb], rho=0.3, n_iter=2, xeta=1e-3, n_batch=100, modelfile=['./intermediate/enc_model_dynAERNN.json', './intermediate/dec_model_dynAERNN.json'], weightfile=['./intermediate/enc_weights_dynAERNN.hdf5', './intermediate/dec_weights_dynAERNN.hdf5'], savefilesuffix="testing") embs = [] t1 = time() for temp_var in range(lookback + 1, length + 1): emb, _ = embedding.learn_embeddings(graphs[:temp_var]) embs.append(emb) print(embedding._method_name + ':\n\tTraining time: %f' % (time() - t1)) plt.figure() plt.clf() plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding_v2(embs[-5:-1], dynamic_sbm_series[-5:]) plt.show()
def plotresults(self, dynamic_sbm_series): """Function to plot the results""" plt.figure() plt.clf() plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding_v2(self._X[-5:-1], dynamic_sbm_series[-5:]) resultdir = self._resultdir + '/' + self._datatype if not os.path.exists(resultdir): os.mkdir(resultdir) resultdir = resultdir + '/' + self._method if not os.path.exists(resultdir): os.mkdir(resultdir) # plt.savefig('./'+resultdir+'/V_'+self._method+'_nm'+str(self._nodemigration)+'_l'+str(self._length)+'_theta'+str(theta)+'_emb'+str(self._K*2)+'.pdf',bbox_inches='tight',dpi=600) plt.show()
xeta = 1e-4, n_batch = 100, modelfile = ['./intermediate/enc_model_dynAE.json', './intermediate/dec_model_dynAE.json'], weightfile = ['./intermediate/enc_weights_dynAE.hdf5', './intermediate/dec_weights_dynAE.hdf5'], savefilesuffix = "testing" ) embs = [] t1 = time() for temp_var in range(lookback+1, length+1): emb, _ = embedding.learn_embeddings(graphs[:temp_var]) embs.append(emb) print (embedding._method_name+':\n\tTraining time: %f' % (time() - t1)) plt.figure() plt.clf() plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding_v2(embs[-5:-1], dynamic_sbm_series[-5:]) plt.show() #dynRNN embedding= DynRNN(d = dim_emb, beta = 5, n_prev_graphs = lookback, nu1 = 1e-6, nu2 = 1e-6, n_enc_units = [500,300], n_dec_units = [500,300], rho = 0.3, n_iter = 250, xeta = 1e-3, n_batch = 100, modelfile = ['./intermediate/enc_model_dynRNN.json',
def plot_dynam_graph(title, graph_list): #dynAERNN graphs = [] for graph in graph_list: if not graph == None: graphs.append(graph) dynamic_sbm_series = graphs outdir = os.path.exists(os.path.dirname(__file__)+"/out") testDataType = 'sbm_cd' length = len(graph_list) dim_emb = 128 lookback = 2 embedding = DynAERNN(d = dim_emb, beta = 5, n_prev_graphs = lookback, nu1 = 1e-6, nu2 = 1e-6, n_aeunits = [500, 300], n_lstmunits = [500,dim_emb], rho = 0.3, n_iter = 250, xeta = 1e-3, n_batch = 100, modelfile = None, #['./intermediate/enc_model_dynAERNN.json', #'./intermediate/dec_model_dynAERNN.json'], weightfile = None, #['./intermediate/enc_weights_dynAERNN.hdf5', #'./intermediate/dec_weights_dynAERNN.hdf5'], savefilesuffix = None) #"testing") embs = [] t1 = time() for temp_var in range(lookback+1, length+1): emb, _ = embedding.learn_embeddings(graphs[:temp_var]) embs.append(emb) print (embedding._method_name+':\n\tTraining time: %f' % (time() - t1)) plt.figure() plt.clf() plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding_v2(embs[-5:-1], dynamic_sbm_series[-5:]) plt.show() # #dynamicTriad datafile = dataprep_util.prep_input_dynTriad(graphs, length, testDataType) embedding= dynamicTriad(niters = 20, starttime = 0, datafile = datafile, batchsize = 1000, nsteps = length, embdim = dim_emb, stepsize = 1, stepstride = 1, outdir = outdir, cachefn = '/tmp/'+ testDataType, lr = 0.1, beta = [0.1,0.1], negdup = 1, datasetmod = 'core.dataset.adjlist', trainmod = 'dynamicgem.dynamictriad.core.algorithm.dynamic_triad', pretrain_size = length, sampling_args = {}, validation = 'link_reconstruction', datatype = testDataType, scale = 1, classifier = 'lr', debug = False, test = 'link_predict', repeat = 1, resultdir = outdir, testDataType = testDataType, clname = 'lr') #node_num = node_num ) t1 = time() embedding.learn_embedding() print (embedding._method_name+':\n\tTraining time: %f' % (time() - t1)) embedding.get_embedding() embedding.plotresults(dynamic_sbm_series)