Skip to content

Commit dc53610

Browse files
committed
migrate examples
1 parent edece65 commit dc53610

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

examples/gae.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ using JLD2
77
using Statistics: mean
88
using SparseArrays
99
using Graphs.SimpleGraphs
10-
using Graphs: adjacency_matrix
1110
using CUDA
1211

1312
@load "data/cora_features.jld2" features
@@ -21,13 +20,13 @@ target_catg = 7
2120
epochs = 200
2221

2322
## Preprocessing data
24-
adj_mat = Matrix{Float32}(adjacency_matrix(g)) |> gpu
23+
fg = FeaturedGraph(g) |> gpu
2524
train_X = Matrix{Float32}(features) |> gpu # dim: num_features * num_nodes
26-
train_y = adj_mat # dim: num_nodes * num_nodes
25+
train_y = fg # dim: num_nodes * num_nodes
2726

2827
## Model
29-
encoder = Chain(GCNConv(adj_mat, num_features=>hidden1, relu),
30-
GCNConv(adj_mat, hidden1=>hidden2))
28+
encoder = Chain(GCNConv(fg, num_features=>hidden1, relu),
29+
GCNConv(fg, hidden1=>hidden2))
3130
model = Chain(GAE(encoder, σ)) |> gpu
3231

3332
## Loss

examples/gcn.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using JLD2
66
using Statistics
77
using SparseArrays
88
using Graphs.SimpleGraphs
9-
using Graphs: adjacency_matrix
109
using CUDA
1110
using Random
1211

@@ -25,12 +24,12 @@ epochs = 100
2524
## Preprocessing data
2625
train_X = Matrix{Float32}(features) |> gpu # dim: num_features * num_nodes
2726
train_y = Matrix{Float32}(labels) |> gpu # dim: target_catg * num_nodes
28-
adj_mat = Matrix{Float32}(adjacency_matrix(g)) |> gpu
27+
fg = FeaturedGraph(g) |> gpu
2928

3029
## Model
31-
model = Chain(GCNConv(adj_mat, num_features=>hidden, relu),
30+
model = Chain(GCNConv(fg, num_features=>hidden, relu),
3231
Dropout(0.5),
33-
GCNConv(adj_mat, hidden=>target_catg),
32+
GCNConv(fg, hidden=>target_catg),
3433
) |> gpu
3534

3635
## Loss

examples/gde.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ using GeometricFlux, Flux, JLD2, SparseArrays, DiffEqFlux, DifferentialEquations
22
using Flux: onehotbatch, onecold, logitcrossentropy, throttle
33
using Flux: @epochs
44
using Statistics: mean
5-
using Graphs: adjacency_matrix
65

76
# Load the dataset
87
@load "data/cora_features.jld2" features
@@ -19,22 +18,22 @@ epochs = 40
1918
# Preprocess the data and compute adjacency matrix
2019
train_X = Matrix{Float32}(features) # dim: num_features * num_nodes
2120
train_y = Float32.(labels) # dim: target_catg * num_nodes
22-
adj_mat = Matrix{Float32}(adjacency_matrix(g))
21+
fg = FeaturedGraph(g)
2322

2423
# Define the Neural GDE
2524
diffeqarray_to_array(x) = reshape(cpu(x), size(x)[1:2])
2625

2726
node = NeuralODE(
28-
GCNConv(adj_mat, hidden=>hidden),
27+
GCNConv(fg, hidden=>hidden),
2928
(0.f0, 1.f0), Tsit5(), save_everystep = false,
3029
reltol = 1e-3, abstol = 1e-3, save_start = false
3130
)
3231

33-
model = Chain(GCNConv(adj_mat, num_features=>hidden, relu),
32+
model = Chain(GCNConv(fg, num_features=>hidden, relu),
3433
Dropout(0.5),
3534
node,
3635
diffeqarray_to_array,
37-
GCNConv(adj_mat, hidden=>target_catg),
36+
GCNConv(fg, hidden=>target_catg),
3837
softmax)
3938

4039
# Loss

examples/gde_gpu.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ using GeometricFlux, Flux, JLD2, SparseArrays, DiffEqFlux, DifferentialEquations
22
using Flux: onehotbatch, onecold, logitcrossentropy, throttle
33
using Flux: @epochs
44
using Statistics: mean
5-
using Graphs: adjacency_matrix
65
using CUDA
76

87
# Load the dataset
@@ -20,22 +19,22 @@ epochs = 40
2019
# Preprocess the data and compute adjacency matrix
2120
train_X = Matrix{Float32}(features) |> gpu # dim: num_features * num_nodes
2221
train_y = Float32.(labels) |> gpu # dim: target_catg * num_nodes
23-
adj_mat = Matrix{Float32}(adjacency_matrix(g)) |> gpu
22+
fg = FeaturedGraph(g) |> gpu
2423

2524
# Define the Neural GDE
2625
diffeqarray_to_array(x) = reshape(gpu(x), size(x)[1:2])
2726

2827
node = NeuralODE(
29-
GCNConv(adj_mat, hidden=>hidden) |> gpu,
28+
GCNConv(fg, hidden=>hidden) |> gpu,
3029
(0.f0, 1.f0), Tsit5(), save_everystep = false,
3130
reltol = 1e-3, abstol = 1e-3, save_start = false
3231
)
3332

34-
model = Chain(GCNConv(adj_mat, num_features=>hidden, relu),
33+
model = Chain(GCNConv(fg, num_features=>hidden, relu),
3534
Dropout(0.5),
3635
node,
3736
diffeqarray_to_array,
38-
GCNConv(adj_mat, hidden=>target_catg),
37+
GCNConv(fg, hidden=>target_catg),
3938
softmax) |> gpu
4039

4140
# Loss

0 commit comments

Comments
 (0)