@@ -151,12 +151,14 @@ end
151
151
152
152
"""
153
153
remove_edges(g::GNNGraph, edges_to_remove::AbstractVector{<:Integer})
154
+ remove_edges(g::GNNGraph, p=0.5)
154
155
155
- Remove specified edges from a GNNGraph.
156
+ Remove specified edges from a GNNGraph, either by specifying edge indices or by randomly removing edges with a given probability .
156
157
157
158
# Arguments
158
159
- `g`: The input graph from which edges will be removed.
159
- - `edges_to_remove`: Vector of edge indices to be removed.
160
+ - `edges_to_remove`: Vector of edge indices to be removed. This argument is only required for the first method.
161
+ - `p`: Probability of removing each edge. This argument is only required for the second method and defaults to 0.5.
160
162
161
163
# Returns
162
164
A new GNNGraph with the specified edges removed.
@@ -178,6 +180,14 @@ julia> g_new
178
180
GNNGraph:
179
181
num_nodes: 3
180
182
num_edges: 4
183
+
184
+ # Remove edges with a probability of 0.5
185
+ julia> g_new = remove_edges(g, 0.5);
186
+
187
+ julia> g_new
188
+ GNNGraph:
189
+ num_nodes: 3
190
+ num_edges: 2
181
191
```
182
192
"""
183
193
function remove_edges (g:: GNNGraph{<:COO_T} , edges_to_remove:: AbstractVector{<:Integer} )
@@ -200,6 +210,13 @@ function remove_edges(g::GNNGraph{<:COO_T}, edges_to_remove::AbstractVector{<:In
200
210
g. ndata, edata, g. gdata)
201
211
end
202
212
213
+
214
+ function remove_edges (g:: GNNGraph{<:COO_T} , p = 0.5 )
215
+ num_edges = g. num_edges
216
+ edges_to_remove = filter (_ -> rand () < p, 1 : num_edges)
217
+ return remove_edges (g, edges_to_remove)
218
+ end
219
+
203
220
"""
204
221
remove_multi_edges(g::GNNGraph; aggr=+)
205
222
0 commit comments