easygraph.functions.graph_embedding package

Submodules

easygraph.functions.graph_embedding.NOBE module

easygraph.functions.graph_embedding.NOBE.NOBE(G, K)[source]

Graph embedding via NOBE[1].

Parameters:
  • G (easygraph.Graph) – An unweighted and undirected graph.

  • K (int) – Embedding dimension k

Returns:

Y – list of embedding vectors (y1, y2, · · · , yn)

Return type:

list

Examples

>>> NOBE(G,K=15)

References

easygraph.functions.graph_embedding.NOBE.NOBE_GA(G, K)[source]

Graph embedding via NOBE-GA[1].

Parameters:
  • G (easygraph.Graph) – An unweighted and undirected graph.

  • K (int) – Embedding dimension k

Returns:

Y – list of embedding vectors (y1, y2, · · · , yn)

Return type:

list

Examples

>>> NOBE_GA(G,K=15)

References

easygraph.functions.graph_embedding.deepwalk module

easygraph.functions.graph_embedding.deepwalk.deepwalk(G, dimensions=128, walk_length=80, num_walks=10, **skip_gram_params)[source]

Graph embedding via DeepWalk.

Parameters:
  • G (easygraph.Graph or easygraph.DiGraph) –

  • dimensions (int) – Embedding dimensions, optional(default: 128)

  • walk_length (int) – Number of nodes in each walk, optional(default: 80)

  • num_walks (int) – Number of walks per node, optional(default: 10)

  • skip_gram_params (dict) – Parameters for gensim.models.Word2Vec - do not supply size, it is taken from the dimensions parameter

Returns:

  • embedding_vector (dict) – The embedding vector of each node

  • most_similar_nodes_of_node (dict) – The most similar nodes of each node and its similarity

Examples

>>> deepwalk(G,
...          dimensions=128, # The graph embedding dimensions.
...          walk_length=80, # Walk length of each random walks.
...          num_walks=10, # Number of random walks.
...          skip_gram_params = dict( # The skip_gram parameters in Python package gensim.
...          window=10,
...             min_count=1,
...             batch_words=4,
...             iter=15
...          ))

References

easygraph.functions.graph_embedding.line module

class easygraph.functions.graph_embedding.line.LINE(dimension=128, walk_length=80, walk_num=20, negative=5, batch_size=128, init_alpha=0.025, order=3)[source]

Bases: Module

Graph embedding via LINE. :param G: :type G: easygraph.Graph or easygraph.DiGraph :param dimension: :type dimension: int :param walk_length: :type walk_length: int :param walk_num: :type walk_num: int :param negative: :type negative: int :param batch_size: :type batch_size: int :param init_alpha: :type init_alpha: float :param order: :type order: int

Returns:

embedding_vector – The embedding vector of each node

Return type:

dict

Examples

>>> model = LINE(
...          dimension=128,
...          walk_length=80,
...          walk_num=20,
...          negative=5,
...          batch_size=128,
...          init_alpha=0.025,
...          order=3  )
>>> model.train()
>>> emb = model(g, return_dict=True) # g: easygraph.Graph or easygraph.DiGraph

References

https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/frp0228-Tang.pdf

static add_args(parser)[source]

Add model-specific arguments to the parser.

classmethod build_model_from_args(args)[source]
forward(g, return_dict=True)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

easygraph.functions.graph_embedding.net_emb_example_citeseer module

easygraph.functions.graph_embedding.node2vec module

easygraph.functions.graph_embedding.node2vec.node2vec(G, dimensions=128, walk_length=80, num_walks=10, p=1.0, q=1.0, weight_key=None, workers=None, **skip_gram_params)[source]

Graph embedding via Node2Vec.

