|
1 | 1 | # Temporal Graphs
|
2 | 2 |
|
3 |
| -Time varying graph topologies and node features are supported through the [`TemporalSnapshotsGNNGraph`](@ref) type. |
| 3 | +Temporal Graphs are graphs with time varying topologies and node features. In GraphNeuralNetworks.jl temporal graphs with fixed number of nodes over time are supported by the [`TemporalSnapshotsGNNGraph`](@ref) type. |
| 4 | + |
| 5 | +## Creating a TemporalSnapshotsGNNGraph |
| 6 | + |
| 7 | +A temporal graph can be created by passing a list of snapshots to the constructor. Each snapshot is a [`GNNGraph`](@ref). |
| 8 | + |
| 9 | +```julia-repl |
| 10 | +julia> snapshots = [rand_graph(10,20) for i in 1:5]; |
| 11 | +
|
| 12 | +julia> tg = TemporalSnapshotsGNNGraph(snapshots) |
| 13 | +TemporalSnapshotsGNNGraph: |
| 14 | + num_nodes: [10, 10, 10, 10, 10] |
| 15 | + num_edges: [20, 20, 20, 20, 20] |
| 16 | + num_snapshots: 5 |
| 17 | +``` |
| 18 | + |
| 19 | +A new temporal graph can be created by adding or removing snapshots to an existing temporal graph. |
| 20 | + |
| 21 | +```julia-repl |
| 22 | +julia> new_tg = add_snapshot(tg, 3, rand_graph(10, 16)) # add a new snapshot at time 3 |
| 23 | +TemporalSnapshotsGNNGraph: |
| 24 | + num_nodes: [10, 10, 10, 10, 10, 10] |
| 25 | + num_edges: [20, 20, 16, 20, 20, 20] |
| 26 | + num_snapshots: 6 |
| 27 | +``` |
| 28 | +```julia-repl |
| 29 | +julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)]; |
| 30 | +
|
| 31 | +julia> tg = TemporalSnapshotsGNNGraph(snapshots) |
| 32 | +TemporalSnapshotsGNNGraph: |
| 33 | + num_nodes: [10, 10, 10] |
| 34 | + num_edges: [20, 14, 22] |
| 35 | + num_snapshots: 3 |
| 36 | +
|
| 37 | +julia> new_tg = remove_snapshot(tg, 2) # remove snapshot at time 2 |
| 38 | +TemporalSnapshotsGNNGraph: |
| 39 | + num_nodes: [10, 10] |
| 40 | + num_edges: [20, 22] |
| 41 | + num_snapshots: 2 |
| 42 | +``` |
| 43 | + |
| 44 | +See [`rand_temporal_radius_graph`](@ref) and ['rand_temporal_hyperbolic_graph'](@ref) for generating random temporal graphs. |
| 45 | + |
| 46 | +```julia-repl |
| 47 | +julia> tg = rand_temporal_radius_graph(10, 3, 0.1, 0.5) |
| 48 | +TemporalSnapshotsGNNGraph: |
| 49 | + num_nodes: [10, 10, 10] |
| 50 | + num_edges: [32, 30, 34] |
| 51 | + num_snapshots: 3 |
| 52 | +``` |
| 53 | + |
| 54 | +## Basic Queries |
| 55 | + |
| 56 | +Basic queries are similar to those for [`GNNGraph`](@ref)s: |
| 57 | +```julia-repl |
| 58 | +julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)]; |
| 59 | +
|
| 60 | +julia> tg = TemporalSnapshotsGNNGraph(snapshots) |
| 61 | +TemporalSnapshotsGNNGraph: |
| 62 | + num_nodes: [10, 10, 10] |
| 63 | + num_edges: [20, 14, 22] |
| 64 | + num_snapshots: 3 |
| 65 | +
|
| 66 | +julia> tg.num_nodes # number of nodes in each snapshot |
| 67 | +3-element Vector{Int64}: |
| 68 | + 10 |
| 69 | + 10 |
| 70 | + 10 |
| 71 | +
|
| 72 | +julia> tg.num_edges # number of edges in each snapshot |
| 73 | +3-element Vector{Int64}: |
| 74 | + 20 |
| 75 | + 14 |
| 76 | + 22 |
| 77 | +
|
| 78 | +julia> tg.num_snapshots # number of snapshots |
| 79 | +3 |
| 80 | +
|
| 81 | +julia> tg.snapshots # list of snapshots |
| 82 | +3-element Vector{GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}}: |
| 83 | + GNNGraph(10, 20) with no data |
| 84 | + GNNGraph(10, 14) with no data |
| 85 | + GNNGraph(10, 22) with no data |
| 86 | +
|
| 87 | +julia> tg.snapshots[1] # first snapshot, same as tg[1] |
| 88 | +GNNGraph: |
| 89 | + num_nodes: 10 |
| 90 | + num_edges: 20 |
| 91 | +``` |
| 92 | + |
| 93 | +## Data Features |
| 94 | + |
| 95 | +Node, edge, and graph features can be added at construction time or later using: |
| 96 | + |
| 97 | +```julia-repl |
| 98 | +julia> snapshots = [rand_graph(10,20; ndata = rand(3,10)), rand_graph(10,14; ndata = rand(4,10)), rand_graph(10,22; ndata = rand(5,10))]; # node features at construction time |
| 99 | +
|
| 100 | +julia> tg = TemporalSnapshotsGNNGraph(snapshots); |
| 101 | +
|
| 102 | +julia> tg.tgdata.y = rand(3,1); # graph features after construction |
| 103 | +
|
| 104 | +julia> tg |
| 105 | +TemporalSnapshotsGNNGraph: |
| 106 | + num_nodes: [10, 10, 10] |
| 107 | + num_edges: [20, 14, 22] |
| 108 | + num_snapshots: 3 |
| 109 | + tgdata: |
| 110 | + y = 3×1 Matrix{Float64} |
| 111 | +
|
| 112 | +julia> tg.ndata # vector of Datastore for node features |
| 113 | +3-element Vector{DataStore}: |
| 114 | + DataStore(10) with 1 element: |
| 115 | + x = 3×10 Matrix{Float64} |
| 116 | + DataStore(10) with 1 element: |
| 117 | + x = 4×10 Matrix{Float64} |
| 118 | + DataStore(10) with 1 element: |
| 119 | + x = 5×10 Matrix{Float64} |
| 120 | +
|
| 121 | +julia> typeof(tg.ndata.x) # vector containing the x feature of each snapshot |
| 122 | +Vector{Matrix{Float64}} |
| 123 | +``` |
0 commit comments