-
Notifications
You must be signed in to change notification settings - Fork 72
Learnable epsilon in GIN #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aurorarossi
wants to merge
6
commits into
JuliaGraphs:master
Choose a base branch
from
aurorarossi:learnable-epsilon-gin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a0408b
Learnable epsilon
aurorarossi 9782473
Learnable epsilon and flag train
aurorarossi fd49d7c
Learnable epsilon and flag
aurorarossi fc40307
Merge branch 'master' into learnable-epsilon-gin
aurorarossi 82f23cf
Change eps to unicode char
aurorarossi f0c8676
Fix gpu problem
aurorarossi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -590,7 +590,7 @@ function Base.show(io::IO, l::EdgeConv) | |||||
| end | ||||||
|
|
||||||
| @doc raw""" | ||||||
| GINConv(f, ϵ; aggr=+) | ||||||
| GINConv(f, [ϵ]; aggr=+, train_eps=false) | ||||||
|
|
||||||
| Graph Isomorphism convolutional layer from paper [How Powerful are Graph Neural Networks?](https://arxiv.org/pdf/1810.00826.pdf). | ||||||
|
|
||||||
|
|
@@ -603,7 +603,9 @@ where ``f_\Theta`` typically denotes a learnable function, e.g. a linear layer o | |||||
| # Arguments | ||||||
|
|
||||||
| - `f`: A (possibly learnable) function acting on node features. | ||||||
| - `ϵ`: Weighting factor. | ||||||
| - `ϵ`: Initial value of the weighting factor ``\epsilon``. Default `0.0f0`. | ||||||
| - `train_eps`: If `true`, ``\epsilon`` is trainable. Default `false`. | ||||||
| - `aggr`: Neighborhood aggregation function. Default `+`. | ||||||
|
|
||||||
| # Examples: | ||||||
|
|
||||||
|
|
@@ -619,28 +621,37 @@ g = GNNGraph(s, t) | |||||
| nn = Dense(in_channel, out_channel) | ||||||
|
|
||||||
| # create layer | ||||||
| l = GINConv(nn, 0.01f0, aggr = mean) | ||||||
| l = GINConv(nn; ϵ = 0.01f0, train_eps = true, aggr = mean) | ||||||
|
|
||||||
| # forward pass | ||||||
| y = l(g, x) | ||||||
| ``` | ||||||
| """ | ||||||
| struct GINConv{R <: Real, NN, A} <: GNNLayer | ||||||
| struct GINConv{E, NN, A} <: GNNLayer | ||||||
| nn::NN | ||||||
| ϵ::R | ||||||
| ϵ::E | ||||||
| aggr::A | ||||||
| train_eps::Bool | ||||||
| end | ||||||
|
|
||||||
| Flux.@layer :expand GINConv | ||||||
| Flux.trainable(l::GINConv) = (nn = l.nn,) | ||||||
| Flux.trainable(l::GINConv) = l.train_eps ? (; l.nn, l.ϵ) : (; l.nn) | ||||||
|
|
||||||
| GINConv(nn, ϵ; aggr = +) = GINConv(nn, ϵ, aggr) | ||||||
| GINConv(nn, ϵ::Real; aggr = +, train_eps::Bool = false) = | ||||||
| GINConv(nn, train_eps ? [ϵ] : ϵ, aggr, train_eps) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| GINConv(nn, ϵ::Real, aggr) = GINConv(nn, ϵ; aggr) | ||||||
|
|
||||||
| GINConv(nn; ϵ::Real = 0.0f0, aggr = +, train_eps::Bool = false) = | ||||||
| GINConv(nn, ϵ; aggr, train_eps) | ||||||
|
|
||||||
| (l::GINConv)(g, x) = GNNlib.gin_conv(l, g, x) | ||||||
|
|
||||||
| function Base.show(io::IO, l::GINConv) | ||||||
| print(io, "GINConv($(l.nn)") | ||||||
| print(io, ", $(l.ϵ)") | ||||||
| print(io, ", ϵ=$(l.ϵ)") | ||||||
| l.train_eps && print(io, ", train_eps=true") | ||||||
| l.aggr == (+) || print(io, ", aggr=$(l.aggr)") | ||||||
| print(io, ")") | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is safer?