Skip to content

Commit

Permalink
Merge pull request #12 from PoisotLab/dev-reorder
Browse files Browse the repository at this point in the history
✅  new tests
  • Loading branch information
Timothée Poisot committed Sep 8, 2015
2 parents 3708139 + b325d26 commit 3031615
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,6 +1,6 @@
julia 0.3
Cairo
Color 0.2.10-
Colors
DataFrames
Lexicon
Logging
Expand Down
2 changes: 1 addition & 1 deletion src/Brim.jl
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/permutations.jl
Expand Up @@ -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
Expand All @@ -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

Expand Down
17 changes: 16 additions & 1 deletion 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

0 comments on commit 3031615

Please sign in to comment.