Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
9779c026
"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "fa71fb447803d269d1050fe5081e2cb577b04b94"
Unverified
Commit
9779c026
authored
Jun 04, 2020
by
Mufei Li
Committed by
GitHub
Jun 04, 2020
Browse files
Fix tutorial (#1587)
parent
2b9d06b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
tutorials/models/1_gnn/1_gcn.py
tutorials/models/1_gnn/1_gcn.py
+13
-6
No files found.
tutorials/models/1_gnn/1_gcn.py
View file @
9779c026
...
@@ -126,6 +126,8 @@ def evaluate(model, g, features, labels, mask):
...
@@ -126,6 +126,8 @@ def evaluate(model, g, features, labels, mask):
import
time
import
time
import
numpy
as
np
import
numpy
as
np
g
,
features
,
labels
,
train_mask
,
test_mask
=
load_cora_data
()
g
,
features
,
labels
,
train_mask
,
test_mask
=
load_cora_data
()
# Add edges between each node and itself to preserve old node representations
g
.
add_edges
(
g
.
nodes
(),
g
.
nodes
())
optimizer
=
th
.
optim
.
Adam
(
net
.
parameters
(),
lr
=
1e-2
)
optimizer
=
th
.
optim
.
Adam
(
net
.
parameters
(),
lr
=
1e-2
)
dur
=
[]
dur
=
[]
for
epoch
in
range
(
50
):
for
epoch
in
range
(
50
):
...
@@ -159,18 +161,23 @@ for epoch in range(50):
...
@@ -159,18 +161,23 @@ for epoch in range(50):
#
#
# Here, :math:`H^{(l)}` denotes the :math:`l^{th}` layer in the network,
# Here, :math:`H^{(l)}` denotes the :math:`l^{th}` layer in the network,
# :math:`\sigma` is the non-linearity, and :math:`W` is the weight matrix for
# :math:`\sigma` is the non-linearity, and :math:`W` is the weight matrix for
# this layer. :math:`
D
` and :math:`
A`, as commonly seen, represent
degree
# this layer. :math:`
\tilde{D}
` and :math:`
\tilde{A}` are separately the
degree
#
matrix
and adjacency matri
x, respectively. The ~ is a renormalization trick
# and adjacency matri
ces for the graph. With the superscript ~, we are referring
#
in which we add a self-connection to each node of the graph, and build the
#
to the variant where we add additional edges between each node and itself to
#
corresponding degree and adjacency matrix.
The shape of the input
#
preserve its old representation in graph convolutions.
The shape of the input
# :math:`H^{(0)}` is :math:`N \times D`, where :math:`N` is the number of nodes
# :math:`H^{(0)}` is :math:`N \times D`, where :math:`N` is the number of nodes
# and :math:`D` is the number of input features. We can chain up multiple
# and :math:`D` is the number of input features. We can chain up multiple
# layers as such to produce a node-level representation output with shape
# layers as such to produce a node-level representation output with shape
# :math`N \times F`, where :math:`F` is the dimension of the output node
# :math
:
`N \times F`, where :math:`F` is the dimension of the output node
# feature vector.
# feature vector.
#
#
# The equation can be efficiently implemented using sparse matrix
# The equation can be efficiently implemented using sparse matrix
# multiplication kernels (such as Kipf's
# multiplication kernels (such as Kipf's
# `pygcn <https://github.com/tkipf/pygcn>`_ code). The above DGL implementation
# `pygcn <https://github.com/tkipf/pygcn>`_ code). The above DGL implementation
# in fact has already used this trick due to the use of builtin functions. To
# in fact has already used this trick due to the use of builtin functions. To
# understand what is under the hood, please read our tutorial on :doc:`PageRank <../../basics/3_pagerank>`.
# understand what is under the hood, please read our tutorial on :doc:`PageRank <../../basics/3_pagerank>`.
#
# Note that the tutorial code implements a simplified version of GCN where we
# replace :math:`\tilde{D}^{-\frac{1}{2}}\tilde{A}\tilde{D}^{-\frac{1}{2}}` with
# :math:`\tilde{A}`. For a full implementation, see our example
# `here <https://github.com/dmlc/dgl/tree/master/examples/pytorch/gcn>`_.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment