Temporal Graphs

TemporalSnapshotsGNNGraph

Documentation page for the graph type TemporalSnapshotsGNNGraph and related methods, representing time varying graphs with time varying features.

GNNGraphs.TemporalSnapshotsGNNGraphType
TemporalSnapshotsGNNGraph(snapshots)

A type representing a time-varying graph as a sequence of snapshots, each snapshot being a GNNGraph.

The argument snapshots is a collection of GNNGraphs with arbitrary number of nodes and edges each.

Calling tg the temporal graph, tg[t] returns the t-th snapshot.

The snapshots can contain node/edge/graph features, while global features for the whole temporal sequence can be stored in tg.tgdata.

See add_snapshot and remove_snapshot for adding and removing snapshots.

Examples

julia> snapshots = [rand_graph(i , 2*i) for i in 10:10:50];

julia> tg = TemporalSnapshotsGNNGraph(snapshots)
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 20, 30, 40, 50]
  num_edges: [20, 40, 60, 80, 100]
  num_snapshots: 5

julia> tg.num_snapshots
5

julia> tg.num_nodes
5-element Vector{Int64}:
 10
 20
 30
 40
 50

julia> tg[1]
GNNGraph:
  num_nodes: 10
  num_edges: 20

julia> tg[2:3]
TemporalSnapshotsGNNGraph:
  num_nodes: [20, 30]
  num_edges: [40, 60]
  num_snapshots: 2

julia> tg[1] = rand_graph(10, 16)
GNNGraph:
  num_nodes: 10
  num_edges: 16
source
GNNGraphs.add_snapshotMethod
add_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int, g::GNNGraph)

Return a TemporalSnapshotsGNNGraph created starting from tg by adding the snapshot g at time index t.

Examples

julia> snapshots = [rand_graph(10, 20) for i in 1:5];

julia> tg = TemporalSnapshotsGNNGraph(snapshots)
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10, 10, 10, 10]
  num_edges: [20, 20, 20, 20, 20]
  num_snapshots: 5

julia> new_tg = add_snapshot(tg, 3, rand_graph(10, 16)) # add a new snapshot at time 3
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10, 10, 10, 10, 10]
  num_edges: [20, 20, 16, 20, 20, 20]
  num_snapshots: 6
source
GNNGraphs.remove_snapshotMethod
remove_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int)

Return a TemporalSnapshotsGNNGraph created starting from tg by removing the snapshot at time index t.

Examples

julia> using GNNGraphs

julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];

julia> tg = TemporalSnapshotsGNNGraph(snapshots)
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10, 10]
  num_edges: [20, 14, 22]
  num_snapshots: 3

julia> new_tg = remove_snapshot(tg, 2) # remove snapshot at time 2
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10]
  num_edges: [20, 22]
  num_snapshots: 2
source

Random Generators

GNNGraphs.rand_temporal_radius_graphFunction
rand_temporal_radius_graph(number_nodes::Int, 
                           number_snapshots::Int,
                           speed::AbstractFloat,
                           r::AbstractFloat;
                           self_loops = false,
                           dir = :in,
                           kws...)

Create a random temporal graph given number_nodes nodes and number_snapshots snapshots. First, the positions of the nodes are randomly generated in the unit square. Two nodes are connected if their distance is less than a given radius r. Each following snapshot is obtained by applying the same construction to new positions obtained as follows. For each snapshot, the new positions of the points are determined by applying random independent displacement vectors to the previous positions. The direction of the displacement is chosen uniformly at random and its length is chosen uniformly in [0, speed]. Then the connections are recomputed. If a point happens to move outside the boundary, its position is updated as if it had bounced off the boundary.

Arguments

  • number_nodes: The number of nodes of each snapshot.
  • number_snapshots: The number of snapshots.
  • speed: The speed to update the nodes.
  • r: The radius of connection.
  • self_loops: If true, consider the node itself among its neighbors, in which case the graph will contain self-loops.
  • dir: The direction of the edges. If dir=:in edges go from the neighbors to the central node. If dir=:out we have the opposite direction.
  • kws: Further keyword arguments will be passed to the GNNGraph constructor of each snapshot.

Example

julia> n, snaps, s, r = 10, 5, 0.1, 1.5;

julia> tg = rand_temporal_radius_graph(n,snaps,s,r) # complete graph at each snapshot
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10, 10, 10, 10]
  num_edges: [90, 90, 90, 90, 90]
  num_snapshots: 5
source
GNNGraphs.rand_temporal_hyperbolic_graphFunction
rand_temporal_hyperbolic_graph(number_nodes::Int, 
                               number_snapshots::Int;
                               α::Real,
                               R::Real,
                               speed::Real,
                               ζ::Real=1,
                               self_loop = false,
                               kws...)

Create a random temporal graph given number_nodes nodes and number_snapshots snapshots. First, the positions of the nodes are generated with a quasi-uniform distribution (depending on the parameter α) in hyperbolic space within a disk of radius R. Two nodes are connected if their hyperbolic distance is less than R. Each following snapshot is created in order to keep the same initial distribution.

Arguments

  • number_nodes: The number of nodes of each snapshot.
  • number_snapshots: The number of snapshots.
  • α: The parameter that controls the position of the points. If α=ζ, the points are uniformly distributed on the disk of radius R. If α>ζ, the points are more concentrated in the center of the disk. If α<ζ, the points are more concentrated at the boundary of the disk.
  • R: The radius of the disk and of connection.
  • speed: The speed to update the nodes.
  • ζ: The parameter that controls the curvature of the disk.
  • self_loops: If true, consider the node itself among its neighbors, in which case the graph will contain self-loops.
  • kws: Further keyword arguments will be passed to the GNNGraph constructor of each snapshot.

Example

julia> n, snaps, α, R, speed, ζ = 10, 5, 1.0, 4.0, 0.1, 1.0;

julia> thg = rand_temporal_hyperbolic_graph(n, snaps; α, R, speed, ζ)
TemporalSnapshotsGNNGraph:
  num_nodes: [10, 10, 10, 10, 10]
  num_edges: [44, 46, 48, 42, 38]
  num_snapshots: 5

References

Section D of the paper Dynamic Hidden-Variable Network Models and the paper Hyperbolic Geometry of Complex Networks

source