Skip to content

Commit d47da55

Browse files
InterdisciplinaryPhysicsTeampitmonticoneClaudMor
committed
Clean docs and docstrings
Co-Authored-By: Pietro Monticone <[email protected]> Co-Authored-By: Claudio Moroni <[email protected]>
1 parent f2c9e8a commit d47da55

16 files changed

+77
-108
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
45
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Revise
2+
using Distributions
23
using Graphs
34
using MultilayerGraphs
45
using Documenter

docs/src/API.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This page provides a list of exported methods organized by topic and audience. M
88

99
```@docs
1010
Node
11-
11+
id
1212
```
1313

1414
### Vertices
@@ -74,6 +74,8 @@ Layer(
7474
) where {T<:Integer, U <: Real, G<:AbstractGraph{T}}
7575
7676
has_node(layer::Layer, n::Node)
77+
add_vertex!(layer::Layer, mv::MultilayerVertex)
78+
add_vertex!(layer::L, n::Node, args...; kwargs...) where {T, L <: Layer{T}}
7779
rem_vertex!(layer::Layer, mv::MultilayerVertex)
7880
rem_vertex!(layer::Layer, n::Node)
7981
@@ -129,8 +131,6 @@ get_symmetric_interlayer(
129131
interlayer::In;
130132
symmetric_interlayer_name::String = String(interlayer.name) * "_rev"
131133
) where {T,U,G,In<:Interlayer{T,U,G}}
132-
133-
134134
```
135135

136136
### Multilayer-Specific Methods
@@ -200,6 +200,10 @@ mv_vertices(mg::AbstractMultilayerGraph)
200200
mv_inneighbors(mg::AbstractMultilayerGraph, mv::MultilayerVertex)
201201
mv_outneighbors(mg::AbstractMultilayerGraph, mv::MultilayerVertex)
202202
mv_neighbors( mg::AbstractMultilayerGraph, mv::MultilayerVertex)
203+
add_vertex!(mg::M, V::MultilayerVertex) where {T, U, M <: AbstractMultilayerUGraph{T,U}}
204+
add_vertex!(mg::M, V::MultilayerVertex) where {T, U, M <: AbstractMultilayerDiGraph{T,U}}
205+
rem_vertex!(mg::AbstractMultilayerUGraph, V::MultilayerVertex)
206+
rem_vertex!(mg::AbstractMultilayerDiGraph, V::MultilayerVertex)
203207
has_edge(mg::AbstractMultilayerGraph, edge::MultilayerEdge)
204208
has_edge( subgraph::AbstractMultilayerGraph, s::MultilayerVertex, d::MultilayerVertex)
205209
ne(mg::AbstractMultilayerGraph)
@@ -220,8 +224,6 @@ is_directed(m::M) where { M <: Type{ <: AbstractMultilayerUGraph}}
220224
is_directed(mg::AbstractMultilayerDiGraph)
221225
is_directed(m::M) where { M <: Type{ <: AbstractMultilayerDiGraph}}
222226
has_node(mg::AbstractMultilayerGraph, n::Node)
223-
rem_vertex!(mg::AbstractMultilayerUGraph, V::MultilayerVertex)
224-
rem_vertex!(mg::AbstractMultilayerDiGraph, V::MultilayerVertex)
225227
set_metadata!(mg::AbstractMultilayerGraph, mv::MultilayerVertex, metadata::Union{Tuple, NamedTuple})
226228
set_metadata!(mg::AbstractMultilayerDiGraph, src::MultilayerVertex, dst::MultilayerVertex, metadata::Union{Tuple, NamedTuple})
227229
set_metadata!(mg::AbstractMultilayerUGraph, src::MultilayerVertex, dst::MultilayerVertex, metadata::Union{Tuple, NamedTuple})
@@ -286,8 +288,6 @@ modularity(
286288
287289
288290
von_neumann_entropy(mg::M) where {T,U,M<:AbstractMultilayerUGraph{T,U}}
289-
290-
291291
```
292292

293293
### Representations
@@ -300,7 +300,6 @@ metadata_tensor(mg::M) where {T,U, M <: AbstractMultilayerGraph{T,U}}
300300
array(amr::AbstractMatrixRepresentation)
301301
SupraWeightMatrix{T,U}
302302
supra_weight_matrix(mg::M) where {T,U, M <: AbstractMultilayerGraph{T,U}}
303-
304303
```
305304

306305
### Traits
@@ -312,11 +311,16 @@ is_meta(g::G) where {G <: AbstractGraph}
312311
is_meta(g::G) where {G<:Type{<:AbstractGraph}}
313312
```
314313

315-
316-
317-
----------------------------------------------------
318-
####################################################
319-
----------------------------------------------------
314+
### Utilities
315+
```@docs
316+
multilayer_kronecker_delta(dims::NTuple{4,Int64})
317+
δk{T}
318+
δk(N::Int64)
319+
δ_1{T<: Number}
320+
δ_2{T<:Number}
321+
δ_3{T<:Number}
322+
δ_Ω{T}
323+
```
320324

321325

322326
## Developer
@@ -346,7 +350,7 @@ metadata(he::MultilayerGraphs.HalfEdge)
346350
weight(he::MultilayerGraphs.HalfEdge)
347351
```
348352

349-
# Subgraphs
353+
### Subgraphs
350354

351355
```@docs
352356
has_vertex(subgraph::S, v::T ) where {T,S<:AbstractSubGraph{T}}
@@ -358,7 +362,7 @@ outneighbors(subgraph::AbstractSubGraph, mv::MultilayerVertex)
358362
neighbors(subgraph::S, v::T) where {T,S<:AbstractSubGraph{T}}
359363
neighbors(subgraph::AbstractSubGraph, mv::MultilayerVertex)
360364
edgetype(::S) where {T,U,S<:AbstractSubGraph{T,U}}
361-
has_edge(subgraph::S, s::MultilayerVertex, d::MultilayerVertex) where { T, S <: AbstractSubGraph{T}}
365+
has_edge( subgraph::S, s::T, d::T) where {T,S<:AbstractSubGraph{T}}
362366
add_edge!(subgraph::S, src::T, dst::T; weight::W = nothing, metadata::Union{Tuple, NamedTuple}= NamedTuple()) where {T, U<: Real, W<:Union{ U, Nothing},G<:AbstractGraph{T},S<:AbstractSubGraph{T,U,G}}
363367
rem_edge!(subgraph::S, src::T, dst::T) where {T, S<:AbstractSubGraph{T}}
364368
AbstractLayer
@@ -374,12 +378,10 @@ AbstractInterlayer
374378
AbstractMultilayerGraph{T <: Integer, U <: Real}
375379
has_vertex(mg::M, v::T) where {T, M <: AbstractMultilayerGraph{T}}
376380
vertices(mg::AbstractMultilayerGraph)
377-
inneighbors(mg::AbstractMultilayerUGraph, v::T) where {T <: Integer, M <: AbstractMultilayerUGraph{T}}
378-
inneighbors(mg::M, v::T) where {T <: Integer, M <: AbstractMultilayerDiGraph{T}}
381+
inneighbors(mg::M, v::T) where {T,M<:AbstractMultilayerUGraph{T,<:Real}}
382+
inneighbors(mg::M, v::T) where {T, M<:AbstractMultilayerGraph{T,<:Real}}
379383
inneighbors(mg::AbstractMultilayerGraph, mv::MultilayerVertex)
380-
outneighbors(mg::M, v::T) where {M <: AbstractMultilayerGraph{T} } where { T <: Integer}
381-
outneighbors(mg::M, v::T) where {M <: AbstractMultilayerGraph{T} } where { T <: Integer}
382-
outneighbors(mg::M, v::T) where {M <: AbstractMultilayerGraph{T} } where { T <: Integer}
384+
outneighbors(mg::M, v::T) where {T, M<:AbstractMultilayerGraph{T}}
383385
neighbors(mg::AbstractMultilayerGraph, mv::MultilayerVertex)
384386
edgetype(::M) where {T,U,M<:AbstractMultilayerGraph{T,U}}
385387
has_edge(mg::M, src::T, dst::T) where { T, M <: AbstractMultilayerUGraph{T}}
@@ -399,8 +401,4 @@ AbstractMatrixRepresentation{T,U}
399401
```@docs
400402
IsWeighted{X}
401403
IsMeta{X}
402-
```
403-
404-
405-
```@docs
406-
```
404+
```

docs/src/index.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ CurrentModule = MultilayerGraphs
2222

2323
A multilayer graph is composed of *layers*, i.e. graphs whose vertices represent the same set of nodes (not all nodes need to be represented in every layer), and *interlayers*, i.e. the [bipartite graphs](https://en.wikipedia.org/wiki/Bipartite_graph) that connect vertices in two different layers. Vertices in a multilayer graph are represented using the [`MultilayerVertex`](@ref) struct, while nodes are represented using the [`Node`](@ref) struct.
2424

25-
[`MultilayerGraph`](@ref) and [`MultilayerDiGraph`](@ref) are fully-fledged [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) extensions. Both structs are designed to allow for layers and interlayers of any type (as long as they are Graphs.jl extensions themselves) and to permit layers and interlayers of different types. However, it is required that all layers and interlayers in [`MultilayerGraph`](@ref) are undirected, and all layers and interlayers in [`MultilayerDiGraph`](@ref) are directed.
25+
`MultilayerGraph` and `MultilayerDiGraph` are fully-fledged [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) extensions. Both structs are designed to allow for layers and interlayers of any type (as long as they are Graphs.jl extensions themselves) and to permit layers and interlayers of different types. However, it is required that all layers and interlayers in `MultilayerGraph` are undirected, and all layers and interlayers in `MultilayerDiGraph` are directed.
2626

27-
[`MultilayerGraph`](@ref) and [`MultilayerDiGraph`](@ref) support the specification of vertex and edge metadata, provided that the underlying layer or interlayer also supports metadata.
27+
`MultilayerGraph` and `MultilayerDiGraph` support the specification of vertex and edge metadata, provided that the underlying layer or interlayer also supports metadata.
2828

2929
## Installation
3030

@@ -36,7 +36,7 @@ pkg> add MultilayerGraphs
3636

3737
## Tutorial
3838

39-
Here we illustrate how to define, handle and analyse a [`MultilayerGraph`](@ref) (the directed version is completely analogous).
39+
Here we illustrate how to define, handle and analyse a `MultilayerGraph` (the directed version is completely analogous).
4040

4141
```julia
4242
using Revise
@@ -56,7 +56,6 @@ const max_vertices = 7
5656
const min_edges = 1
5757
const max_edges = max_vertices*(max_vertices-1)
5858
const n_nodes = max_vertices
59-
; #hide
6059
```
6160

6261
Next we define nodes:
@@ -76,7 +75,7 @@ const all_nodes = [Node("node_$i") for i in 1:n_nodes]
7675
Node("node_7")
7776
```
7877

