Skip to content

Commit e2f751b

Browse files
authored
Map Inf path lengths to zero (#117)
* Map Inf path lengths to zero * Use FW paths to calculate rna[:averagepath] * Add disconnected graph test for rna * Move :averagepath calculation to separate function * Bump version to v1.5.2
1 parent 4988fd5 commit e2f751b

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# RecurrenceAnalysis.jl News
22

3+
## v1.5.2
4+
- New, faster formula for `rna[:averagepath]` allowing disconnected graphs.
5+
36
## v1.5.1
47
- Minor documentation fixes.
58

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RecurrenceAnalysis"
22
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
33
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
4-
version = "1.5.1"
4+
version = "1.5.2"
55

66
[deps]
77
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"

src/rna.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ function rna(args...; kwargs...)
4343
return Dict{Symbol, Float64}(
4444
:density => density(graph),
4545
:transitivity => global_clustering_coefficient(graph),
46-
:averagepath => mean(1 ./ closeness_centrality(graph)),
46+
:averagepath => averagepath(graph),
4747
:diameter => diameter(graph)
4848
)
4949
end
50+
51+
"""
52+
averagepath(graph)
53+
54+
Calculates average minimum path length for a SimpleGraph.
55+
Uses Donner, 2010, Eq. 26 on pg. 18.
56+
"""
57+
function averagepath(graph::SimpleGraph)
58+
num_verts = nv(graph)
59+
60+
dist_mat = floyd_warshall_shortest_paths(graph).dists
61+
@. dist_mat[dist_mat == typemax(dist_mat)] = 0.
62+
63+
return sum(dist_mat) / (num_verts * (num_verts - 1))
64+
end

test/smallmatrix.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,27 @@ end
184184
@test rna_dict[:transitivity] sum(triangles) / sum(triples)
185185
@test rna_dict[:averagepath] sum(dismat9) / (9*8)
186186
@test rna_dict[:diameter] == maximum(dismat9)
187+
adjmat11 = [0 0 0 1 0 0 0 1 0 0
188+
0 0 0 0 1 0 0 0 1 0
189+
0 0 0 0 0 1 0 0 0 0
190+
1 0 0 0 0 0 1 0 0 0
191+
0 1 0 0 0 0 0 1 0 0
192+
0 0 1 0 0 0 0 0 1 0
193+
0 0 0 1 0 0 0 0 0 0
194+
1 0 0 0 1 0 0 0 0 0
195+
0 1 0 0 0 1 0 0 0 0
196+
0 0 0 0 0 0 0 0 0 0]
197+
dismat11 = [0 3 6 1 2 5 2 1 4 Inf
198+
3 0 3 4 1 2 5 2 1 Inf
199+
6 3 0 7 4 1 8 5 2 Inf
200+
1 4 7 0 3 6 1 2 5 Inf
201+
2 1 4 3 0 3 4 1 2 Inf
202+
5 2 1 6 3 0 7 4 1 Inf
203+
2 5 8 1 4 7 0 3 6 Inf
204+
1 2 5 2 1 4 3 0 3 Inf
205+
4 1 2 5 2 1 6 3 0 Inf
206+
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0]
207+
rna_dict = rna(RecurrenceMatrix(adjmat11))
208+
@test !isinf(rna_dict[:averagepath])
209+
@test rna_dict[:averagepath] sum(dismat11[1:9,1:9]) / (9*10)
187210
end

0 commit comments

Comments
 (0)