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/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/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 diff --git a/test/reorder_by_module.jl b/test/reorder_by_module.jl index 1299821..436a0f6 100644 --- a/test/reorder_by_module.jl +++ b/test/reorder_by_module.jl @@ -1,11 +1,26 @@ module TestReorderByModule using Base.Test using Brim - #=testdir = dirname(@__FILE__)=# + + # 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] + M = no_empty_modules!(Modular(A, S)) + 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