-
Notifications
You must be signed in to change notification settings - Fork 47
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
Adding PairNorm support #418
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: achiverram28 <[email protected]>
# Implementation of normalization layers for GraphNeuralNetworks | ||
|
||
@doc raw""" | ||
PairNorm(scale_value; [scale_individually]) |
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.
PairNorm(scale_value; [scale_individually]) | |
PairNorm(scale_value; scale_individually=false) |
@doc raw""" | ||
PairNorm(scale_value; [scale_individually]) | ||
|
||
PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223) |
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.
PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223) | |
PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223). |
|
||
PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223) | ||
|
||
Performs the operation(normalization) |
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.
Performs the operation(normalization) | |
Performs the operation |
\mathbf{x}_i^c &= \mathbf{x}_i - \frac{1}{n} | ||
\sum_{i=1}^n \mathbf{x}_i \\ | ||
|
||
\mathbf{x}_i^{\prime} &= s \cdot | ||
\frac{\mathbf{x}_i^c}{\sqrt{\frac{1}{n} \sum_{i=1}^n | ||
{\| \mathbf{x}_i^c \|}^2_2}} |
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.
\mathbf{x}_i^c &= \mathbf{x}_i - \frac{1}{n} | |
\sum_{i=1}^n \mathbf{x}_i \\ | |
\mathbf{x}_i^{\prime} &= s \cdot | |
\frac{\mathbf{x}_i^c}{\sqrt{\frac{1}{n} \sum_{i=1}^n | |
{\| \mathbf{x}_i^c \|}^2_2}} | |
\mathbf{x}_i^c &= \mathbf{x}_i - \frac{1}{n} | |
\sum_{i=1}^n \mathbf{x}_i \\ | |
\mathbf{x}_i^{\prime} &= s \cdot | |
\frac{\mathbf{x}_i^c}{\sqrt{\frac{1}{n} \sum_{i=1}^n | |
{\| \mathbf{x}_i^c \|}^2_2}} |
The input to this layer is the output from GNN layers | ||
|
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.
The input to this layer is the output from GNN layers |
|
||
# Arguments | ||
|
||
- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0` |
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.
- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0` | |
- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0`. |
``` | ||
Default `false` | ||
|
||
- `ϵ` : Small value added in the denominator for numerical stability. Default `1f-5` |
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.
- `ϵ` : Small value added in the denominator for numerical stability. Default `1f-5` | |
- `ϵ` : Small value added in the denominator for numerical stability. Default `1f-5`. |
This should be mentioned in the first line fo the docstring.
@functor PairNorm | ||
|
||
function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5, ϵ=nothing) | ||
ε = _greek_ascii_depwarn(ϵ => eps, :BatchNorm, "ϵ" => "eps") |
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.
ε = _greek_ascii_depwarn(ϵ => eps, :BatchNorm, "ϵ" => "eps") |
|
||
@functor PairNorm | ||
|
||
function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5, ϵ=nothing) |
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.
function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5, ϵ=nothing) | |
function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5) |
return PairNorm(scale_value, ε, scale_individually) | ||
end | ||
|
||
function (PN::PairNorm)(x::AbstractArray) |
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.
function (PN::PairNorm)(x::AbstractArray) | |
function (pn::PairNorm)(x::AbstractArray) | |
eps = ofeltype(x, pn.ϵ) | |
s = ofeltype(pn.scale_value) |
end | ||
|
||
function (PN::PairNorm)(x::AbstractArray) | ||
xm = mean(x, dims=1) |
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.
all dimensions are wrong here and belowe. The node dimension is the secnd dimension, the feature dimension is the first
xm = mean(x, dims=1) | |
xm = mean(x, dims=2) |
Addressing #405
Adding a new
normalise.jl