G-DynaDist · Chapter 4
API reference
The Graphs4Distance and TGraph classes of GDynaDist.
The package exposes two classes:
from GDynaDist import Graphs4Distance, TGraph
You normally only interact with Graphs4Distance, which stores all graphs and computes the embeddings and distances. Each loaded graph is stored as a TGraph.
Graphs4Distance
Graphs4Distance(verbose = 2, dim = 32, n_epochs = 30, k = 1, eta = 0.8, seed = 123)
| Parameter | Type | Default | Description |
|---|---|---|---|
verbose |
int | 2 |
Verbosity level: 0 prints nothing, 1 prints some messages, 2 is the most verbose. |
dim |
int | 32 |
Embedding dimension. |
n_epochs |
int | 30 |
Number of training epochs to obtain the embeddings. |
k |
int | 1 |
Order of the Gaussian approximation of EDRep. |
eta |
float | 0.8 |
Learning rate. |
seed |
int | 123 |
Seed of the random number generator. |
Attributes: the parameters above, plus graphs, a dictionary of TGraph objects indexed by the graph names.
LoadDataset
Data.LoadDataset(df_, name, nodes = None, taumin = None, t_agg = 1.0, format = None, symmetric = True)
Loads and preprocesses a temporal graph and stores it in Data.graphs[name].
| Parameter | Type | Default | Description |
|---|---|---|---|
df_ |
pandas.DataFrame |
required | Temporal edge list with columns i, j, t (an interaction between i and j starting at time t). It may also have a column tau (the duration of the interaction) or a column w (a weight, for instantaneous interactions). |
name |
str, int or float | required | Unique identifier of the graph. |
nodes |
array | None |
List of nodes. By default, nodes are inferred from the edge list; passing them explicitly lets you include nodes that never interact. |
taumin |
int | None |
With the $(i,j,t,\tau)$ format, discretizes time. Defaults to the shortest $\tau$. |
t_agg |
float | 1.0 |
Time aggregation: interactions within the same window are considered simultaneous. Use it to reduce the number of snapshots (and speed up the computation) and to choose the time scale of the analysis. |
format |
str | None |
datetime format of the t column, e.g. '%Y-%m-%d %H:%M:%S'. Leave None if time is numeric. |
symmetric |
bool | True |
True for undirected graphs, False for directed ones. |
GraphDynamicEmbedding
Data.GraphDynamicEmbedding(name, keep_graph = False)
Computes the embedding of a temporal graph with EDRep and stores it in Data.graphs[name].X.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str, int or float | required | Identifier of the graph. |
keep_graph |
bool | False |
If False, the dataframe of the temporal graph is deleted after the embedding is computed, to save memory. |
GetDistance
Data.GetDistance(name_1, name_2, distance_type = 'unmatched', node_mapping = None)
Computes the distance between two loaded graphs. Embeddings are computed first if needed.
| Parameter | Type | Default | Description |
|---|---|---|---|
name_1, name_2 |
str, int or float | required | Identifiers of the two graphs. |
distance_type |
str | 'unmatched' |
'unmatched' or 'matched'. |
node_mapping |
dict or 'Same' |
None |
Required for the matched distance: the known bijective mapping between the nodes of the first and second graph, or 'Same' if they share the same node labels. |
Returns the distance (float).
TGraph
Container of a preprocessed temporal graph, accessible as Data.graphs[name].
| Attribute | Type | Description |
|---|---|---|
df |
pandas.DataFrame |
Preprocessed temporal edge list (deleted after embedding unless keep_graph = True). |
NodeMapper |
dict | Maps the node ids to integers $0, \dots, n-1$, the row indices of the embedding. |
n |
int | Number of nodes. |
T |
int | Number of snapshots. |
t_agg |
float | Aggregation parameter. |
taumin |
float | Shortest interaction duration used. |
X |
array | Embedding matrix (after GraphDynamicEmbedding). |
symmetric |
bool | Whether the graph is undirected. |