Skip to content

Adding PairNorm support#418

Open
achiverram28 wants to merge 1 commit intoJuliaGraphs:masterfrom
achiverram28:master2
Open

Adding PairNorm support#418
achiverram28 wants to merge 1 commit intoJuliaGraphs:masterfrom
achiverram28:master2

Conversation

@achiverram28
Copy link
Copy Markdown
Contributor

Addressing #405

Adding a new normalise.jl

  • Initially added the PairNorm support
  • Will add GraphNorm next

Signed-off-by: achiverram28 <ramsamarth21bcs24@iiitkottayam.ac.in>
Comment thread src/layers/normalise.jl
# Implementation of normalization layers for GraphNeuralNetworks

@doc raw"""
PairNorm(scale_value; [scale_individually])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PairNorm(scale_value; [scale_individually])
PairNorm(scale_value; scale_individually=false)

Comment thread src/layers/normalise.jl
@doc raw"""
PairNorm(scale_value; [scale_individually])

PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Comment thread src/layers/normalise.jl

PairNorm layer from paper [PairNorm: Tackling Oversmoothing in GNNs](https://arxiv.org/abs/1909.12223)

Performs the operation(normalization)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Performs the operation(normalization)
Performs the operation

Comment thread src/layers/normalise.jl
Comment on lines +10 to +15
\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}}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\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}}

Comment thread src/layers/normalise.jl
Comment on lines +18 to +19
The input to this layer is the output from GNN layers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The input to this layer is the output from GNN layers

Comment thread src/layers/normalise.jl

# Arguments

- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0`
- `scale_value`: Scaling factor `s` used in normalisation. Default `1.0`.

Comment thread src/layers/normalise.jl
```
Default `false`

- `ϵ` : Small value added in the denominator for numerical stability. Default `1f-5`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `ϵ` : 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.

Comment thread src/layers/normalise.jl
@functor PairNorm

function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5, ϵ=nothing)
ε = _greek_ascii_depwarn(ϵ => eps, :BatchNorm, "ϵ" => "eps")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ε = _greek_ascii_depwarn(ϵ => eps, :BatchNorm, "ϵ" => "eps")

Comment thread src/layers/normalise.jl

@functor PairNorm

function PairNorm(scale_value::Real=1.0f0; scale_individually::Bool=false, eps::Real=1f-5, ϵ=nothing)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment thread src/layers/normalise.jl
return PairNorm(scale_value, ε, scale_individually)
end

function (PN::PairNorm)(x::AbstractArray)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function (PN::PairNorm)(x::AbstractArray)
function (pn::PairNorm)(x::AbstractArray)
eps = ofeltype(x, pn.ϵ)
s = ofeltype(pn.scale_value)

Comment thread src/layers/normalise.jl
end

function (PN::PairNorm)(x::AbstractArray)
xm = mean(x, dims=1)
Copy link
Copy Markdown
Member

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

Suggested change
xm = mean(x, dims=1)
xm = mean(x, dims=2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants