Skip to content

Commit

Permalink
fix transitivity (#110)
Browse files Browse the repository at this point in the history
* fix transitivity

* test and fixed docstring

* update Project.toml
  • Loading branch information
heliosdrm authored Dec 13, 2020
1 parent 2511090 commit 1d45308
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RecurrenceAnalysis"
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
version = "1.3.1"
version = "1.3.2"

[deps]
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"
Expand Down
26 changes: 16 additions & 10 deletions src/rqa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,46 @@ recurrence plot `R` is identified as the network adjacency matrix `A`.
We quote from [^Donner2011], where the authors provide a complete description:
Transitivity is related to fundamental algebraic relationships between triples
of discrete objects. Specifically, in graph-theoretical terms, we identify the
set `X` with the set of vertices `V` , and the relation `R with the mutual
set `X` with the set of vertices `V` , and the relation `R` with the mutual
adjacency of pairs of vertices. Hence, for a given vertex `i ∈ V` , transitivity
refers to the fact that for two other vertices `j, k ∈ V` with
`A_ij = A_ik = 1, A_jk = 1` also holds. In a general network, this is typically
not the case for all vertices. Consequently, characterising the degree of
transitivity (or, alternatively, the relative frequency of closed 3-loops, which
are commonly referred to as triangles) with respect to some individual vertex or
are commonly referred to as triangles) with respect to
the whole network provides important information on the structural graph
properties, which may be related to important general features of the underlying
system.
The network transitivity averages the local transitivity or clustering
coefficient
The network transitivity measures the fraction of closed triangles with respect to
the number of linked triples of vertices in the whole network:
```math
\\mathcal{C} = \\frac{number of triangles including vertex i}{number of triples centred on vertex i}
\\mathcal{T} = \\frac{3 \\times \\textrm{number of triangles in the network}}{\\textrm{number of linked triples of vertices}}
```
over the all nodes in the network [^Boccaletti2006]:
or given the adjacency matrix `A`
```math
\\mathcal{T} = \\frac{trace(R^3)}{\\sum R^2}
\\mathcal{T} = \\frac{trace(A^3)}{\\sum(A^2) - trace(A^2)}
```
## References
[^Donner2011]: R.V. Donner *et al.*, [The geometry of chaotic dynamics — a complex network perspective, Eur. Phys. J. B 84, 653–672 (2011)](https://doi.org/10.1140/epjb/e2011-10899-1)
[^Boccaletti2006]: S.Boccaletti *et al.*, [Complex networks: Structure and dynamics, Physics Reports Volume 424, Issues 4–5 (2006)](https://doi.org/10.1016/j.physrep.2005.10.009)
"""
function transitivity(R::ARM)
if size(R, 1) size(R, 2)
@warn "Computing network transitivity of a non-square adjacency matrix is impossible"
return NaN
end
= R.data * R.data
=* R.data
trans = LinearAlgebra.tr(R³) / sum(R²)
numerator = zero(eltype(R²))
for col = 1:size(R,2)
rows = view(rowvals(R), nzrange(R,col))
for r = rows
numerator += R²[r, col]
end
end
trans = numerator / (sum(R²) - LinearAlgebra.tr(R²))
end


Expand Down
13 changes: 13 additions & 0 deletions test/smallmatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,16 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))))
@test rqa_params[:NMPRT] == 3
end
end

### Recurrence network
@testset "Recurrence networks" begin
# 7 edges, 12 linked triples, 1 triangle (1-2-4)
mat = [0 1 0 1 0 0
1 0 1 1 1 0
0 1 0 0 0 0
1 1 0 0 0 1
0 1 0 0 0 1
0 0 0 1 1 0]
adjmat = RecurrenceMatrix(mat)
@test transitivity(adjmat) == 0.25 # (3/12)
end

0 comments on commit 1d45308

Please sign in to comment.