Skip to content

Commit 8c542c5

Browse files
authored
Add docstrings for TemporalSnapshotsGNNgraph (#294)
* Add struct docstring * Add `remove/add_snapshots` docstrings * Add examples
1 parent 65c0faa commit 8c542c5

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/GNNGraphs/temporalsnapshotsgnngraph.jl

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
"""
2+
TemporalSnapshotsGNNGraph(snapshots::AbstractVector{<:GNNGraph})
3+
4+
A type representing a temporal graph as a sequence of snapshots, in this case a snapshot is a [`GNNGraph`](@ref).
5+
6+
It stores the feature array associated to the graph itself as a [`DataStore`](@ref) object, and it uses the [`DataStore`](@ref) objects of each snapshot for the node and edge features.
7+
The features can be passed at construction time or added later.
8+
9+
# Arguments
10+
- snapshot: a vector of snapshots, each snapshot must have the same number of nodes.
11+
12+
# Examples
13+
```julia
14+
julia> using GraphNeuralNetworks
15+
16+
julia> snapshots = [rand_graph(10,20) for i in 1:5];
17+
18+
julia> tgs = TemporalSnapshotsGNNGraph(snapshots)
19+
TemporalSnapshotsGNNGraph:
20+
num_nodes: [10, 10, 10, 10, 10]
21+
num_edges: [20, 20, 20, 20, 20]
22+
num_snapshots: 5
23+
24+
julia> tgs.tgdata.x = rand(4); # add temporal graph feature
25+
26+
julia> tgs # show temporal graph with new feature
27+
TemporalSnapshotsGNNGraph:
28+
num_nodes: [10, 10, 10, 10, 10]
29+
num_edges: [20, 20, 20, 20, 20]
30+
num_snapshots: 5
31+
tgdata:
32+
x = 4-element Vector{Float64}
33+
```
34+
"""
135
struct TemporalSnapshotsGNNGraph
236
num_nodes::Vector{Int}
337
num_edges::Vector{Int}
@@ -33,6 +67,30 @@ function Base.getindex(tg::TemporalSnapshotsGNNGraph, t::AbstractVector)
3367
return TemporalSnapshotsGNNGraph(tg.num_nodes[t], tg.num_edges[t], length(t), tg.snapshots[t], tg.tgdata)
3468
end
3569

70+
"""
71+
add_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int, g::GNNGraph)
72+
73+
Return a `TemporalSnapshotsGNNGraph` created starting from `tg` by adding the snapshot `g` at time index `t`.
74+
75+
# Example
76+
```julia
77+
julia> using GraphNeuralNetworks
78+
79+
julia> snapshots = [rand_graph(10,20) for i in 1:5];
80+
81+
julia> tgs = TemporalSnapshotsGNNGraph(snapshots)
82+
TemporalSnapshotsGNNGraph:
83+
num_nodes: [10, 10, 10, 10, 10]
84+
num_edges: [20, 20, 20, 20, 20]
85+
num_snapshots: 5
86+
87+
julia> new_tgs = add_snapshot(tgs, 3, rand_graph(10,16)) # add a new snapshot at time 3
88+
TemporalSnapshotsGNNGraph:
89+
num_nodes: [10, 10, 10, 10, 10, 10]
90+
num_edges: [20, 20, 16, 20, 20, 20]
91+
num_snapshots: 6
92+
```
93+
"""
3694
function add_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int, g::GNNGraph)
3795
@assert g.num_nodes == tg.num_nodes[t] "number of nodes must match"
3896
num_nodes= tg.num_nodes
@@ -45,6 +103,30 @@ function add_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int, g::GNNGraph)
45103
return TemporalSnapshotsGNNGraph(num_nodes, num_edges, num_snapshots, snapshots, tg.tgdata)
46104
end
47105

106+
"""
107+
remove_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int)
108+
109+
Return a `TemporalSnapshotsGNNGraph` created starting from `tg` by removing the snapshot at time index `t`.
110+
111+
# Example
112+
```julia
113+
julia> using GraphNeuralNetworks
114+
115+
julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];
116+
117+
julia> tgs = TemporalSnapshotsGNNGraph(snapshots)
118+
TemporalSnapshotsGNNGraph:
119+
num_nodes: [10, 10, 10]
120+
num_edges: [20, 14, 22]
121+
num_snapshots: 3
122+
123+
julia> new_tgs = remove_snapshot(tgs,2) # remove snapshot at time 2
124+
TemporalSnapshotsGNNGraph:
125+
num_nodes: [10, 10]
126+
num_edges: [20, 22]
127+
num_snapshots: 2
128+
```
129+
"""
48130
function remove_snapshot(tg::TemporalSnapshotsGNNGraph, t::Int)
49131
num_nodes= tg.num_nodes
50132
num_edges = tg.num_edges

0 commit comments

Comments
 (0)