79-
And construct `MultilayerVertex`s from these nodes:
78+
You may access (but not modify) the `id` of a `Node` via the [`id`](@ref) function. And construct `MultilayerVertex`s from these nodes:
8079

8180
```julia
8281
## Convert nodes to multilayer vertices without metadata
@@ -106,7 +105,7 @@ multilayervertices_meta[1]
106105
MV(Node("node_1"), :nothing, ("I'm node node_1",))
107106
```
108107

109-
Where `MV` is an alias for `MultilayerVertex`. The first field is the `Node` being represented, the second the (name of) the layer the vertex is represented in (here it is set to `nothing`, since these vertices are yet to be assigned), and the metadata associated to the vertex (no metadata are currently represented via an empty `NamedTuple`). `MultilayerVertex` metadata can be represented via a `Tuple` or a `NamedTuple` (see below for examples).
108+
Where `MV` is an alias for `MultilayerVertex`. The first field is the `Node` being represented (accessible via the [`node`](@ref) function), the second the (name of) the layer the vertex is represented in ((accessible via the [`layer`](@ref) function), here it is set to `nothing`, since these vertices are yet to be assigned), and the metadata associated to the vertex ((accessible via the [`metadata`](@ref) function), no metadata are currently represented via an empty `NamedTuple`). `MultilayerVertex` metadata can be represented via a `Tuple` or a `NamedTuple` (see below for examples).
110109

111110
### Layers
112111

@@ -155,7 +154,6 @@ function _get_srcmv_dstmv_layer(layer::Layer)
155154

156155
return mvs, src_mv, dst_mv
157156
end
158-
; #hide
159157
```
160158

161159
We are now are ready to define some `Layer`s. Every type of graph from the Graphs.jl ecosystem may underlie a `Layer` (or an `Interlayer`). We will construct a few of them, each time with a different number of vertices and edges.
@@ -204,14 +202,13 @@ layer_vg = Layer( :layer_vg,
204202

205203
# Collect all layers in an ordered list. Order will be recorded when instantiating the multilayer graph.
206204
layers = [layer_sg, layer_swg, layer_mg, layer_vg]
207-
; #hide
208205
```
209206

210207
The API that inspects and modifies `Layer`s will be shown below together with that of `Interlayer`s, since they are usually the same. There are of course other constructors that you may discover by typing `?Layer` in the console.
211208

212209
### Interlayers
213210

214-
Now we turn to defining `Interlayer`s. Interlayers are the graphs containing all the edges between vertices is two distinct layers. As before, we need an utility to ease randomization:
211+
Now we turn to defining [`Interlayer`](@ref)s. Interlayers are the graphs containing all the edges between vertices is two distinct layers. As before, we need an utility to ease randomization:
215212

