Skip to content

Commit 909df5a

Browse files
tempogral graph
1 parent ce2c266 commit 909df5a

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

GNNGraphs/docs/src/guides/temporalgraph.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CurrentModule = GNNGraphs
44

55
# Temporal Graphs
66

7-
Temporal Graphs are graphs with time varying topologies and features. In GNNGraphs.jl, temporal graphs with fixed number of nodes over time are supported by the [`TemporalSnapshotsGNNGraph`](@ref) type.
7+
Temporal Graphs are graphs with time-varying topologies and features. In GNNGraphs.jl, temporal graphs with are represented by the [`TemporalSnapshotsGNNGraph`](@ref) type.
88

99
## Creating a TemporalSnapshotsGNNGraph
1010

@@ -13,7 +13,7 @@ A temporal graph can be created by passing a list of snapshots to the constructo
1313
```jldoctest temporal
1414
julia> using GNNGraphs
1515
16-
julia> snapshots = [rand_graph(10,20) for i in 1:5];
16+
julia> snapshots = [rand_graph(10, 20) for i in 1:5];
1717
1818
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
1919
TemporalSnapshotsGNNGraph:
@@ -56,24 +56,53 @@ TemporalSnapshotsGNNGraph:
5656
num_edges: [32, 30, 34]
5757
num_snapshots: 3
5858
```
59+
## Indexing
60+
61+
Snapshots in a temporal graph can be accessed using indexing:
62+
63+
```jldoctest temporal
64+
julia> snapshots = [rand_graph(10, 20), rand_graph(10, 14), rand_graph(10, 22)];
65+
66+
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
67+
68+
julia> tg[1] # first snapshot
69+
GNNGraph:
70+
num_nodes: 10
71+
num_edges: 20
72+
73+
julia> tg[2:3] # snapshots 2 and 3
74+
TemporalSnapshotsGNNGraph:
75+
num_nodes: [10, 10]
76+
num_edges: [14, 22]
77+
num_snapshots: 2
78+
```
79+
80+
A snapshot can be modified by assigning a new snapshot to the temporal graph:
81+
82+
```jldoctest temporal
83+
julia> tg[1] = rand_graph(10, 16) # replace first snapshot
84+
GNNGraph:
85+
num_nodes: 10
86+
num_edges: 16
87+
```
5988

6089
## Basic Queries
6190

6291
Basic queries are similar to those for [`GNNGraph`](@ref)s:
6392
```jldoctest temporal
64-
julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];
93+
julia> snapshots = [rand_graph(10,20), rand_graph(12,14), rand_graph(14,22)];
6594
6695
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
6796
TemporalSnapshotsGNNGraph:
68-
num_nodes: [10, 10, 10]
97+
num_nodes: [10, 12, 14]
6998
num_edges: [20, 14, 22]
7099
num_snapshots: 3
71100
72101
julia> tg.num_nodes # number of nodes in each snapshot
73102
3-element Vector{Int64}:
74103
10
75-
10
76-
10
104+
12
105+
14
77106
78107
julia> tg.num_edges # number of edges in each snapshot
79108
3-element Vector{Int64}:
@@ -87,8 +116,8 @@ julia> tg.num_snapshots # number of snapshots
87116
julia> tg.snapshots # list of snapshots
88117
3-element Vector{GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}}:
89118
GNNGraph(10, 20) with no data
90-
GNNGraph(10, 14) with no data
91-
GNNGraph(10, 22) with no data
119+
GNNGraph(12, 14) with no data
120+
GNNGraph(14, 22) with no data
92121
93122
julia> tg.snapshots[1] # first snapshot, same as tg[1]
94123
GNNGraph:
@@ -97,7 +126,7 @@ GNNGraph:
97126
```
98127

99128
## Data Features
100-
A temporal graph can store global feature for the entire time series in the `tgdata` filed.
129+
A temporal graph can store global feature for the entire time series in the `tgdata` field.
101130
Also, each snapshot can store node, edge, and graph features in the `ndata`, `edata`, and `gdata` fields, respectively.
102131

103132
```jldoctest temporal
@@ -131,5 +160,3 @@ julia> [ds.x for ds in tg.ndata]; # vector containing the x feature of each snap
131160
julia> [g.x for g in tg.snapshots]; # same vector as above, now accessing
132161
# the x feature directly from the snapshots
133162
```
134-
135-

GNNGraphs/src/temporalsnapshotsgnngraph.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ TemporalSnapshotsGNNGraph:
4646
num_nodes: [20, 30]
4747
num_edges: [40, 60]
4848
num_snapshots: 2
49+
50+
julia> tg[1] = rand_graph(10, 16)
51+
GNNGraph:
52+
num_nodes: 10
53+
num_edges: 16
4954
```
5055
"""
5156
struct TemporalSnapshotsGNNGraph{G<:GNNGraph, D<:DataStore}

0 commit comments

Comments
 (0)