From 2e01b31ef6ac4b940e1418d6aca45478ca4e7815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 7 Sep 2015 22:24:59 -0400 Subject: [PATCH 1/3] Identation and readme --- README.md | 5 +++-- test/reorder_by_module.jl | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbd5583..61e4983 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.16579.svg)](http://dx.doi.org/10.5281/zenodo.16579) [![Documentation Status](https://readthedocs.org/projects/brimjl/badge/?version=latest)](https://readthedocs.org/projects/brimjl/?badge=latest) -Various ways to optimize the modularity of bipartite networks using BRIM in -`Julia`. General purpose, but mostly used for biological and ecological datasets. +This package offers ways to optimize the modularity of bipartite networks using +BRIM in `Julia`. It should be reasonably general purpose, but has only be used +for biological and ecological datasets so far. diff --git a/test/reorder_by_module.jl b/test/reorder_by_module.jl index 1299821..e42f928 100644 --- a/test/reorder_by_module.jl +++ b/test/reorder_by_module.jl @@ -1,11 +1,14 @@ module TestReorderByModule using Base.Test using Brim - #=testdir = dirname(@__FILE__)=# + A = [1 0 0; 0 0 1; 0 1 0] S = [0 1 0; 1 0 0; 0 0 1; 0 1 0; 0 0 1; 0 0 1] C = [1 0 0; 0 1 0; 0 0 1; 0 1 0; 0 0 1; 0 0 1] + M = no_empty_modules!(Modular(A, S)) + reorder_by_module!(M) @test sum(abs(M.S .- C)) == 0 + end From 8d0e0c9b48c8901d39b6042d2e846618d452140e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 7 Sep 2015 22:45:51 -0400 Subject: [PATCH 2/3] New tests for reorder_by_module --- REQUIRE | 2 +- src/Brim.jl | 2 +- test/reorder_by_module.jl | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index f209d7d..c65980e 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,6 @@ julia 0.3 Cairo -Color 0.2.10- +Colors DataFrames Lexicon Logging diff --git a/src/Brim.jl b/src/Brim.jl index 5f1cfa6..3a20ab5 100644 --- a/src/Brim.jl +++ b/src/Brim.jl @@ -2,7 +2,7 @@ module Brim # Dependencies using Cairo -using Color +using Colors using DataFrames using Logging Logging.configure(output=open("brim.log", "a"), level=INFO) diff --git a/test/reorder_by_module.jl b/test/reorder_by_module.jl index e42f928..436a0f6 100644 --- a/test/reorder_by_module.jl +++ b/test/reorder_by_module.jl @@ -2,6 +2,8 @@ module TestReorderByModule using Base.Test using Brim + # Test 1 - simple case + A = [1 0 0; 0 0 1; 0 1 0] S = [0 1 0; 1 0 0; 0 0 1; 0 1 0; 0 0 1; 0 0 1] C = [1 0 0; 0 1 0; 0 0 1; 0 1 0; 0 0 1; 0 0 1] @@ -11,4 +13,14 @@ module TestReorderByModule reorder_by_module!(M) @test sum(abs(M.S .- C)) == 0 + # Test 2 - more complex case + + A = [0 0 0 1 1 1; 1 1 1 0 0 0; 0 0 0 1 1 1; 1 1 1 0 0 0; 0 0 0 1 1 1; 1 1 1 0 0 0] + M = recursive_brim!(partition_random(A)) + reorder_by_module!(M) + + target = [1 0; 1 0; 1 0; 0 1; 0 1; 0 1; 1 0; 1 0; 1 0; 0 1; 0 1; 0 1] + + @test hash(M.S) == hash(target) + end From b325d26a369f5fa67195517aae819205b007f5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 7 Sep 2015 22:48:42 -0400 Subject: [PATCH 3/3] Ensure that all swapped submatrices are 2x2 --- src/permutations.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/permutations.jl b/src/permutations.jl index 3aa64a6..e7ae6cc 100644 --- a/src/permutations.jl +++ b/src/permutations.jl @@ -33,7 +33,7 @@ end Performs a constrained swap: the marginals are conserved. """ function constrained_swap(A::Array{Int64, 2}) - # TODO checks + @assert size(A) == (2, 2) const c1 = [1 0; 0 1] const c2 = [0 1; 1 0] if A == c2 @@ -48,6 +48,7 @@ Perfoms a free swap: the matrix cells are shuffled. The marginals are not (necessarily) conserved. """ function free_swap(A::Array{Int64, 2}) + @assert size(A) == (2, 2) return reshape(A[shuffle([1, 2, 3, 4])], (2, 2)) end