216213

217214
```julia
@@ -240,7 +237,6 @@ function rand_ne_interlayer(layer_1, layer_2)
240237
_ne = rand(_nv:(_nv*(_nv-1)) ÷ 2 )
241238
return _ne
242239
end
243-
; #hide
244240
```
245241

246242
An `Interlayer` is constructed by passing its name, the two `Layer`s it should connect, and the other parameters just like the `Layer`'s constructor. The random constructor reads:
@@ -298,7 +294,6 @@ interlayer_empty_sg_vg = empty_interlayer( layer_sg,
298294

299295
# Collect all interlayers. Even though the list is ordered, order will not matter when instantiating the multilayer graph.
300296
interlayers = [interlayer_sg_swg, interlayer_swg_mg, interlayer_mg_vg, interlayer_multiplex_sg_mg, interlayer_empty_sg_vg]
301-
; #hide
302297
```
303298

304299
Next, we explore the API associated to modify and analyze `Layer`s and `Interlayer`s.
@@ -405,9 +400,9 @@ interlayer_sg_swg_vertices = mv_vertices(interlayer_sg_swg)
405400

406401
The `vertices` command would return an internal representation of the `MultilayerVertex`s. This method, together with others, serves to make `MultilayerGraphs.jl` compatible with the Graphs.jl ecosystem, but it is not meant to be called by the end user. It is, anyway, thought to be used by developers who wish to interface their packages with `MultilayerGraphs.jl` just as with other packages of the `Graphs.jl` ecosystem: a developer-oriented guide will be compiled if there is the need.
407402

408-
In the [API](@ref) page the intended usage of all methods (*end-user* or *developer*) is highlighted.
403+
In the [API](@ref) page the intended usage of all methods ([End-User](@ref) or [Developer](@ref)) is highlighted.
409404

410-
To add a vertex, simply use [`add_vertex!`](@ref). Let us define a vertex with metadata to add. Since nodes may not be represented more than once in layers, we have to define a new node to:
405+
To add a vertex, simply use [`add_vertex!(layer::Layer, mv::MultilayerVertex)`](@ref). Let us define a vertex with metadata to add. Since nodes may not be represented more than once in layers, we have to define a new node to:
411406

412407
```julia
413408
new_node = Node("missing_node")

src/MultilayerGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export
2424
# Node.jl
2525
AbstractNode,
2626
Node,
27+
id,
2728
# abstractvertex.jl
2829
AbstractVertex,
2930
# multilayervertex.jl
@@ -74,6 +75,7 @@ export
7475
AbstractLayer,
7576
Layer,
7677
has_node,
78+
add_vertex!
7779
rem_vertex!,
7880
# interlayer.jl
7981
AbstractInterlayer,

src/abstractmultilayerdigraph.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,13 @@ Return `true` if `mg` is directed, `false` otherwise.
373373
Graphs.is_directed(mg::M) where {M<:Type{<:AbstractMultilayerDiGraph}} = true
374374

375375
"""
376-
inneighbors(mg::M, v::T) where {M <: AbstractMultilayerDiGraph{T} } where { T <: Integer}
376+
inneighbors(mg::M, v::T
377+
) where {T, M<:AbstractMultilayerGraph{T,<:Real}}
378+
377379
378380
Return the list of inneighbors of `v` within `mg`.
379381
"""
380-
function Graphs.inneighbors(mg::M, v::T
381-
) where {M<:AbstractMultilayerGraph{T,<:Real}} where {T}
382+
function Graphs.inneighbors(mg::M, v::T) where {T, M<:AbstractMultilayerGraph{T,<:Real}}
382383

383384
_inneighbors = T[]
384385

src/abstractmultilayergraph.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Graphs.has_vertex(mg::AbstractMultilayerGraph, mv::MultilayerVertex) = get_bare_
121121
122122
Return a list of the `MultilayerVertex`s contained in `mg`.
123123
"""
124-
mv_vertices(mg::AbstractMultilayerGraph) = [get_rich_mv(mg, v) for v in vertices(mg)]
124+
mv_vertices(mg::AbstractMultilayerGraph) = [get_rich_mv(mg, v) for v in vertices(mg)]
125125

126126
"""
127127
nv(mg::M) where {M <: AbstractMultilayerGraph }
@@ -524,13 +524,13 @@ Graphs.outneighbors( mg::AbstractMultilayerGraph, mv::MultilayerVertex) = outnei
524524

525525

526526
"""
527-
outneighbors(mg::M, v::T) where {M <: AbstractMultilayerGraph{T} } where { T <: Integer}
527+
outneighbors(mg::M, v::T) where {T, M<:AbstractMultilayerGraph{T}}
528528
529529
Return the list of outneighbors of `v` within `mg`.
530530
"""
531531
function Graphs.outneighbors(
532532
mg::M, v::T
533-
) where {M<:AbstractMultilayerGraph{T,<:Real}} where {T}
533+
) where {T, M<:AbstractMultilayerGraph{T}}
534534

535535
_outneighbors = T[]
536536

@@ -780,7 +780,7 @@ degree_variance(mg::AbstractMultilayerGraph) = var(degree(mg))
780780
norm_factor::Union{Float64,Symbol}=:max
781781
)
782782
783-
Return the complete multilayer global clustering coefficient, equal to the ratio of realized triplets over all possible triplets, including those whose every or some edges belong to interlayers, normalized by `norm_factor`. If `norm_factor == :max`, then the ratio is normalized by `maximum(mg.array)`. This function does not override Graphs.jl's `global_clustering_coefficient`, since the latter does not consider cliques where two nodes are the same node but in different layers/interlayers. See [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
783+
Return the complete multilayer global clustering coefficient, equal to the ratio of realized triplets over all possible triplets, including those whose every or some edges belong to interlayers, normalized by `norm_factor`. If `norm_factor == :max`, then the ratio is normalized by `maximum(array(weight_tensor(mg)))`, else it is not normalized. This function does not override Graphs.jl's `global_clustering_coefficient`, since the latter does not consider cliques where two nodes are the same node but in different layers/interlayers. See [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
784784
"""
785785
function multilayer_global_clustering_coefficient(
786786
mg::AbstractMultilayerGraph, norm_factor::Union{Float64,Symbol}=:max
@@ -816,7 +816,7 @@ end
816816
"""
817817
multilayer_weighted_global_clustering_coefficient(mg::M, norm_factor::Union{Float64, Symbol} = :max) where {M <: AbstractMultilayerGraph}
818818
819-
Return the complete multilayer global clustering coefficient, equal to the ratio of realized triplets over all possible triplets, including those whose every or some edges belong to interlayers, normalized by `norm_factor`. Each triplets contributes for `w[1]` if all of its vertices are in one layer, `w[2]` if its vertices span two layers, and `w[3]` if they span 3 layers. If `norm_factor == :max`, then the ratio is normalized by `maximum(mg.array)`. This function does not override Graphs.jl's `global_clustering_coefficient`, since the latter does not consider cliques where two nodes are the same node but in different layers/interlayers. See [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
819+
Return the complete multilayer global clustering coefficient, equal to the ratio of realized triplets over all possible triplets, including those whose every or some edges belong to interlayers, normalized by `norm_factor`. Each triplets contributes for `w[1]` if all of its vertices are in one layer, `w[2]` if its vertices span two layers, and `w[3]` if they span 3 layers. If `norm_factor == :max`, then the ratio is normalized by `maximum(array(weight_tensor(mg)))`, else it is not normalized. This function does not override Graphs.jl's `global_clustering_coefficient`, since the latter does not consider cliques where two nodes are the same node but in different layers/interlayers. See [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
820820
"""
821821
function multilayer_weighted_global_clustering_coefficient(
822822
mg::M, w::Vector{Float64}, norm_factor::Union{Float64,Symbol}=:max
@@ -851,7 +851,7 @@ end
851851
norm_factor::Union{Float64,Symbol}=:max
852852
)
853853
854-
Return the overlay clustering coefficient as calculated in [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022).
854+
Return the overlay clustering coefficient as calculated in [De Domenico et al. (2013)](https://doi.org/10.1103/PhysRevX.3.041022). If `norm_factor == :max`, then the ratio is normalized by `maximum(array(weight_tensor(mg)))`, else it is not normalized.
855855
"""
856856
function overlay_clustering_coefficient(
857857
mg::AbstractMultilayerGraph, norm_factor::Union{Float64,Symbol}=:max

src/abstractmultilayerugraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ Return `true` if `mg` is directed, `false` otherwise.
342342
Graphs.is_directed(mg::M) where {M<:Type{<:AbstractMultilayerUGraph}} = false
343343

344344
"""
345-
inneighbors(mg::M, v::T) where {M <: AbstractMultilayerUGraph{T} } where { T <: Integer}
345+
inneighbors(mg::M, v::T) where {T,M<:AbstractMultilayerUGraph{T,<:Real}}
346346
347347
Return the list of inneighbors of `v` within `mg`.
348348
"""

0 commit comments

Comments
 (0)