-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add unbatch * implement add_nodes * cleanup
- Loading branch information
1 parent
195bb6c
commit da7b1e4
Showing
8 changed files
with
209 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,52 @@ | ||
""" | ||
rand_graph(n, m; directed=false, kws...) | ||
rand_graph(n, m; bidirected=true, kws...) | ||
Generate a random (Erdós-Renyi) `GNNGraph` with `n` nodes. | ||
Generate a random (Erdós-Renyi) `GNNGraph` with `n` nodes | ||
and `m` edges. | ||
If `directed=false` the output will contain `2m` edges: | ||
the reverse edge of each edge will be present. | ||
If `directed=true` instead, `m` unrelated edges are generated. | ||
If `bidirected=true` the reverse edge of each edge will be present. | ||
If `bidirected=false` instead, `m` unrelated edges are generated. | ||
In any case, the output graph will contain no self-loops or multi-edges. | ||
Additional keyword argument will be fed to the [`GNNGraph`](@ref) constructor. | ||
Additional keyword arguments will be passed to the [`GNNGraph`](@ref) constructor. | ||
# Usage | ||
```juliarepl | ||
julia> g = rand_graph(5, 4, bidirected=false) | ||
GNNGraph: | ||
num_nodes = 5 | ||
num_edges = 4 | ||
num_graphs = 1 | ||
ndata: | ||
edata: | ||
gdata: | ||
julia> edge_index(g) | ||
([1, 3, 3, 4], [5, 4, 5, 2]) | ||
# In the bidirected case, edge data will be duplicated on the reverse edges if needed. | ||
julia> g = rand_graph(5, 4, edata=rand(16, 2)) | ||
GNNGraph: | ||
num_nodes = 5 | ||
num_edges = 4 | ||
num_graphs = 1 | ||
ndata: | ||
edata: | ||
e => (16, 4) | ||
gdata: | ||
# Each edge has a reverse | ||
julia> edge_index(g) | ||
([1, 3, 3, 4], [3, 4, 1, 3]) | ||
``` | ||
""" | ||
function rand_graph(n::Integer, m::Integer; directed=false, kws...) | ||
return GNNGraph(Graphs.erdos_renyi(n, m, is_directed=directed); kws...) | ||
function rand_graph(n::Integer, m::Integer; bidirected=true, kws...) | ||
if bidirected | ||
@assert iseven(m) "Need even number of edges for bidirected graphs, given m=$m." | ||
end | ||
m2 = bidirected ? m÷2 : m | ||
return GNNGraph(Graphs.erdos_renyi(n, m2, is_directed=!bidirected); kws...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters