Skip to content

Commit

Permalink
Merge branch '3.4' of https://github.com/tractor/tractor into 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jonclayden committed Feb 22, 2024
2 parents 1754f5e + 48374cb commit 2a93c4d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

Expand All @@ -37,7 +37,7 @@ jobs:

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: lib/R
key: ${{ runner.os }}-deps-${{ matrix.R }}-${{ hashFiles('lib/*/DESCRIPTION') }}
Expand Down
18 changes: 13 additions & 5 deletions tractor.graph/inst/tinytest/test-15-partition.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ expect_true(all(t_partitioned$getVertexWeights() %in% 0:1))
expect_equal_to_reference(modularityMatrix(graph), "modmat.rds")
expect_true(modularity(t_partitioned) >= 0)
expect_true(modularity(t_partitioned) <= 1)
i_partitioned <- igraph::cluster_leading_eigen(as(graph, "igraph"))
expect_equal(modularity(t_partitioned), igraph::modularity(i_partitioned), tolerance=1e-3)

if (requireNamespace("igraph", quietly=TRUE))
{
i_partitioned <- igraph::cluster_leading_eigen(as(graph, "igraph"))
expect_equal(modularity(t_partitioned), igraph::modularity(i_partitioned), tolerance=1e-3)
}

# Binarised version
graph$binarise()
t_partitioned <- partitionGraph(graph, method="modularity")
expect_equal(t_partitioned$nCommunities(), 3L)
expect_true(all(t_partitioned$getVertexWeights() %in% 0:1))
i_partitioned <- igraph::cluster_leading_eigen(as(graph, "igraph"))
expect_true(membershipMatches(t_partitioned$getVertexMemberships(), i_partitioned$membership))
expect_equal(modularity(t_partitioned), igraph::modularity(i_partitioned))

if (requireNamespace("igraph", quietly=TRUE))
{
i_partitioned <- igraph::cluster_leading_eigen(as(graph, "igraph"))
expect_true(membershipMatches(t_partitioned$getVertexMemberships(), i_partitioned$membership))
expect_equal(modularity(t_partitioned), igraph::modularity(i_partitioned))
}

graph <- readGraphFile("graph")
pn <- principalNetworks(graph)$graph$serialise()
Expand Down
27 changes: 18 additions & 9 deletions tractor.graph/inst/tinytest/test-20-fuzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ testMetricAgreement <- function (t_graph, i_graph = as(t_graph,"igraph"))
i_density <- igraph::edge_density(i_graph, loops=t_graph$isSelfConnected())
expect_equal(t_density, i_density, info=info)

# Some metrics are not supported by igraph for directed graphs
if (!t_graph$isDirected())
{
# Clustering coefficients
# igraph returns NaN when there are no triangles
i_clustering <- igraph::transitivity(i_graph, "barrat", isolates="zero")
expect_equal(clusteringCoefficients(t_graph,method="barrat"), i_clustering, info=info)

# Laplacian matrix
expect_equivalent(laplacianMatrix(t_graph), igraph::laplacian_matrix(i_graph,sparse=FALSE), info=info)
}

# Convert weights to costs
# NB: this is needed only for quantities tested below, so timing of the
# inversion is significant
if (t_graph$isWeighted())
igraph::E(i_graph)$weight <- 1 / igraph::E(i_graph)$weight

Expand All @@ -50,23 +64,18 @@ testMetricAgreement <- function (t_graph, i_graph = as(t_graph,"igraph"))
expect_equivalent(graphEfficiency(t_graph,type="global"), i_global_eff, info=info)

# Some metrics are not supported by igraph for directed graphs
if(!t_graph$isDirected())
if (!t_graph$isDirected())
{
# Clustering coefficients
# igraph returns NaN when there are no triangles
i_clustering <- igraph::transitivity(i_graph, "barrat", isolates="zero")
expect_equal(clusteringCoefficients(t_graph,method="barrat"), i_clustering, info=info)

# Betweenness centrality
t_bc <- structure(betweennessCentrality(t_graph$getAssociationMatrix()), dim=NULL)
i_bc <- igraph::betweenness(i_graph)
expect_equal(t_bc, 2*i_bc, info=info)

# Laplacian matrix
expect_equivalent(laplacianMatrix(t_graph), igraph::laplacian_matrix(i_graph,sparse=FALSE), info=info)
}
}

if (!requireNamespace("igraph", quietly=TRUE))
exit_file("The \"igraph\" package is not available")

# Random binary graph
testMetricAgreement(randomGraph(10, M=20))

Expand Down

0 comments on commit 2a93c4d

Please sign in to comment.