Parameters:
  • G (easygraph.Graph or easygraph.DiGraph) –

  • dimensions (int) – Embedding dimensions, optional(default: 128)

  • walk_length (int) – Number of nodes in each walk, optional(default: 80)

  • num_walks (int) – Number of walks per node, optional(default: 10)

  • p (float) – The return hyper parameter, optional(default: 1.0)

  • q (float) – The input parameter, optional(default: 1.0)

  • weight_key (string or None (default: None)) – On weighted graphs, this is the key for the weight attribute

  • workers (int or None, optional(default : None)) – The number of workers generating random walks (default: None). None if not using only one worker.

  • skip_gram_params (dict) – Parameters for gensim.models.Word2Vec - do not supply ‘size’, it is taken from the ‘dimensions’ parameter

Returns:

  • embedding_vector (dict) – The embedding vector of each node

  • most_similar_nodes_of_node (dict) – The most similar nodes of each node and its similarity

Examples

>>> node2vec(G,
...          dimensions=128, # The graph embedding dimensions.
...          walk_length=80, # Walk length of each random walks.
...          num_walks=10, # Number of random walks.
...          p=1.0, # The `p` possibility in random walk in [1]_
...          q=1.0, # The `q` possibility in random walk in [1]_
...          weight_key='weight',
...          skip_gram_params=dict( # The skip_gram parameters in Python package gensim.
...          window=10,
...             min_count=1,
...             batch_words=4
...          ))

References

easygraph.functions.graph_embedding.sdne module

class easygraph.functions.graph_embedding.sdne.Dataload(Adj, Node)[source]

Bases: Dataset

class easygraph.functions.graph_embedding.sdne.SDNE(graph, node_size, nhid0, nhid1, dropout=0.06, alpha=0.02, beta=10.0)[source]

Bases: Module

Graph embedding via SDNE.

graph : easygraph.Graph or easygraph.DiGraph

node: Size of nodes

nhid0, nhid1: Two dimensions of two hiddenlayers, default: 128, 64

dropout: One parameter for regularization, default: 0.025

alpha, beta: Twe parameters graph=g: : easygraph.Graph or easygraph.DiGraph

Examples

>>> import easygraph as eg
>>> model = eg.SDNE(graph=g, node_size= len(g.nodes), nhid0=128, nhid1=64, dropout=0.025, alpha=2e-2, beta=10)
>>> emb = model.train(model, epochs, lr, bs, step_size, gamma, nu1, nu2, device, output)

epochs, “–epochs”, default=400, type=int, help=”The training epochs of SDNE”

alpha, “–alpha”, default=2e-2, type=float, help=”alhpa is a hyperparameter in SDNE”

beta, “–beta”, default=10.0, type=float, help=”beta is a hyperparameter in SDNE”

lr, “–lr”, default=0.006, type=float, help=”learning rate”

bs, “–bs”, default=100, type=int, help=”batch size of SDNE”

step_size, “–step_size”, default=10, type=int, help=”The step size for lr”

gamma, # “–gamma”, default=0.9, type=int, help=”The gamma for lr”

step_size, “–step_size”, default=10, type=int, help=”The step size for lr”

nu1, # “–nu1”, default=1e-5, type=float, help=”nu1 is a hyperparameter in SDNE”

nu2, “–nu2”, default=1e-4, type=float, help=”nu2 is a hyperparameter in SDNE”

device, “– device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”) “

output “–output”, default=”node.emb”, help=”Output representation file”

Reference

https://www.kdd.org/kdd2016/papers/files/rfp0191-wangAemb.pdf

forward(adj_batch, adj_mat, b_mat)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

savector(adj)[source]
train(model, epochs=100, lr=0.006, bs=100, step_size=10, gamma=0.9, nu1=1e-05, nu2=0.0001, device='cpu', output='out.emb')[source]

Sets the module in training mode.

This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation mode, if they are affected, e.g. Dropout, BatchNorm, etc.

Parameters:

mode (bool) – whether to set training mode (True) or evaluation mode (False). Default: True.

Returns:

self

Return type:

Module

training: bool
easygraph.functions.graph_embedding.sdne.get_adj(g)[source]
easygraph.functions.graph_embedding.sdne.parse_args()[source]

Module contents