-
Notifications
You must be signed in to change notification settings - Fork 48
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
Added node_shuffle
#429
Added node_shuffle
#429
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,6 +248,28 @@ function remove_nodes(g::GNNGraph{<:COO_T}, nodes_to_remove::AbstractVector) | |
ndata, edata, g.gdata) | ||
end | ||
|
||
""" | ||
node_shuffle(g::GNNGraph{<:COO_T}) | ||
|
||
Shuffle the node features in the given GNNGraph as shown in paper [On Node Features for Graph Neural Networks](https://arxiv.org/ftp/arxiv/papers/1911/1911.08795.pdf) | ||
|
||
# Arguments | ||
- `g::GNNGraph`: The input graph represented as a GNNGraph. | ||
|
||
# Returns | ||
- `g::GNNGraph`: The GNNGraph with shuffled node features. | ||
""" | ||
function node_shuffle(g::GNNGraph{<:COO_T}) | ||
features = g.ndata.x | ||
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. we can have no guarantess that there exists features named x |
||
num_nodes = size(features, 1) | ||
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. the node dimension is the second one |
||
|
||
shuffled_indices = randperm(num_nodes) | ||
shuffled_features = features[shuffled_indices, :] | ||
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. this is shuffling feature dimensions, not nodes |
||
|
||
g.ndata.x = shuffled_features | ||
return g | ||
end | ||
|
||
""" | ||
add_edges(g::GNNGraph, s::AbstractVector, t::AbstractVector; [edata]) | ||
add_edges(g::GNNGraph, (s, t); [edata]) | ||
|
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.
this is mutating, so it should be called
node_shuffle!