You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/GNNGraphs/transform.jl
+66Lines changed: 66 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -502,6 +502,72 @@ function add_edges(g::GNNHeteroGraph{<:COO_T},
502
502
ntypes, etypes)
503
503
end
504
504
505
+
"""
506
+
perturb_edges([rng], g::GNNGraph, perturb_ratio)
507
+
508
+
Perturb the graph `g` by adding random edges, based on a specified `perturb_ratio`. The `perturb_ratio` determines the fraction of new edges to add relative to the current number of edges in the graph. These new edges are added without creating self-loops. Optionally, a random `seed` can be provided to ensure reproducible perturbations.
509
+
510
+
The function returns a new `GNNGraph` instance that shares some of the underlying data with `g` but includes the additional edges. The nodes for the new edges are selected randomly, and no edge data (`edata`) or weights (`w`) are assigned to these new edges.
511
+
512
+
# Parameters
513
+
- `g::GNNGraph`: The graph to be perturbed.
514
+
- `perturb_ratio`: The ratio of the number of new edges to add relative to the current number of edges in the graph. For example, a `perturb_ratio` of 0.1 means that 10% of the current number of edges will be added as new random edges.
515
+
- `seed=123`: An optional seed for the random number generator to ensure reproducible results.
516
+
517
+
# Examples
518
+
519
+
```julia
520
+
julia> g = GNNGraph((s, t, w))
521
+
GNNGraph:
522
+
num_nodes: 4
523
+
num_edges: 5
524
+
525
+
julia> perturbed_g = perturb_edges(g, 0.2)
526
+
GNNGraph:
527
+
num_nodes: 4
528
+
num_edges: 6 # One new edge added if the original graph had 5 edges, as 0.2 of 5 is 1.
0 commit comments