Graph Embedding Algorithms¶
AE Static¶
-
class
dynamicgem.embedding.ae_static.
AE
(d, *hyper_dict, **kwargs)[source]¶ Auto-Encoder based static graph embedding.
AE is a static graph embedding method which can be used as a baseline for comparing the dynamic graph embedding methods. It uses the fully connected Nueral network as its encoder and decoder.
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
n_units (list) – vector of length K-1 containing #units in hidden layers of encoder/decoder, not including the units in the embedding layer
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
Examples
>>> from dynamicgem.embedding.ae_static import AE >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 1000 >>> community_num = 2 >>> node_change_num = 10 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> embedding = AE(d=dim_emb, beta=5, nu1=1e-6, nu2=1e-6, K=3, n_units=[500, 300, ], n_iter=epochs, xeta=1e-4, n_batch=100, modelfile=['./intermediate/enc_modelsbm.json', './intermediate/dec_modelsbm.json'], weightfile=['./intermediate/enc_weightssbm.hdf5', './intermediate/dec_weightssbm.hdf5'])
>>> graphs = [g[0] for g in dynamic_sbm_series] >>> embs = []
>>> for temp_var in range(length): >>> emb, _ = embedding.learn_embeddings(graphs[temp_var]) >>> embs.append(emb)
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_embedding
(self, filesuffix=None)[source]¶ Function to load the embedding values.
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Numpy vector of embedding values
- Return type
Vector
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
DynamicAE (dyngraph2vecAE)¶
-
class
dynamicgem.embedding.dynAE.
DynAE
(d, *hyper_dict, **kwargs)[source]¶ Dynamic AutoEncoder
DynAE is a dynamic graph embedding algorithm which also takes different timestep graph with varying lookback to be considered in embedding the nodes using the autoencoder.
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
n_prev_graphs (int) – Lookback (number of previous graphs to be considered) for the dynamic graph embedding
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
rho (float) – bounding ratio for number of units in consecutive layers (< 1)
n_units (list) – vector of length K-1 containing #units in hidden layers of encoder/decoder, not including the units in the embedding layer
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
Examples
>>> from dynamicgem.embedding.dynAE import DynAE >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 1000 >>> community_num = 2 >>> node_change_num = 10 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> embedding = DynAE(d=dim_emb, beta=5, n_prev_graphs=lookback, nu1=1e-6, nu2=1e-6, n_units=[500, 300, ], rho=0.3, n_iter=epochs, xeta=args.learningrate, n_batch=args.batch, modelfile=['./intermediate/enc_model.json', './intermediate/dec_model.json'], weightfile=['./intermediate/enc_weights.hdf5', './intermediate/dec_weights.hdf5'], savefilesuffix="testing")
>>> graphs = [g[0] for g in dynamic_sbm_series] >>> embs = []
>>> for temp_var in range(length): >>> emb, _ = embedding.learn_embeddings(graphs[temp_var]) >>> embs.append(emb)
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
DynamicAERNN (dyngraph2vecAERNN)¶
-
class
dynamicgem.embedding.dynAERNN.
DynAERNN
(d, *hyper_dict, **kwargs)[source]¶ Dynamic AutoEncoder with Recurrent Neural Network
dyngraph2vecAERNN or DynAERNN is a dynamic graph embedding algorithm which combines the auto-encoder with the recurrent neural network to perform the embedding for the temporally evolving graphs.
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
n_prev_graphs (int) – Lookback (number of previous graphs to be considered) for the dynamic graph embedding
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
rho (float) – bounding ratio for number of units in consecutive layers (< 1)
n_aeunits (list) –
List of embedding dimension for lstm layers (n_lstmunits=) –
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
Examples
>>> from dynamicgem.embedding.dynAERNN import DynAERNN >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 1000 >>> community_num = 2 >>> node_change_num = 10 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> embedding = DynAERNN(d=dim_emb, beta=5, n_prev_graphs=lookback, nu1=1e-6, nu2=1e-6, n_units=[500, 300, ], rho=0.3, n_iter=epochs, xeta=args.learningrate, n_batch=args.batch, modelfile=['./intermediate/enc_model.json', './intermediate/dec_model.json'], weightfile=['./intermediate/enc_weights.hdf5', './intermediate/dec_weights.hdf5'], savefilesuffix="testing")
>>> graphs = [g[0] for g in dynamic_sbm_series] >>> embs = []
>>> for temp_var in range(length): >>> emb, _ = embedding.learn_embeddings(graphs[temp_var]) >>> embs.append(emb)
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
Dynamic TRIAD¶
-
class
dynamicgem.embedding.dynamicTriad.
dynamicTriad
(*hyper_dict, **kwargs)[source]¶ Dynamic Triad Closure based embedding
DynamicTriad preserves both structural informa- tion and evolution patterns of a given network. The general idea of our approach is to impose triad, which is a group of three vertices and is one of the basic units of networks.
- Parameters
niters (int) – Number of iteration to run the algorithm
starttime (int) – start time for the graph step
datafile (str) – The file for the input graph
batchsize (int) – batch size for training the algorithm
nsteps (int) – total number of steps in the temporal graph
embdim (int) – embedding dimension
stepsize (int) – step size for the graph
stepstride (int) – stride to consider for temporal stride
outdir (str) – The output directory to store the result
cachefn (str) – Directory to cache the temporary data
lr (float) – Learning rate for the algorithm
beta (float) – coefficients for triad component
negdup (float) – neg/pos ratio during sampling
datasetmod (str) – module name for dataset loading
trainmod (str) – module name for training model
pretrain_size (int) – size of the graph for pre-training
sampling_args (int) – sampling size
validation (list) – link_reconstruction validation data
datatype (str) – type of network data
scale (int) – scaling
classifier (str) – type of classifier to be used
debug (bool) – debugging flag
test (bool) – type of test to perform
repeat (int) – Number of times to repeat the learning
resultdir (str) – directory to store the result
testDataType (str) – type of test data
clname (str) – classifier type
node_num (int) – number of nodes
Examples
>>> from dynamicgem.embedding.dynamicTriad import dynamicTriad >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 200 >>> community_num = 2 >>> node_change_num = 2 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series]
>>> datafile = dataprep_util.prep_input_dynTriad(graphs, length, args.testDataType)
>>> embedding = dynamicTriad(niters=10, starttime=0, datafile=datafile, batchsize=10, nsteps=5, embdim=16, stepsize=1, stepstride=1, outdir='./output', cachefn='./tmp', lr=0.001, beta=0.1, negdup=1, datasetmod='dynamicgem.utils.dynamictriad_utils.dataset.adjlist', trainmod='dynamicgem.utils.dynamictriad_utils.algorithm.dynamic_triad', pretrain_size=4, sampling_args={}, validation='link_reconstruction', datatype='sbm_cd', scale=1, classifier='lr', debug=False, test='link_predict', repeat=1, resultdir='./results_link_all', testDataType='sbm_cd', clname='lr', node_num=node_num )
>>> embedding.learn_embedding() >>> embedding.get_embedding() >>> outdir = args.resultdir >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + args.testDataType >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + 'dynTRIAD' >>> if not os.path.exists(outdir): >>> os.mkdir(outdir)
>>> lp.expstaticLP_TRIAD(dynamic_sbm_series, graphs, embedding, 1, outdir + '/', 'nm' + str(args.nodemigration) + '_l' + str(args.nsteps) + '_emb' + str(args.embdim), )
-
get_edge_weight
(self, t, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, t, X=None, node_l=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
X
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Adjacency list of the given node.
- Return type
List
-
-
learn_embedding
(self)[source]¶ Learns the embedding of the nodes.
- Returns
Node embeddings and time taken by the algorithm
- Return type
List
Dynamic GEM (dynGEM)¶
-
class
dynamicgem.embedding.dynGEM.
DynGEM
(*hyper_dict, **kwargs)[source]¶ Structural Deep Network Embedding
DynSDNE (also DynGEM) perfomr the dynamic network embedding while utilizing Structural Deep Network Embedding (SDNE) with dynamically evolving graphs as input.
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
n_prev_graphs (int) – Lookback (number of previous graphs to be considered) for the dynamic graph embedding
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
rho (float) – bounding ratio for number of units in consecutive layers (< 1)
n_aeunits (list) –
List of embedding dimension for lstm layers (n_lstmunits=) –
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
Examples
>>> from dynamicgem.embedding.dynSDNE import DynSDNE >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 1000 >>> community_num = 2 >>> node_change_num = 10 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series] >>> embedding = DynSDNE(d=128, beta=5, alpha=0, nu1=1e-6, nu2=1e-6, K=3, n_units=[500, 300], n_iter=20, xeta=0.01, n_batch=500, modelfile=['./intermediate/enc_model.json', './intermediate/dec_model.json'], weightfile=['./intermediate/enc_weights.hdf5', './intermediate/dec_weights.hdf5']) >>> embedding.learn_embedding(graph=graphs._graph, edge_f=None, is_weighted=True, no_python=True)
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
Dynamic RNN (dyngraph2vecRNN)¶
-
class
dynamicgem.embedding.dynRNN.
DynRNN
(d, *hyper_dict, **kwargs)[source]¶ Dynamic embedding with Recurrent Neural Network
dyngraph2vecRNN or DynRNN is a dynamic graph embedding algorithm which uses the recurrent neural network to perform the embedding for the temporally evolving graphs.
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
n_prev_graphs (int) – Lookback (number of previous graphs to be considered) for the dynamic graph embedding
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
rho (float) – bounding ratio for number of units in consecutive layers (< 1)
n_enc_units (list) –
n_dec_units (list) –
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
Examples
>>> from dynamicgem.embedding.dynRNN import DynRNN >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 1000 >>> community_num = 2 >>> node_change_num = 10 >>> length =5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> embedding = DynRNN(d=dim_emb, beta=5, n_prev_graphs=lookback, nu1=1e-6, nu2=1e-6, n_units=[500, 300, ], rho=0.3, n_iter=epochs, xeta=args.learningrate, n_batch=args.batch, modelfile=['./intermediate/enc_model.json', './intermediate/dec_model.json'], weightfile=['./intermediate/enc_weights.hdf5', './intermediate/dec_weights.hdf5'], savefilesuffix="testing")
>>> graphs = [g[0] for g in dynamic_sbm_series] >>> embs = []
>>> for temp_var in range(length): >>> emb, _ = embedding.learn_embeddings(graphs[temp_var]) >>> embs.append(emb)
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, node_l=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
Dynamic Graph Factorization¶
-
class
dynamicgem.embedding.graphFac_dynamic.
GraphFactorization
(d, n_iter, n_iter_sub, eta, regu, kappa, initEmbed=None)[source]¶ Graph Facgorization based network embedding
It utilizes factorization based method to acquire the embedding of the graph nodes.
- Parameters
d (int) – dimension of the embedding
eta (float) – learning rate of sgd
regu (float) – regularization coefficient of magnitude of weights
beta (float) – penalty parameter in matrix B of 2nd order objective
n_iter (int) – number of sgd iterations for first embedding (const)
method_name (str) – method name
initEmbed (Matrix) – Previous timestep embedding initialized for the current timestep
Examples
>>> from dynamicgem.embedding.graphFac_dynamic import GraphFactorization >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length = 5 >>> dynamic_sbm_series = dynamic_SBM_graph.get_random_perturbation_series_v2(node_num, community_num, length, node_change_num) >>> dynamic_embeddings = GraphFactorization(100, 100, 10, 5 * 10 ** -2, 1.0, 1.0) >>> dynamic_embeddings.learn_embeddings([g[0] for g in dynamic_sbm_series])
>>> plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding(dynamic_embeddings.get_embeddings(), dynamic_sbm_series) >>> plt.show()
-
get_edge_weight
(self, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, X=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
Dynamic SDNE¶
-
class
dynamicgem.embedding.sdne_dynamic.
SDNE
(d, beta, alpha, nu1, nu2, K, n_units, rho, n_iter, n_iter_subs, xeta, n_batch, modelfile=None, weightfile=None, node_frac=1, n_walks_per_node=5, len_rw=2)[source]¶ Structural Deep Network Embedding
SDNE perform the network embedding while utilizing Structural Deep Network Embedding (SDNE).
- Parameters
d (int) – dimension of the embedding
beta (float) – penalty parameter in matrix B of 2nd order objective
n_prev_graphs (int) – Lookback (number of previous graphs to be considered) for the dynamic graph embedding
nu1 (float) – L1-reg hyperparameter
nu2 (float) – L2-reg hyperparameter
K (float) – number of hidden layers in encoder/decoder
rho (float) – bounding ratio for number of units in consecutive layers (< 1)
n_aeunits (list) –
List of embedding dimension for lstm layers (n_lstmunits=) –
n_iter (int) – number of sgd iterations for first embedding (const)
xeta (float) – sgd step size parameter
n_batch (int) – minibatch size for SGD
modelfile (str) – Files containing previous encoder and decoder models
weightfile (str) – Files containing previous encoder and decoder weights
node_frac (float) – Fraction of nodes to use for random walk
n_walks_per_node (int) – Number of random walks to do for each selected nodes
len_rw (int) – Length of every random walk
Examples
>>> from dynamicgem.embedding.sdne_dynamic import SDNE >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length = 2 >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series(node_num, community_num, length, 1, node_change_num) >>> dynamic_embedding = SDNE(d=16, beta=5, alpha=1e-5, nu1=1e-6, nu2=1e-6, K=3, n_units=[500, 300,], rho=0.3, n_iter=2, n_iter_subs=5, xeta=0.01, n_batch=500, modelfile=['./intermediate/enc_model.json', './intermediate/dec_model.json'], weightfile=['./intermediate/enc_weights.hdf5', './intermediate/dec_weights.hdf5'], node_frac=1, n_walks_per_node=10, len_rw=2) >>> dynamic_embedding.learn_embeddings([g[0] for g in dynamic_sbm_series], False, subsample=False) >>> plot_dynamic_sbm_embedding.plot_dynamic_sbm_embedding(dynamic_embedding.get_embeddings(), dynamic_sbm_series) >>> plt.savefig('result/visualization_sdne_cd.png') >>> plt.show()
-
get_edge_weight
(self, i, j, embed=None, filesuffix=None)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconst_from_embed
(self, embed, filesuffix=None)[source]¶ Function to reconstruct the graph from the embedding.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
REconstructed graph for the given nodes.
- Return type
List
-
-
get_reconstructed_adj
(self, embed=None, filesuffix=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
node_l
node for which the adjacency list will be created.
- Type
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
-
learn_embedding
(self, graph, prevStepInfo=True, loadfilesuffix=None, savefilesuffix=None, subsample=False)[source]¶ Learns the embedding of the nodes.
-
graph
¶ Networkx Graph Object
- Type
Object
-
savefilesuffix
¶ file suffix to be used for saving the data
- type
str
- Returns:
List: Node embeddings and time taken by the algorithm
-
-
learn_embeddings
(self, graphs, prevStepInfo=False, loadsuffixinfo=None, savesuffixinfo=None, subsample=False)[source]¶ Learns the embedding of the nodes.
-
graph
Networkx Graph Object
- Type
Object
-
prevStepInfo
Incorporate previous step info
- Type
-
loadfilesuffix
file suffix for loading the previos data
- Type
-
savefilesuffix
file suffix to be used for saving the data
- type
str
- Returns:
List: Node embeddings and time taken by the algorithm
-
TIMERS¶
-
class
dynamicgem.embedding.TIMERS.
TIMERS
(*hyper_dict, **kwargs)[source]¶ Timers: Dynamic graph embedding
Timers perfomrs dynamic graph embedding by utilizing the SVDS decomposition of incremental graph.
- Parameters
Args – K (int): dimension of the embedding theta (float): threshold for rerun datafile (str): location of the data file length (int) : total timesteps of the data nodemigraiton (int): number of nodes to migrate for sbm_cd datatype resultdir (str): directory to save the result datatype (str): sbm_cd, enron, academia, hep, AS
Examples
>>> from dynamicgem.embedding.TIMERS import TIMERS >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length =5 >>> resultdir='./results_link_all' >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series]
>>> datafile = dataprep_util.prep_input_TIMERS(graphs, length, args.testDataType)
>>> embedding = TIMERS(K=16, Theta=0.5, datafile=datafile, length=length, nodemigration=node_change_num, resultdir=resultdir, datatype='sbm_cd' ) >>> outdir_tmp = './output' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> outdir_tmp = outdir_tmp + '/sbm_cd' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> if not os.path.exists(outdir_tmp + '/incrementalSVD'): >>> os.mkdir(outdir_tmp + '/incrementalSVD') >>> if not os.path.exists(outdir_tmp + '/rerunSVD'): >>> os.mkdir(outdir_tmp + '/rerunSVD') >>> if not os.path.exists(outdir_tmp + '/optimalSVD'): >>> os.mkdir(outdir_tmp + '/optimalSVD')
>>> embedding.learn_embedding()
>>> outdir = resultdir >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + args.testDataType >>> if not os.path.exists(outdir): >>> os.mkdir(outdir)
>>> embedding.get_embedding(outdir_tmp, 'incrementalSVD') # embedding.plotresults() >>> outdir1 = outdir + '/incrementalSVD' >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
>>> embedding.get_embedding(outdir_tmp, 'rerunSVD') >>> outdir1 = outdir + '/rerunSVD' # embedding.plotresults() >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
>>> embedding.get_embedding(outdir_tmp, 'optimalSVD') # embedding.plotresults() >>> outdir1 = outdir + '/optimalSVD' >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
-
get_edge_weight
(self, t, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, t, X=None, node_l=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
incremental SVD¶
-
class
dynamicgem.embedding.incrementalSVD.
incSVD
(*hyper_dict, **kwargs)[source]¶ Incremental Singular Value Decomposition
Utilizes the incremental SVD decomposition to acquire the embedding of the nodes.
- Parameters
Args – K (int): dimension of the embedding theta (float): threshold for rerun datafile (str): location of the data file length (int) : total timesteps of the data nodemigraiton (int): number of nodes to migrate for sbm_cd datatype resultdir (str): directory to save the result datatype (str): sbm_cd, enron, academia, hep, AS
Examples
>>> from dynamicgem.embedding.incrementalSVD import incSVD >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length =5 >>> resultdir='./results_link_all' >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series]
>>> datafile = dataprep_util.prep_input_TIMERS(graphs, length, args.testDataType)
>>> embedding = incSVD(K=16, Theta=0.5, datafile=datafile, length=length, nodemigration=node_change_num, resultdir=resultdir, datatype='sbm_cd' ) >>> outdir_tmp = './output' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> outdir_tmp = outdir_tmp + '/sbm_cd' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> if not os.path.exists(outdir_tmp + '/incrementalSVD'): >>> os.mkdir(outdir_tmp + '/incrementalSVD') >>> embedding.learn_embedding() >>> outdir = resultdir >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + args.testDataType >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> embedding.get_embedding(outdir_tmp, 'incrementalSVD') # embedding.plotresults() >>> outdir1 = outdir + '/incrementalSVD' >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
-
get_edge_weight
(self, t, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, t, X=None, node_l=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
rerunSVD¶
-
class
dynamicgem.embedding.rerunSVD.
rerunSVD
(*hyper_dict, **kwargs)[source]¶ Timers: rerun Singular Value Decomposition
Timers perfomrs dynamic graph embedding by utilizing the SVDS decomposition of incremental graph with a bound to trigger the update.
- Parameters
Args – K (int): dimension of the embedding theta (float): threshold for rerun datafile (str): location of the data file length (int) : total timesteps of the data nodemigraiton (int): number of nodes to migrate for sbm_cd datatype resultdir (str): directory to save the result datatype (str): sbm_cd, enron, academia, hep, AS
Examples
>>> from dynamicgem.embedding.rerunSVD import rerunSVD >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length =5 >>> resultdir='./results_link_all' >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series]
>>> datafile = dataprep_util.prep_input_TIMERS(graphs, length, args.testDataType)
>>> embedding = rerunSVD(K=16, Theta=0.5, datafile=datafile, length=length, nodemigration=node_change_num, resultdir=resultdir, datatype='sbm_cd' ) >>> outdir_tmp = './output' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> outdir_tmp = outdir_tmp + '/sbm_cd' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> if not os.path.exists(outdir_tmp + '/rerunSVD'): >>> os.mkdir(outdir_tmp + '/rerunSVD') >>> embedding.learn_embedding() >>> outdir = resultdir >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + args.testDataType >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> embedding.get_embedding(outdir_tmp, 'rerunSVD') >>> outdir1 = outdir + '/rerunSVD' # embedding.plotresults() >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
-
get_edge_weight
(self, t, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, t, X=None, node_l=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
optimalSVD¶
-
class
dynamicgem.embedding.optimalSVD.
optimalSVD
(*hyper_dict, **kwargs)[source]¶ Optimal Singular Value Decomposition
It performs the SVD of each new graph.
- Parameters
Args – K (int): dimension of the embedding theta (float): threshold for rerun datafile (str): location of the data file length (int) : total timesteps of the data nodemigraiton (int): number of nodes to migrate for sbm_cd datatype resultdir (str): directory to save the result datatype (str): sbm_cd, enron, academia, hep, AS
Examples
>>> from dynamicgem.embedding.optimalSVD import optimalSVD >>> from dynamicgem.graph_generation import dynamic_SBM_graph >>> node_num = 100 >>> community_num = 2 >>> node_change_num = 2 >>> length =5 >>> resultdir='./results_link_all' >>> dynamic_sbm_series = dynamic_SBM_graph.get_community_diminish_series_v2(node_num, community_num, length, 1, node_change_num) >>> graphs = [g[0] for g in dynamic_sbm_series]
>>> datafile = dataprep_util.prep_input_TIMERS(graphs, length, args.testDataType)
>>> embedding = optimalSVD(K=16, Theta=0.5, datafile=datafile, length=length, nodemigration=node_change_num, resultdir=resultdir, datatype='sbm_cd' ) >>> outdir_tmp = './output' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> outdir_tmp = outdir_tmp + '/sbm_cd' >>> if not os.path.exists(outdir_tmp): >>> os.mkdir(outdir_tmp) >>> if not os.path.exists(outdir_tmp + '/optimalSVD'): >>> os.mkdir(outdir_tmp + '/optimalSVD') >>> embedding.learn_embedding() >>> outdir = resultdir >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> outdir = outdir + '/' + args.testDataType >>> if not os.path.exists(outdir): >>> os.mkdir(outdir) >>> embedding.get_embedding(outdir_tmp, 'optimalSVD') # embedding.plotresults() >>> outdir1 = outdir + '/optimalSVD' >>> if not os.path.exists(outdir1): >>> os.mkdir(outdir1) >>> lp.expstaticLP_TIMERS(dynamic_sbm_series, graphs, embedding, 1, outdir1 + '/', 'nm' + str(args.nodemigration) + '_l' + str(length) + '_emb' + str(int(dim_emb)), )
-
get_edge_weight
(self, t, i, j)[source]¶ Function to get edge weight.
-
embed
¶ Embedding values of all the nodes.
- Type
Matrix
- Returns
Weight of the given edge.
- Return type
Float
-
-
get_method_name
(self)[source]¶ Function to return the method name.
- Returns
Name of the method.
- Return type
String
-
get_method_summary
(self)[source]¶ Function to return the summary of the algorithm.
- Returns
Method summary
- Return type
String
-
get_reconstructed_adj
(self, t, X=None, node_l=None)[source]¶ Function to reconstruct the adjacency list for the given node.
-
embed
Embedding values of all the nodes.
- Type
Matrix
-
filesuffix
File suffix to be used to load the embedding.
- Type
- Returns
Adjacency list of the given node.
- Return type
List
-
Evaluation Functions¶
Graph Reconstruction¶
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
evaluateStaticGraphReconstruction
(digraph, graph_embedding, X_stat, node_l=None, sample_ratio_e=None, file_suffix=None, is_undirected=True, is_weighted=False)[source]¶ Function to evaluate static graph reconstruction
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
digraph
¶ Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
graph_embedding
¶ Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
X_stat
¶ Embedding values of the graph.
- Type
ndarray
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
sammple_ratio_e
¶ SAmpling ration for testing. Only sample number of nodes are tested.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
is_undirected
¶ Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
is_weighted
¶ Flag denoting if the graph has weighted edge.
- type
bool
- Returns:
ndarray: MAP, precision curve, error values and error baselines
-
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
expGR
(digraph, graph_embedding, X, n_sampled_nodes, rounds, res_pre, m_summ, file_suffix=None, is_undirected=True, sampling_scheme='rw')[source]¶ Function to evaluate graph reconstruction
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
digraph
Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
graph_embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
X_stat
Embedding values of the graph.
- Type
ndarray
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
n_sampled_nodes
¶ Total number of nodes.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
rounds
¶ Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
res_pre
¶ prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
m_summ
¶ summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_graph_reconstruction.
sampling_scheme
¶ sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
Link Prediction¶
-
dynamicgem.evaluation.evaluate_link_prediction.
evaluateDynamicLinkPrediction
(graph, embedding, rounds, n_sample_nodes=None, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate Dynamic Link Prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
graph
¶ Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
¶ Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
¶ Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
¶ Sampling scheme to be used.
- type
str
- Returns:
ndarray: MAP, precision curve
-
-
dynamicgem.evaluation.evaluate_link_prediction.
evaluateDynamicLinkPrediction_TIMERS
(graph, embedding, t, rounds, n_sample_nodes=None, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate Dynamic Link Prediction for TIMERS
-
dynamicgem.evaluation.evaluate_link_prediction.
graph
Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sample_nodes
sampled nodes
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
Sampling scheme to be used.
- type
str
- Returns:
ndarray: MAP, precision curve
-
-
dynamicgem.evaluation.evaluate_link_prediction.
evaluateDynamic_changed_LinkPrediction
(graph, embedding, rounds, edges_add, edges_rm, n_sample_nodes=None, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate dynamic changed link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
graph
Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
¶ sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
¶ Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
¶ summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
evaluateDynamic_changed_LinkPrediction_v2
(graph, embedding, rounds, edges_add, edges_rm, n_sample_nodes=None, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate dynamic changed link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
graph
Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
edges_add
list of edges to be added.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
edges_rm
list of edges to be removed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
expLP
(graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
digraph
¶ Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
graph_embedding
¶ Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
X_stat
¶ Embedding values of the graph.
- Type
ndarray
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
¶ prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
exp_changedLP
(graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate only changed link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
digraph
Networkx Graph Object
- Type
Object
-
dynamicgem.evaluation.evaluate_link_prediction.
graph_embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
X_stat
Embedding values of the graph.
- Type
ndarray
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
expstaticLP
(dynamic_sbm_series, graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate statically changed link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
dynamic_sbm_series
¶ list of Networkx Graph Object
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
expstaticLP_TIMERS
(dynamic_sbm_series, graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate statically changed link prediction for TIMERS
-
dynamicgem.evaluation.evaluate_link_prediction.
dynamic_sbm_series
list of Networkx Graph Object
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
gaphs
Networkx graphs
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
expstaticLP_TRIAD
(dynamic_sbm_series, graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate statically changed link prediction for dynamic Triad
-
dynamicgem.evaluation.evaluate_link_prediction.
dynamic_sbm_series
list of Networkx Graph Object
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
gaphs
Networkx graphs
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
-
dynamicgem.evaluation.evaluate_link_prediction.
expstatic_changedLP
(dynamic_sbm_series, graphs, embedding, rounds, res_pre, m_summ, n_sample_nodes=1000, train_ratio_init=0.5, no_python=False, is_undirected=True, sampling_scheme='u_rand')[source]¶ Function to evaluate statically changed link prediction
-
dynamicgem.evaluation.evaluate_link_prediction.
dynamic_sbm_series
list of Networkx Graph Object
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
gaphs
Networkx graphs
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
embedding
Algorithm for learning graph embedding
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
n_sampled_nodes
List of sampled nodes.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
train_ratio_init
sample to be used for training and testing.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
rounds
Number of times to run the experiment
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
res_pre
prefix to be used to store the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
m_summ
summary to be used to save the result.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
file_suffix
Suffix for file name.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
is_undirected
Flag to denote if the graph is directed.
- Type
-
dynamicgem.evaluation.evaluate_link_prediction.
sampling_scheme
sampling scheme for selecting the nodes.
- type
str
- Returns:
ndarray: Mean Average precision
-
Metrics¶
-
dynamicgem.evaluation.metrics.
checkedges
(edge_list, e)[source]¶ Function to check if the given edgelist matches.
-
dynamicgem.evaluation.metrics.
e
¶ Original edge list
- type
list
- Returns:
bool: Boolean result to denoe if all the edges matches.
-
-
dynamicgem.evaluation.metrics.
computeMAP
(predicted_edge_list, true_digraph, max_k=-1)[source]¶ Function to calculate Mean Average Precision
-
dynamicgem.evaluation.metrics.
max_k
¶ precision@k
- type
int
- Returns:
Float: Mean Average Precision score
-
-
dynamicgem.evaluation.metrics.
computeMAP_changed
(predicted_edge_list, true_digraph, node_dict, edges_rm, max_k=-1)[source]¶ Function to calculate MAP of the change graph
-
dynamicgem.evaluation.metrics.
predicted_edge_list
List of predicted edges.
- Type
-
dynamicgem.evaluation.metrics.
true_digraph
original graph
- Type
-
dynamicgem.evaluation.metrics.
node_edges_rm
¶ list of edges removed from the original graph.
- Type
-
dynamicgem.evaluation.metrics.
max_k
precision@k
- type
int
- Returns:
Float: Mean Average Precision score
-
-
dynamicgem.evaluation.metrics.
computePrecisionCurve
(predicted_edge_list, true_digraph, max_k=-1)[source]¶ Function to calculate the precision curve
-
dynamicgem.evaluation.metrics.
predicted_edge_list
List of predicted edges.
- Type
-
dynamicgem.evaluation.metrics.
true_digraph
original graph
- Type
-
dynamicgem.evaluation.metrics.
max_k
precision@k
- type
int
- Returns:
ndarray: precision_scores, delta_factors
-
-
dynamicgem.evaluation.metrics.
computePrecisionCurve_changed
(predicted_edge_list, true_digraph, node_edges_rm, max_k=-1)[source]¶ Function to calculate Preicison curve of changed graph
-
dynamicgem.evaluation.metrics.
predicted_edge_list
List of predicted edges.
- Type
-
dynamicgem.evaluation.metrics.
true_digraph
original graph
- Type
-
dynamicgem.evaluation.metrics.
node_edges_rm
list of edges removed from the original graph.
- Type
-
dynamicgem.evaluation.metrics.
max_k
precision@k
- type
int
- Returns:
Float: Mean Average Precision score
-
-
dynamicgem.evaluation.metrics.
getEmbeddingShift
(X1, X2, S1, S2)[source]¶ Function to get the shift in embedding
-
dynamicgem.evaluation.metrics.
getMetricsHeader
()[source]¶ Function to get the header for storing the result
Embedding Visualization¶
-
dynamicgem.evaluation.visualize_embedding.
expVis
(X, res_pre, m_summ, node_labels=None, di_graph=None)[source]¶ Function to perform visualixe the experiments of dynamic graph
-
dynamicgem.evaluation.visualize_embedding.
plot_embedding2D
(node_pos, node_colors=None, di_graph=None)[source]¶ Function to plot the embedding in two dimension using TSNE to reduce the dimension
Experiments¶
Config¶
Experiments¶
-
dynamicgem.experiments.exp.
call_exps
(params, data_set, n_graphs)[source]¶ Function to run the experiments
-
dynamicgem.experiments.exp.
call_plot_hyp
(data_set, params)[source]¶ Function to plot the result of hyperparameter search
-
dynamicgem.experiments.exp.
data_set
Name of the dataset to be used for the experiment
- Type
-
dynamicgem.experiments.exp.
params
Dictionary of parameters necessary for running the experiment
- Type
-
-
dynamicgem.experiments.exp.
call_plot_hyp_all
(data_sets, params)[source]¶ Function to plot the the result of all the hyper-parameters
-
dynamicgem.experiments.exp.
data_set
Name of the dataset to be used for the experiment
- Type
-
dynamicgem.experiments.exp.
params
Dictionary of parameters necessary for running the experiment
- Type
-
-
dynamicgem.experiments.exp.
choose_best_hyp
(data_set, graphs, params)[source]¶ Function to get the best hyperparameter using a grid search
-
dynamicgem.experiments.exp.
data_set
Name of the dataset to be used for the experiment
- Type
-
dynamicgem.experiments.exp.
graphs
¶ Networkx Graph Object
- Type
Object
-
dynamicgem.experiments.exp.
params
Dictionary of parameters necessary for running the experiment
- Type
-
-
dynamicgem.experiments.exp.
get_max
(val, val_max, idx, idx_max)[source]¶ Function to get the maximum value.
-
dynamicgem.experiments.exp.
learn_emb
(MethObj, graphs, params, res_pre, m_summ)[source]¶ Function to learn embedding
-
dynamicgem.experiments.exp.
MethObj
¶ Object of the algorithm class
- Type
obj
-
dynamicgem.experiments.exp.
graphs
Networkx Graph Object
- Type
Object
-
dynamicgem.experiments.exp.
params
Dictionary of parameters necessary for running the experiment
- Type
-
dynamicgem.experiments.exp.
m_summ
¶ summary added to the filename of the result.
- type
str
- Returns:
ndarray: Learned embedding
-
-
dynamicgem.experiments.exp.
run_exps
(MethObj, meth, dim, graphs, data_set, params)[source]¶ Function to run the experiment
-
dynamicgem.experiments.exp.
MethObj
Object of the algorithm class
- Type
obj
-
dynamicgem.experiments.exp.
graphs
Networkx Graph Object
- Type
Object
-
dynamicgem.experiments.exp.
data_set
Name of the dataset to be used for the experiment
- Type
-
dynamicgem.experiments.exp.
params
Dictionary of parameters necessary for running the experiment
- type
dict
- Returns:
ndarray: Learned embedding
-
Graph Generation¶
Dynamic Stochastic Block Model Graph¶
-
dynamicgem.graph_generation.dynamic_SBM_graph.
diminish_community
(sbm_graph, community_id, nodes_to_purturb, criteria, criteria_r)[source]¶ Function to diminsh the SBM community
-
dynamicgem.graph_generation.dynamic_SBM_graph.
sbm_graph
¶ Networkx Graph Object
- Type
Object
-
dynamicgem.graph_generation.dynamic_SBM_graph.
criteria
¶ Criteria used to diminish the community
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
criteria_r
¶ Used to sort the nodes in reverse once order based on criteria
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
diminish_community_v2
(sbm_graph, community_id, nodes_to_purturb, chngnodes)[source]¶ Function to diminsh the SBM community
-
dynamicgem.graph_generation.dynamic_SBM_graph.
sbm_graph
Networkx Graph Object
- Type
Object
-
dynamicgem.graph_generation.dynamic_SBM_graph.
community_id
Community to diminish
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
nodes_to_purturb
Number of nodes to perturb
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
drawGraph
(node_num, community_num)[source]¶ Function to draw the graphs
-
dynamicgem.graph_generation.dynamic_SBM_graph.
dyn_node_chng
(sbm_graph, node_id)[source]¶ Function to dynamically change the nodes
-
dynamicgem.graph_generation.dynamic_SBM_graph.
sbm_graph
Networkx Graph Object
- Type
Object
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
dyn_node_chng_v2
(sbm_graph, node_id)[source]¶ Function to dynamically change the nodes
-
dynamicgem.graph_generation.dynamic_SBM_graph.
sbm_graph
Networkx Graph Object
- Type
Object
-
dynamicgem.graph_generation.dynamic_SBM_graph.
node_id
Id of the node to resample
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
get_community_diminish_series
(node_num, community_num, length, community_id, nodes_to_purturb, criteria, criteria_r)[source]¶ Function to get diminshing community series
-
dynamicgem.graph_generation.dynamic_SBM_graph.
nodes_to_purturb
Number of nodes to perturb
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
community_id
Community to diminish
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
criteria
Criteria used to diminish the community
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
criteria_r
Used to sort the nodes in reverse once order based on criteria
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
get_community_diminish_series_v2
(node_num, community_num, length, community_id, nodes_to_purturb)[source]¶ Function to get diminishing community series
-
dynamicgem.graph_generation.dynamic_SBM_graph.
node_num
Total number of nodes
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
community_num
Total number of community
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
nodes_to_purturb
Number of nodes to perturb
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
length
Length of the graph sequence
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
community_id
Community to diminish
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
get_random_perturbation_series
(node_num, community_num, length, nodes_to_purturb)[source]¶ Function to get random perturbation
-
dynamicgem.graph_generation.dynamic_SBM_graph.
node_num
Total number of nodes
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
community_num
Total number of community
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
nodes_to_purturb
Number of nodes to perturb
- Type
-
dynamicgem.graph_generation.dynamic_SBM_graph.
length
Length of the graph sequence
- Type
-
-
dynamicgem.graph_generation.dynamic_SBM_graph.
random_node_perturbation
(sbm_graph, nodes_to_purturb)[source]¶ Function to randomly perturb the nodes
-
dynamicgem.graph_generation.dynamic_SBM_graph.
sbm_graph
Networkx Graph Object
- Type
Object
-
dynamicgem.graph_generation.dynamic_SBM_graph.
nodes_to_purturb
Number of nodes to perturb
- Type
-