From ca19645e172643dd69450660cf85b98493cba973 Mon Sep 17 00:00:00 2001 From: Alberto Pessia Date: Wed, 15 Feb 2017 15:18:52 +0200 Subject: [PATCH 1/2] Change 'shuffle!' function name Avoid shadowing of 'Base.shuffle!' function --- src/mcmc/algorithm.jl | 4 ++-- src/mcmc/gibbs.jl | 2 +- src/misc/basic_functions.jl | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mcmc/algorithm.jl b/src/mcmc/algorithm.jl index 528f85f..5864b67 100644 --- a/src/mcmc/algorithm.jl +++ b/src/mcmc/algorithm.jl @@ -316,7 +316,7 @@ function splitmerge!(ij::Vector{Int}, end end - shuffle!(neighbours, S) + shuffleunits!(neighbours, S) split!(ij, neighbours, S, data, priorR, priorC, settings, support, state) else @@ -336,7 +336,7 @@ function splitmerge!(ij::Vector{Int}, end end - shuffle!(neighbours, S) + shuffleunits!(neighbours, S) merge!(ij, neighbours, S, data, priorR, priorC, settings, support, state) end diff --git a/src/mcmc/gibbs.jl b/src/mcmc/gibbs.jl index 69e24bd..a3d7659 100644 --- a/src/mcmc/gibbs.jl +++ b/src/mcmc/gibbs.jl @@ -6,7 +6,7 @@ function gibbs!(data::Matrix{UInt8}, settings::KSettings, support::MCMCSupport, state::AminoAcidState) - shuffle!(support.u) + shuffleunits!(support.u) for a in support.u resizesupport!(support, state.k + 1) diff --git a/src/misc/basic_functions.jl b/src/misc/basic_functions.jl index ebabd78..124ab24 100644 --- a/src/misc/basic_functions.jl +++ b/src/misc/basic_functions.jl @@ -1,6 +1,6 @@ # This file is part of Kpax3. License is MIT. -function shuffle!(x::Vector{Int}) +function shuffleunits!(x::Vector{Int}) for i = length(x):-1:2 j = rand(1:i) x[i], x[j] = x[j], x[i] @@ -9,8 +9,8 @@ function shuffle!(x::Vector{Int}) nothing end -function shuffle!(x::Vector{Int}, - S::Int) +function shuffleunits!(x::Vector{Int}, + S::Int) for i = S:-1:2 j = rand(1:i) x[i], x[j] = x[j], x[i] From 948a220516c6bbe54bba93917afbb1cfc9545a89 Mon Sep 17 00:00:00 2001 From: Alberto Pessia Date: Wed, 15 Feb 2017 15:20:15 +0200 Subject: [PATCH 2/2] Change the style of test functions Avoid the use of 'boot.jl' file --- src/boot.jl | 33 --- test/data_processing/data_processing.jl | 110 +++---- test/distances/jaccard.jl | 307 ++++++++++---------- test/distances/simovici_jaroszewicz.jl | 302 ++++++++----------- test/estimate/write.jl | 17 +- test/mcmc/biased_random_walk.jl | 130 ++++----- test/mcmc/diagnostics.jl | 34 +-- test/mcmc/gibbs.jl | 371 ++++++++++-------------- test/mcmc/log_likelihoods.jl | 38 +-- test/mcmc/merge.jl | 218 ++++---------- test/mcmc/partition_ratios.jl | 33 +-- test/mcmc/posterior.jl | 111 ++++--- test/mcmc/split.jl | 294 ++++++------------- test/mcmc/weight.jl | 32 +- test/misc/basic_functions.jl | 8 +- test/misc/partition_functions.jl | 22 +- test/model/likelihoods.jl | 102 +++---- test/model/loss_binder.jl | 20 +- test/model/partition_cols.jl | 53 ++-- test/model/partition_rows.jl | 16 +- test/optimizer/crossover.jl | 40 +-- test/optimizer/local_mode.jl | 129 ++++---- test/optimizer/mutation.jl | 7 +- test/optimizer/selection.jl | 18 +- test/runtests.jl | 88 +++--- test/types/data.jl | 142 ++++----- test/types/prior_col.jl | 14 +- test/types/prior_row.jl | 42 +-- test/types/settings.jl | 70 ++--- test/types/state.jl | 235 +++++++-------- test/types/state_list.jl | 35 ++- test/types/support.jl | 77 ++--- 32 files changed, 1299 insertions(+), 1849 deletions(-) delete mode 100644 src/boot.jl diff --git a/src/boot.jl b/src/boot.jl deleted file mode 100644 index a5eed98..0000000 --- a/src/boot.jl +++ /dev/null @@ -1,33 +0,0 @@ -# This file is part of Kpax3. License is MIT. - -################# -# Load packages # -################# -import Clustering -import Distances -import FileIO -import JLD -import Gadfly -import Measures -import StatsBase - -############## -# Load Types # -############## -include("types/types.jl") - -######################## -# Load basic functions # -######################## -include("misc/misc.jl") - -################# -# Load the rest # -################# -include("data_processing/data_processing.jl") -include("distances/distances.jl") -include("model/model.jl") -include("optimizer/optimizer.jl") -include("mcmc/mcmc.jl") -include("estimate/estimate.jl") -include("plots/plots.jl") diff --git a/test/data_processing/data_processing.jl b/test/data_processing/data_processing.jl index ce458c6..c3cbdcb 100644 --- a/test/data_processing/data_processing.jl +++ b/test/data_processing/data_processing.jl @@ -1,22 +1,15 @@ # This file is part of Kpax3. License is MIT. function test_data_processing_exceptions() - missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', - 'v', 'w', 'x', 'y', 'j', 'z'] - - @test_throws KFASTAError readfasta("data/empty_file.fasta", false, missdna, - 100000000, false, 0) - @test_throws KFASTAError readfasta("data/no_1st_seq.fasta", false, missdna, - 100000000, false, 0) - @test_throws KFASTAError readfasta("data/no_id_char.fasta", false, missdna, - 100000000, false, 0) - @test_throws KFASTAError readfasta("data/no_nth_seq.fasta", false, missdna, - 100000000, false, 0) - - @test_throws KFASTAError readfasta("data/utf8_id.fasta", false, missdna, - 100000000, false, 0) - @test_throws KFASTAError readfasta("data/utf8_seq.fasta", false, missdna, - 100000000, false, 0) + missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] + + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/empty_file.fasta", false, missdna, 100000000, false, 0) + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_1st_seq.fasta", false, missdna, 100000000, false, 0) + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_id_char.fasta", false, missdna, 100000000, false, 0) + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/no_nth_seq.fasta", false, missdna, 100000000, false, 0) + + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/utf8_id.fasta", false, missdna, 100000000, false, 0) + @test_throws Kpax3.KFASTAError Kpax3.readfasta("data/utf8_seq.fasta", false, missdna, 100000000, false, 0) nothing end @@ -24,11 +17,9 @@ end test_data_processing_exceptions() function test_data_processing_read_blanks() - missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', - 'v', 'w', 'x', 'y', 'j', 'z'] + missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] - (data, id, refseq) = readfasta("data/blanks.fasta", false, missdna, - 100000000, false, 0) + (data, id, refseq) = Kpax3.readfasta("data/blanks.fasta", false, missdna, 100000000, false, 0) @test data == UInt8['g' 'a'; 'a' 'g'; 'g' 'c'; @@ -36,12 +27,11 @@ function test_data_processing_read_blanks() 'a' 'g'; 'g' 'c'] @test id == String["ID1", "ID5"] - @test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] + @test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] - @test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('?')) + @test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('?')) - (bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?')) + (bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?')) @test bindata == UInt8[0 1; 1 0; 1 0; @@ -54,12 +44,10 @@ function test_data_processing_read_blanks() 0 1; 0 1; 1 0] - @test val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', - 'g'] + @test val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g'] @test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] - (data, id, refseq) = readfasta("data/blanks.fasta", false, missdna, 1, false, - 0) + (data, id, refseq) = Kpax3.readfasta("data/blanks.fasta", false, missdna, 1, false, 0) @test data == UInt8['g' 'a'; 'a' 'g'; 'g' 'c'; @@ -67,8 +55,7 @@ function test_data_processing_read_blanks() 'a' 'g'; 'g' 'c'] @test id == String["ID1", "ID5"] - @test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] + @test refseq == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] nothing end @@ -76,11 +63,9 @@ end test_data_processing_read_blanks() function test_data_processing_proper_dna_file() - missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', - 'v', 'w', 'x', 'y', 'j', 'z'] + missdna = UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] - (data, id, refseq) = readfasta("data/proper_nt.fasta", false, missdna, - 100000000, false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, missdna, 100000000, false, 0) @test data == UInt8['t' 't' 't' 't' 't' 'c'; 'g' 'g' 'a' 'g' 'a' 'a'; @@ -91,12 +76,11 @@ function test_data_processing_proper_dna_file() 'a' 'a' 't' 't' 'a' 'a'; 'g' 'c' 'g' 'g' 'c' 'g'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - 'a'] + @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a'] - @test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('?')) + @test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('?')) - (bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?')) + (bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?')) @test bindata == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -115,12 +99,10 @@ function test_data_processing_proper_dna_file() 0 0 1 1 0 0; 0 1 0 0 1 0; 1 0 1 1 0 1] - @test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', - 'a', 'g', 't', 'a', 't', 'c', 'g'] + @test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g'] @test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] - (data, id, refseq) = readfasta("data/proper_nt.fasta", false, missdna, 1, - false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, missdna, 1, false, 0) @test data == UInt8['t' 't' 't' 't' 't' 'c'; 'g' 'g' 'a' 'g' 'a' 'a'; 'a' 'a' '?' 'g' 'g' '?'; @@ -130,12 +112,10 @@ function test_data_processing_proper_dna_file() 'a' 'a' 't' 't' 'a' 'a'; 'g' 'c' 'g' 'g' 'c' 'g'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - 'a'] + @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a'] # consider all characters - (data, id, refseq) = readfasta("data/proper_nt.fasta", false, - zeros(UInt8, 1), 100000000, false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_nt.fasta", false, zeros(UInt8, 1), 100000000, false, 0) @test data == UInt8['t' 't' 't' 't' 't' 'c'; 'g' 'g' 'a' 'g' 'a' 'a'; 'a' 'a' 'x' 'g' 'g' 'x'; @@ -146,12 +126,11 @@ function test_data_processing_proper_dna_file() 'g' 'c' 'g' 'g' 'c' 'g'; 'a' 'x' 'a' 'a' 'a' 'a'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - '.'] + @test refseq == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', '.'] - @test_throws KDomainError categorical2binary(data, UInt8(1), UInt8('\0')) + @test_throws Kpax3.KDomainError Kpax3.categorical2binary(data, UInt8(1), UInt8('\0')) - (bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('\0')) + (bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('\0')) @test bindata == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -173,8 +152,7 @@ function test_data_processing_proper_dna_file() 1 0 1 1 0 1; 1 0 1 1 1 1; 0 1 0 0 0 0] - @test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c', - 'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x'] + @test val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x'] @test key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9] nothing @@ -185,8 +163,7 @@ test_data_processing_proper_dna_file() function test_data_processing_proper_protein_file() misspro = UInt8['?', '*', '#', '-', 'b', 'j', 'x', 'z'] - (data, id, refseq) = readfasta("data/proper_aa.fasta", true, misspro, - 100000000, false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, misspro, 100000000, false, 0) @test data == UInt8['k' 'k' 'k' 'k' 'k' 'e'; 'k' 'k' 'i' 'k' 'i' 'i'; @@ -197,10 +174,9 @@ function test_data_processing_proper_protein_file() 'c' 'c' 'y' 'y' 'c' 'c'; 'a' 'a' 't' 'a' 't' 't'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - 'f'] + @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f'] - (bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('?')) + (bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('?')) @test bindata == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -219,12 +195,10 @@ function test_data_processing_proper_protein_file() 0 0 1 1 0 0; 1 1 0 1 0 0; 0 0 1 0 1 1] - @test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', - 'e', 'l', 'm', 'c', 'y', 'a', 't'] + @test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't'] @test key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] - (data, id, refseq) = readfasta("data/proper_aa.fasta", true, misspro, 1, - false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, misspro, 1, false, 0) @test data == UInt8['k' 'k' 'k' 'k' 'k' 'e'; 'k' 'k' 'i' 'k' 'i' 'i'; 'l' 'l' '?' 'v' 'v' '?'; @@ -234,12 +208,10 @@ function test_data_processing_proper_protein_file() 'c' 'c' 'y' 'y' 'c' 'c'; 'a' 'a' 't' 'a' 't' 't'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - 'f'] + @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f'] # consider all characters - (data, id, refseq) = readfasta("data/proper_aa.fasta", true, zeros(UInt8, 1), - 100000000, false, 0) + (data, id, refseq) = Kpax3.readfasta("data/proper_aa.fasta", true, zeros(UInt8, 1), 100000000, false, 0) @test data == UInt8['k' 'k' 'k' 'k' 'k' 'e'; 'k' 'k' 'i' 'k' 'i' 'i'; 'l' 'l' 'x' 'v' 'v' 'x'; @@ -250,10 +222,9 @@ function test_data_processing_proper_protein_file() 'a' 'a' 't' 'a' 't' 't'; 'f' 'x' 'f' 'f' 'f' 'f'] @test id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - '.'] + @test refseq == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', '.'] - (bindata, val, key) = categorical2binary(data, UInt8(127), UInt8('\0')) + (bindata, val, key) = Kpax3.categorical2binary(data, UInt8(127), UInt8('\0')) @test bindata == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -275,8 +246,7 @@ function test_data_processing_proper_protein_file() 0 0 1 0 1 1; 1 0 1 1 1 1; 0 1 0 0 0 0] - @test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l', - 't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x'] + @test val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x'] @test key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9] nothing diff --git a/test/distances/jaccard.jl b/test/distances/jaccard.jl index ba32417..50d1f8d 100644 --- a/test/distances/jaccard.jl +++ b/test/distances/jaccard.jl @@ -25,167 +25,152 @@ function test_jaccard_distance() nt = [1; 1; 1; 1; 1; 1] kt = 6 - @test jaccard(u, ku, u, ku, v) == 0.0 - @test jaccard_index_basic(u, u, v) == 1.0 - @test jaccard_index_table(u, ku, u, ku, v) == 1.0 - - @test_approx_eq jaccard(u, ku, a, ka, v) 0.5333333333333333 - @test_approx_eq jaccard(u, ku, b, kb, v) 0.8 - @test_approx_eq jaccard(u, ku, c, kc, v) 0.8666666666666667 - @test_approx_eq jaccard(u, ku, d, kd, v) 0.9333333333333333 - @test_approx_eq jaccard(u, ku, t, kt, v) 1.0 - - @test_approx_eq jaccard_index_basic(u, a, v) 0.4666666666666667 - @test_approx_eq jaccard_index_basic(u, b, v) 0.2 - @test_approx_eq jaccard_index_basic(u, c, v) 0.1333333333333333 - @test_approx_eq jaccard_index_basic(u, d, v) 0.0666666666666667 - @test_approx_eq jaccard_index_basic(u, t, v) 0.0 - - @test_approx_eq jaccard_index_table(u, ku, a, ka, v) 0.4666666666666667 - @test_approx_eq jaccard_index_table(u, ku, b, kb, v) 0.2 - @test_approx_eq jaccard_index_table(u, ku, c, kc, v) 0.1333333333333333 - @test_approx_eq jaccard_index_table(u, ku, d, kd, v) 0.0666666666666667 - @test_approx_eq jaccard_index_table(u, ku, t, kt, v) 0.0 - - @test_approx_eq jaccardlower(na, ka, v) 0.5333333333333333 - @test_approx_eq jaccardlower(nb, kb, v) 0.8 - @test_approx_eq jaccardlower(nc, kc, v) 0.8666666666666667 - @test_approx_eq jaccardlower(nd, kd, v) 0.9333333333333333 - @test_approx_eq jaccardlower(nt, kt, v) 1.0 - - @test jaccard(a, ka, a, ka, v) == 0.0 - @test jaccard_index_basic(a, a, v) == 1.0 - @test jaccard_index_table(a, ka, a, ka, v) == 1.0 - - @test_approx_eq jaccard(a, ka, u, ku, v) 0.5333333333333333 - @test_approx_eq jaccard(a, ka, b, kb, v) 0.8888888888888889 - @test_approx_eq jaccard(a, ka, c, kc, v) 0.875 - @test_approx_eq jaccard(a, ka, d, kd, v) 0.8571428571428572 - @test_approx_eq jaccard(a, ka, t, kt, v) 1.0 - - @test_approx_eq jaccard_index_basic(a, u, v) 0.4666666666666667 - @test_approx_eq jaccard_index_basic(a, b, v) 0.1111111111111111 - @test_approx_eq jaccard_index_basic(a, c, v) 0.125 - @test_approx_eq jaccard_index_basic(a, d, v) 0.1428571428571428 - @test_approx_eq jaccard_index_basic(a, t, v) 0.0 - - @test_approx_eq jaccard_index_table(a, ka, u, ku, v) 0.4666666666666667 - @test_approx_eq jaccard_index_table(a, ka, b, kb, v) 0.1111111111111111 - @test_approx_eq jaccard_index_table(a, ka, c, kc, v) 0.125 - @test_approx_eq jaccard_index_table(a, ka, d, kd, v) 0.1428571428571428 - @test_approx_eq jaccard_index_table(a, ka, t, kt, v) 0.0 - - @test jaccard(b, kb, b, kb, v) == 0.0 - @test jaccard_index_basic(b, b, v) == 1.0 - @test jaccard_index_table(b, kb, b, kb, v) == 1.0 - - @test_approx_eq jaccard(b, kb, u, ku, v) 0.8 - @test_approx_eq jaccard(b, kb, a, ka, v) 0.8888888888888889 - @test_approx_eq jaccard(b, kb, c, kc, v) 1.0 - @test_approx_eq jaccard(b, kb, d, kd, v) 1.0 - @test_approx_eq jaccard(b, kb, t, kt, v) 1.0 - - @test_approx_eq jaccard_index_basic(b, u, v) 0.2 - @test_approx_eq jaccard_index_basic(b, a, v) 0.1111111111111111 - @test_approx_eq jaccard_index_basic(b, c, v) 0.0 - @test_approx_eq jaccard_index_basic(b, d, v) 0.0 - @test_approx_eq jaccard_index_basic(b, t, v) 0.0 - - @test_approx_eq jaccard_index_table(b, kb, u, ku, v) 0.2 - @test_approx_eq jaccard_index_table(b, kb, a, ka, v) 0.1111111111111111 - @test_approx_eq jaccard_index_table(b, kb, c, kc, v) 0.0 - @test_approx_eq jaccard_index_table(b, kb, d, kd, v) 0.0 - @test_approx_eq jaccard_index_table(b, kb, t, kt, v) 0.0 - - @test jaccard(c, kc, c, kc, v) == 0.0 - @test jaccard_index_basic(c, c, v) == 1.0 - @test jaccard_index_table(c, kc, c, kc, v) == 1.0 - - @test_approx_eq jaccard(c, kc, u, ku, v) 0.8666666666666667 - @test_approx_eq jaccard(c, kc, a, ka, v) 0.875 - @test_approx_eq jaccard(c, kc, b, kb, v) 1.0 - @test_approx_eq jaccard(c, kc, d, kd, v) 0.5 - @test_approx_eq jaccard(c, kc, t, kt, v) 1.0 - - @test_approx_eq jaccard_index_basic(c, u, v) 0.1333333333333333 - @test_approx_eq jaccard_index_basic(c, a, v) 0.125 - @test_approx_eq jaccard_index_basic(c, b, v) 0.0 - @test_approx_eq jaccard_index_basic(c, d, v) 0.5 - @test_approx_eq jaccard_index_basic(c, t, v) 0.0 - - @test_approx_eq jaccard_index_table(c, kc, u, ku, v) 0.1333333333333333 - @test_approx_eq jaccard_index_table(c, kc, a, ka, v) 0.125 - @test_approx_eq jaccard_index_table(c, kc, b, kb, v) 0.0 - @test_approx_eq jaccard_index_table(c, kc, d, kd, v) 0.5 - @test_approx_eq jaccard_index_table(c, kc, t, kt, v) 0.0 - - @test jaccard(d, kd, d, kd, v) == 0.0 - @test jaccard_index_basic(d, d, v) == 1.0 - @test jaccard_index_table(d, kd, d, kd, v) == 1.0 - - @test_approx_eq jaccard(d, kd, u, ku, v) 0.9333333333333333 - @test_approx_eq jaccard(d, kd, a, ka, v) 0.8571428571428572 - @test_approx_eq jaccard(d, kd, b, kb, v) 1.0 - @test_approx_eq jaccard(d, kd, c, kc, v) 0.5 - @test_approx_eq jaccard(d, kd, t, kt, v) 1.0 - - @test_approx_eq jaccard_index_basic(d, u, v) 0.0666666666666667 - @test_approx_eq jaccard_index_basic(d, a, v) 0.1428571428571428 - @test_approx_eq jaccard_index_basic(d, b, v) 0.0 - @test_approx_eq jaccard_index_basic(d, c, v) 0.5 - @test_approx_eq jaccard_index_basic(d, t, v) 0.0 - - @test_approx_eq jaccard_index_table(d, kd, u, ku, v) 0.0666666666666667 - @test_approx_eq jaccard_index_table(d, kd, a, ka, v) 0.1428571428571428 - @test_approx_eq jaccard_index_table(d, kd, b, kb, v) 0.0 - @test_approx_eq jaccard_index_table(d, kd, c, kc, v) 0.5 - @test_approx_eq jaccard_index_table(d, kd, t, kt, v) 0.0 - - @test jaccard(t, kt, t, kt, v) == 0.0 - @test jaccard_index_basic(t, t, v) == 1.0 - @test jaccard_index_table(t, kt, t, kt, v) == 1.0 - - @test_approx_eq jaccard(t, kt, u, ku, v) 1.0 - @test_approx_eq jaccard(t, kt, a, ka, v) 1.0 - @test_approx_eq jaccard(t, kt, b, kb, v) 1.0 - @test_approx_eq jaccard(t, kt, c, kc, v) 1.0 - @test_approx_eq jaccard(t, kt, d, kd, v) 1.0 - - @test_approx_eq jaccard_index_basic(t, u, v) 0.0 - @test_approx_eq jaccard_index_basic(t, a, v) 0.0 - @test_approx_eq jaccard_index_basic(t, b, v) 0.0 - @test_approx_eq jaccard_index_basic(t, c, v) 0.0 - @test_approx_eq jaccard_index_basic(t, d, v) 0.0 - - @test_approx_eq jaccard_index_table(t, kt, u, ku, v) 0.0 - @test_approx_eq jaccard_index_table(t, kt, a, ka, v) 0.0 - @test_approx_eq jaccard_index_table(t, kt, b, kb, v) 0.0 - @test_approx_eq jaccard_index_table(t, kt, c, kc, v) 0.0 - @test_approx_eq jaccard_index_table(t, kt, d, kd, v) 0.0 - - @test jaccard(u, ku, t, kt, v) <= - (jaccard(u, ku, b, kb, v) + jaccard(b, kb, t, kt, v)) - - @test jaccard(a, ka, b, kb, v) <= - (jaccard(a, ka, c, kc, v) + jaccard(c, kc, b, kb, v)) - - @test jaccard(b, kb, c, kc, v) <= - (jaccard(b, kb, d, kd, v) + jaccard(d, kd, c, kc, v)) - - @test jaccard(c, kc, d, kd, v) <= - (jaccard(c, kc, a, ka, v) + jaccard(a, ka, d, kd, v)) - - @test jaccard(a, ka, b, kb, v) <= - (jaccard(a, ka, u, ku, v) + jaccard(u, ku, b, kb, v)) - - @test jaccard(a, ka, b, kb, v) <= - (jaccard(a, ka, t, kt, v) + jaccard(t, kt, b, kb, v)) - - @test jaccard(a, ka, d, kd, v) <= - (jaccard(a, ka, u, ku, v) + jaccard(u, ku, d, kd, v)) - - @test jaccard(a, ka, d, kd, v) <= - (jaccard(a, ka, t, kt, v) + jaccard(t, kt, d, kd, v)) + @test Kpax3.jaccard(u, ku, u, ku, v) == 0.0 + @test Kpax3.jaccard_index_basic(u, u, v) == 1.0 + @test Kpax3.jaccard_index_table(u, ku, u, ku, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(u, ku, a, ka, v) 0.5333333333333333 + @test_approx_eq Kpax3.jaccard(u, ku, b, kb, v) 0.8 + @test_approx_eq Kpax3.jaccard(u, ku, c, kc, v) 0.8666666666666667 + @test_approx_eq Kpax3.jaccard(u, ku, d, kd, v) 0.9333333333333333 + @test_approx_eq Kpax3.jaccard(u, ku, t, kt, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(u, a, v) 0.4666666666666667 + @test_approx_eq Kpax3.jaccard_index_basic(u, b, v) 0.2 + @test_approx_eq Kpax3.jaccard_index_basic(u, c, v) 0.1333333333333333 + @test_approx_eq Kpax3.jaccard_index_basic(u, d, v) 0.0666666666666667 + @test_approx_eq Kpax3.jaccard_index_basic(u, t, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(u, ku, a, ka, v) 0.4666666666666667 + @test_approx_eq Kpax3.jaccard_index_table(u, ku, b, kb, v) 0.2 + @test_approx_eq Kpax3.jaccard_index_table(u, ku, c, kc, v) 0.1333333333333333 + @test_approx_eq Kpax3.jaccard_index_table(u, ku, d, kd, v) 0.0666666666666667 + @test_approx_eq Kpax3.jaccard_index_table(u, ku, t, kt, v) 0.0 + + @test_approx_eq Kpax3.jaccardlower(na, ka, v) 0.5333333333333333 + @test_approx_eq Kpax3.jaccardlower(nb, kb, v) 0.8 + @test_approx_eq Kpax3.jaccardlower(nc, kc, v) 0.8666666666666667 + @test_approx_eq Kpax3.jaccardlower(nd, kd, v) 0.9333333333333333 + @test_approx_eq Kpax3.jaccardlower(nt, kt, v) 1.0 + + @test Kpax3.jaccard(a, ka, a, ka, v) == 0.0 + @test Kpax3.jaccard_index_basic(a, a, v) == 1.0 + @test Kpax3.jaccard_index_table(a, ka, a, ka, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(a, ka, u, ku, v) 0.5333333333333333 + @test_approx_eq Kpax3.jaccard(a, ka, b, kb, v) 0.8888888888888889 + @test_approx_eq Kpax3.jaccard(a, ka, c, kc, v) 0.875 + @test_approx_eq Kpax3.jaccard(a, ka, d, kd, v) 0.8571428571428572 + @test_approx_eq Kpax3.jaccard(a, ka, t, kt, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(a, u, v) 0.4666666666666667 + @test_approx_eq Kpax3.jaccard_index_basic(a, b, v) 0.1111111111111111 + @test_approx_eq Kpax3.jaccard_index_basic(a, c, v) 0.125 + @test_approx_eq Kpax3.jaccard_index_basic(a, d, v) 0.1428571428571428 + @test_approx_eq Kpax3.jaccard_index_basic(a, t, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(a, ka, u, ku, v) 0.4666666666666667 + @test_approx_eq Kpax3.jaccard_index_table(a, ka, b, kb, v) 0.1111111111111111 + @test_approx_eq Kpax3.jaccard_index_table(a, ka, c, kc, v) 0.125 + @test_approx_eq Kpax3.jaccard_index_table(a, ka, d, kd, v) 0.1428571428571428 + @test_approx_eq Kpax3.jaccard_index_table(a, ka, t, kt, v) 0.0 + + @test Kpax3.jaccard(b, kb, b, kb, v) == 0.0 + @test Kpax3.jaccard_index_basic(b, b, v) == 1.0 + @test Kpax3.jaccard_index_table(b, kb, b, kb, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(b, kb, u, ku, v) 0.8 + @test_approx_eq Kpax3.jaccard(b, kb, a, ka, v) 0.8888888888888889 + @test_approx_eq Kpax3.jaccard(b, kb, c, kc, v) 1.0 + @test_approx_eq Kpax3.jaccard(b, kb, d, kd, v) 1.0 + @test_approx_eq Kpax3.jaccard(b, kb, t, kt, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(b, u, v) 0.2 + @test_approx_eq Kpax3.jaccard_index_basic(b, a, v) 0.1111111111111111 + @test_approx_eq Kpax3.jaccard_index_basic(b, c, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(b, d, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(b, t, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(b, kb, u, ku, v) 0.2 + @test_approx_eq Kpax3.jaccard_index_table(b, kb, a, ka, v) 0.1111111111111111 + @test_approx_eq Kpax3.jaccard_index_table(b, kb, c, kc, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(b, kb, d, kd, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(b, kb, t, kt, v) 0.0 + + @test Kpax3.jaccard(c, kc, c, kc, v) == 0.0 + @test Kpax3.jaccard_index_basic(c, c, v) == 1.0 + @test Kpax3.jaccard_index_table(c, kc, c, kc, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(c, kc, u, ku, v) 0.8666666666666667 + @test_approx_eq Kpax3.jaccard(c, kc, a, ka, v) 0.875 + @test_approx_eq Kpax3.jaccard(c, kc, b, kb, v) 1.0 + @test_approx_eq Kpax3.jaccard(c, kc, d, kd, v) 0.5 + @test_approx_eq Kpax3.jaccard(c, kc, t, kt, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(c, u, v) 0.1333333333333333 + @test_approx_eq Kpax3.jaccard_index_basic(c, a, v) 0.125 + @test_approx_eq Kpax3.jaccard_index_basic(c, b, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(c, d, v) 0.5 + @test_approx_eq Kpax3.jaccard_index_basic(c, t, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(c, kc, u, ku, v) 0.1333333333333333 + @test_approx_eq Kpax3.jaccard_index_table(c, kc, a, ka, v) 0.125 + @test_approx_eq Kpax3.jaccard_index_table(c, kc, b, kb, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(c, kc, d, kd, v) 0.5 + @test_approx_eq Kpax3.jaccard_index_table(c, kc, t, kt, v) 0.0 + + @test Kpax3.jaccard(d, kd, d, kd, v) == 0.0 + @test Kpax3.jaccard_index_basic(d, d, v) == 1.0 + @test Kpax3.jaccard_index_table(d, kd, d, kd, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(d, kd, u, ku, v) 0.9333333333333333 + @test_approx_eq Kpax3.jaccard(d, kd, a, ka, v) 0.8571428571428572 + @test_approx_eq Kpax3.jaccard(d, kd, b, kb, v) 1.0 + @test_approx_eq Kpax3.jaccard(d, kd, c, kc, v) 0.5 + @test_approx_eq Kpax3.jaccard(d, kd, t, kt, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(d, u, v) 0.0666666666666667 + @test_approx_eq Kpax3.jaccard_index_basic(d, a, v) 0.1428571428571428 + @test_approx_eq Kpax3.jaccard_index_basic(d, b, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(d, c, v) 0.5 + @test_approx_eq Kpax3.jaccard_index_basic(d, t, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(d, kd, u, ku, v) 0.0666666666666667 + @test_approx_eq Kpax3.jaccard_index_table(d, kd, a, ka, v) 0.1428571428571428 + @test_approx_eq Kpax3.jaccard_index_table(d, kd, b, kb, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(d, kd, c, kc, v) 0.5 + @test_approx_eq Kpax3.jaccard_index_table(d, kd, t, kt, v) 0.0 + + @test Kpax3.jaccard(t, kt, t, kt, v) == 0.0 + @test Kpax3.jaccard_index_basic(t, t, v) == 1.0 + @test Kpax3.jaccard_index_table(t, kt, t, kt, v) == 1.0 + + @test_approx_eq Kpax3.jaccard(t, kt, u, ku, v) 1.0 + @test_approx_eq Kpax3.jaccard(t, kt, a, ka, v) 1.0 + @test_approx_eq Kpax3.jaccard(t, kt, b, kb, v) 1.0 + @test_approx_eq Kpax3.jaccard(t, kt, c, kc, v) 1.0 + @test_approx_eq Kpax3.jaccard(t, kt, d, kd, v) 1.0 + + @test_approx_eq Kpax3.jaccard_index_basic(t, u, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(t, a, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(t, b, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(t, c, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_basic(t, d, v) 0.0 + + @test_approx_eq Kpax3.jaccard_index_table(t, kt, u, ku, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(t, kt, a, ka, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(t, kt, b, kb, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(t, kt, c, kc, v) 0.0 + @test_approx_eq Kpax3.jaccard_index_table(t, kt, d, kd, v) 0.0 + + @test Kpax3.jaccard(u, ku, t, kt, v) <= (Kpax3.jaccard(u, ku, b, kb, v) + Kpax3.jaccard(b, kb, t, kt, v)) + @test Kpax3.jaccard(a, ka, b, kb, v) <= (Kpax3.jaccard(a, ka, c, kc, v) + Kpax3.jaccard(c, kc, b, kb, v)) + @test Kpax3.jaccard(b, kb, c, kc, v) <= (Kpax3.jaccard(b, kb, d, kd, v) + Kpax3.jaccard(d, kd, c, kc, v)) + @test Kpax3.jaccard(c, kc, d, kd, v) <= (Kpax3.jaccard(c, kc, a, ka, v) + Kpax3.jaccard(a, ka, d, kd, v)) + @test Kpax3.jaccard(a, ka, b, kb, v) <= (Kpax3.jaccard(a, ka, u, ku, v) + Kpax3.jaccard(u, ku, b, kb, v)) + @test Kpax3.jaccard(a, ka, b, kb, v) <= (Kpax3.jaccard(a, ka, t, kt, v) + Kpax3.jaccard(t, kt, b, kb, v)) + @test Kpax3.jaccard(a, ka, d, kd, v) <= (Kpax3.jaccard(a, ka, u, ku, v) + Kpax3.jaccard(u, ku, d, kd, v)) + @test Kpax3.jaccard(a, ka, d, kd, v) <= (Kpax3.jaccard(a, ka, t, kt, v) + Kpax3.jaccard(t, kt, d, kd, v)) nothing end diff --git a/test/distances/simovici_jaroszewicz.jl b/test/distances/simovici_jaroszewicz.jl index b646f2b..ad7ae26 100644 --- a/test/distances/simovici_jaroszewicz.jl +++ b/test/distances/simovici_jaroszewicz.jl @@ -26,182 +26,136 @@ function test_simovici_jaroszewicz_distance() kt = 6 # β = 2.0 - @test distsj(u, nu, ku, u, nu, ku, v, β=2.0) == 0.0 - @test_approx_eq distsj(u, nu, ku, a, na, ka, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(u, nu, ku, b, nb, kb, v, β=2.0) 0.7999999999999999 - @test_approx_eq distsj(u, nu, ku, c, nc, kc, v, β=2.0) 0.8666666666666666 - @test_approx_eq distsj(u, nu, ku, d, nd, kd, v, β=2.0) 0.9333333333333333 - @test_approx_eq distsj(u, nu, ku, t, nt, kt, v, β=2.0) 1.0 - - @test distsjlower(nu, ku, v, β=2.0) == 0.0 - @test_approx_eq distsjlower(na, ka, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsjlower(nb, kb, v, β=2.0) 0.7999999999999999 - @test_approx_eq distsjlower(nc, kc, v, β=2.0) 0.8666666666666666 - @test_approx_eq distsjlower(nd, kd, v, β=2.0) 0.9333333333333333 - @test_approx_eq distsjlower(nt, kt, v, β=2.0) 1.0 - - @test distsj(a, na, ka, a, na, ka, v, β=2.0) == 0.0 - @test_approx_eq distsj(a, na, ka, u, nu, ku, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(a, na, ka, b, nb, kb, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(a, na, ka, c, nc, kc, v, β=2.0) 0.4666666666666667 - @test_approx_eq distsj(a, na, ka, d, nd, kd, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(a, na, ka, t, nt, kt, v, β=2.0) 0.4666666666666667 - - @test distsj(b, nb, kb, b, nb, kb, v, β=2.0) == 0.0 - @test_approx_eq distsj(b, nb, kb, u, nu, ku, v, β=2.0) 0.7999999999999999 - @test_approx_eq distsj(b, nb, kb, a, na, ka, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(b, nb, kb, c, nc, kc, v, β=2.0) 0.3333333333333333 - @test_approx_eq distsj(b, nb, kb, d, nd, kd, v, β=2.0) 0.2666666666666667 - @test_approx_eq distsj(b, nb, kb, t, nt, kt, v, β=2.0) 0.2 - - @test distsj(c, nc, kc, c, nc, kc, v, β=2.0) == 0.0 - @test_approx_eq distsj(c, nc, kc, u, nu, ku, v, β=2.0) 0.8666666666666666 - @test_approx_eq distsj(c, nc, kc, a, na, ka, v, β=2.0) 0.4666666666666667 - @test_approx_eq distsj(c, nc, kc, b, nb, kb, v, β=2.0) 0.3333333333333333 - @test_approx_eq distsj(c, nc, kc, d, nd, kd, v, β=2.0) 0.2 - @test_approx_eq distsj(c, nc, kc, t, nt, kt, v, β=2.0) 0.1333333333333333 - - @test distsj(d, nd, kd, d, nd, kd, v, β=2.0) == 0.0 - @test_approx_eq distsj(d, nd, kd, u, nu, ku, v, β=2.0) 0.9333333333333333 - @test_approx_eq distsj(d, nd, kd, a, na, ka, v, β=2.0) 0.5333333333333333 - @test_approx_eq distsj(d, nd, kd, b, nb, kb, v, β=2.0) 0.2666666666666667 - @test_approx_eq distsj(d, nd, kd, c, nc, kc, v, β=2.0) 0.2 - @test_approx_eq distsj(d, nd, kd, t, nt, kt, v, β=2.0) 0.0666666666666667 - - @test distsj(t, nt, kt, t, nt, kt, v, β=2.0) == 0.0 - @test_approx_eq distsj(t, nt, kt, u, nu, ku, v, β=2.0) 1.0 - @test_approx_eq distsj(t, nt, kt, a, na, ka, v, β=2.0) 0.4666666666666667 - @test_approx_eq distsj(t, nt, kt, b, nb, kb, v, β=2.0) 0.2 - @test_approx_eq distsj(t, nt, kt, c, nc, kc, v, β=2.0) 0.1333333333333333 - @test_approx_eq distsj(t, nt, kt, d, nd, kd, v, β=2.0) 0.0666666666666667 - - @test distsjupper(nt, kt, v, β=2.0) == 0.0 - @test_approx_eq distsjupper(nu, ku, v, β=2.0) 1.0 - @test_approx_eq distsjupper(na, ka, v, β=2.0) 0.4666666666666667 - @test_approx_eq distsjupper(nb, kb, v, β=2.0) 0.2 - @test_approx_eq distsjupper(nc, kc, v, β=2.0) 0.1333333333333333 - @test_approx_eq distsjupper(nd, kd, v, β=2.0) 0.0666666666666667 - - @test distsj(u, nu, ku, t, nt, kt, v, β=2.0) <= - (distsj(u, nu, ku, b, nb, kb, v, β=2.0) + - distsj(b, nb, kb, t, nt, kt, v, β=2.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=2.0) <= - (distsj(a, na, ka, c, nc, kc, v, β=2.0) + - distsj(c, nc, kc, b, nb, kb, v, β=2.0)) - - @test distsj(b, nb, kb, c, nc, kc, v, β=2.0) <= - (distsj(b, nb, kb, d, nd, kd, v, β=2.0) + - distsj(d, nd, kd, c, nc, kc, v, β=2.0)) - - @test distsj(c, nc, kc, d, nd, kd, v, β=2.0) <= - (distsj(c, nc, kc, a, na, ka, v, β=2.0) + - distsj(a, na, ka, d, nd, kd, v, β=2.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=2.0) <= - (distsj(a, na, ka, u, nu, ku, v, β=2.0) + - distsj(u, nu, ku, b, nb, kb, v, β=2.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=2.0) <= - (distsj(a, na, ka, t, nt, kt, v, β=2.0) + - distsj(t, nt, kt, b, nb, kb, v, β=2.0)) - - @test distsj(a, na, ka, d, nd, kd, v, β=2.0) <= - (distsj(a, na, ka, u, nu, ku, v, β=2.0) + - distsj(u, nu, ku, d, nd, kd, v, β=2.0)) - - @test distsj(a, na, ka, d, nd, kd, v, β=2.0) <= - (distsj(a, na, ka, t, nt, kt, v, β=2.0) + - distsj(t, nt, kt, d, nd, kd, v, β=2.0)) + @test Kpax3.distsj(u, nu, ku, u, nu, ku, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(u, nu, ku, a, na, ka, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=2.0) 0.7999999999999999 + @test_approx_eq Kpax3.distsj(u, nu, ku, c, nc, kc, v, β=2.0) 0.8666666666666666 + @test_approx_eq Kpax3.distsj(u, nu, ku, d, nd, kd, v, β=2.0) 0.9333333333333333 + @test_approx_eq Kpax3.distsj(u, nu, ku, t, nt, kt, v, β=2.0) 1.0 + + @test Kpax3.distsjlower(nu, ku, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsjlower(na, ka, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsjlower(nb, kb, v, β=2.0) 0.7999999999999999 + @test_approx_eq Kpax3.distsjlower(nc, kc, v, β=2.0) 0.8666666666666666 + @test_approx_eq Kpax3.distsjlower(nd, kd, v, β=2.0) 0.9333333333333333 + @test_approx_eq Kpax3.distsjlower(nt, kt, v, β=2.0) 1.0 + + @test Kpax3.distsj(a, na, ka, a, na, ka, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(a, na, ka, u, nu, ku, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(a, na, ka, b, nb, kb, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(a, na, ka, c, nc, kc, v, β=2.0) 0.4666666666666667 + @test_approx_eq Kpax3.distsj(a, na, ka, d, nd, kd, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(a, na, ka, t, nt, kt, v, β=2.0) 0.4666666666666667 + + @test Kpax3.distsj(b, nb, kb, b, nb, kb, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(b, nb, kb, u, nu, ku, v, β=2.0) 0.7999999999999999 + @test_approx_eq Kpax3.distsj(b, nb, kb, a, na, ka, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(b, nb, kb, c, nc, kc, v, β=2.0) 0.3333333333333333 + @test_approx_eq Kpax3.distsj(b, nb, kb, d, nd, kd, v, β=2.0) 0.2666666666666667 + @test_approx_eq Kpax3.distsj(b, nb, kb, t, nt, kt, v, β=2.0) 0.2 + + @test Kpax3.distsj(c, nc, kc, c, nc, kc, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(c, nc, kc, u, nu, ku, v, β=2.0) 0.8666666666666666 + @test_approx_eq Kpax3.distsj(c, nc, kc, a, na, ka, v, β=2.0) 0.4666666666666667 + @test_approx_eq Kpax3.distsj(c, nc, kc, b, nb, kb, v, β=2.0) 0.3333333333333333 + @test_approx_eq Kpax3.distsj(c, nc, kc, d, nd, kd, v, β=2.0) 0.2 + @test_approx_eq Kpax3.distsj(c, nc, kc, t, nt, kt, v, β=2.0) 0.1333333333333333 + + @test Kpax3.distsj(d, nd, kd, d, nd, kd, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(d, nd, kd, u, nu, ku, v, β=2.0) 0.9333333333333333 + @test_approx_eq Kpax3.distsj(d, nd, kd, a, na, ka, v, β=2.0) 0.5333333333333333 + @test_approx_eq Kpax3.distsj(d, nd, kd, b, nb, kb, v, β=2.0) 0.2666666666666667 + @test_approx_eq Kpax3.distsj(d, nd, kd, c, nc, kc, v, β=2.0) 0.2 + @test_approx_eq Kpax3.distsj(d, nd, kd, t, nt, kt, v, β=2.0) 0.0666666666666667 + + @test Kpax3.distsj(t, nt, kt, t, nt, kt, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsj(t, nt, kt, u, nu, ku, v, β=2.0) 1.0 + @test_approx_eq Kpax3.distsj(t, nt, kt, a, na, ka, v, β=2.0) 0.4666666666666667 + @test_approx_eq Kpax3.distsj(t, nt, kt, b, nb, kb, v, β=2.0) 0.2 + @test_approx_eq Kpax3.distsj(t, nt, kt, c, nc, kc, v, β=2.0) 0.1333333333333333 + @test_approx_eq Kpax3.distsj(t, nt, kt, d, nd, kd, v, β=2.0) 0.0666666666666667 + + @test Kpax3.distsjupper(nt, kt, v, β=2.0) == 0.0 + @test_approx_eq Kpax3.distsjupper(nu, ku, v, β=2.0) 1.0 + @test_approx_eq Kpax3.distsjupper(na, ka, v, β=2.0) 0.4666666666666667 + @test_approx_eq Kpax3.distsjupper(nb, kb, v, β=2.0) 0.2 + @test_approx_eq Kpax3.distsjupper(nc, kc, v, β=2.0) 0.1333333333333333 + @test_approx_eq Kpax3.distsjupper(nd, kd, v, β=2.0) 0.0666666666666667 + + @test Kpax3.distsj(u, nu, ku, t, nt, kt, v, β=2.0) <= (Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=2.0) + Kpax3.distsj(b, nb, kb, t, nt, kt, v, β=2.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=2.0) <= (Kpax3.distsj(a, na, ka, c, nc, kc, v, β=2.0) + Kpax3.distsj(c, nc, kc, b, nb, kb, v, β=2.0)) + @test Kpax3.distsj(b, nb, kb, c, nc, kc, v, β=2.0) <= (Kpax3.distsj(b, nb, kb, d, nd, kd, v, β=2.0) + Kpax3.distsj(d, nd, kd, c, nc, kc, v, β=2.0)) + @test Kpax3.distsj(c, nc, kc, d, nd, kd, v, β=2.0) <= (Kpax3.distsj(c, nc, kc, a, na, ka, v, β=2.0) + Kpax3.distsj(a, na, ka, d, nd, kd, v, β=2.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=2.0) <= (Kpax3.distsj(a, na, ka, u, nu, ku, v, β=2.0) + Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=2.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=2.0) <= (Kpax3.distsj(a, na, ka, t, nt, kt, v, β=2.0) + Kpax3.distsj(t, nt, kt, b, nb, kb, v, β=2.0)) + @test Kpax3.distsj(a, na, ka, d, nd, kd, v, β=2.0) <= (Kpax3.distsj(a, na, ka, u, nu, ku, v, β=2.0) + Kpax3.distsj(u, nu, ku, d, nd, kd, v, β=2.0)) + @test Kpax3.distsj(a, na, ka, d, nd, kd, v, β=2.0) <= (Kpax3.distsj(a, na, ka, t, nt, kt, v, β=2.0) + Kpax3.distsj(t, nt, kt, d, nd, kd, v, β=2.0)) # β = 3.0 - @test distsj(u, nu, ku, u, nu, ku, v, β=3.0) == 0.0 - @test_approx_eq distsj(u, nu, ku, a, na, ka, v, β=3.0) 0.6857142857142857 - @test_approx_eq distsj(u, nu, ku, b, nb, kb, v, β=3.0) 0.9142857142857143 - @test_approx_eq distsj(u, nu, ku, c, nc, kc, v, β=3.0) 0.9428571428571429 - @test_approx_eq distsj(u, nu, ku, d, nd, kd, v, β=3.0) 0.9714285714285714 - @test_approx_eq distsj(u, nu, ku, t, nt, kt, v, β=3.0) 1.0 - - @test distsjlower(nu, ku, v, β=3.0) == 0.0 - @test_approx_eq distsjlower(na, ka, v, β=3.0) 0.68571428571428572063 - @test_approx_eq distsjlower(nb, kb, v, β=3.0) 0.91428571428571425717 - @test_approx_eq distsjlower(nc, kc, v, β=3.0) 0.94285714285714294913 - @test_approx_eq distsjlower(nd, kd, v, β=3.0) 0.97142857142857141906 - @test_approx_eq distsjlower(nt, kt, v, β=3.0) 1.0 - - @test distsj(a, na, ka, a, na, ka, v, β=3.0) == 0.0 - @test_approx_eq distsj(a, na, ka, u, nu, ku, v, β=3.0) 0.6857142857142857 - @test_approx_eq distsj(a, na, ka, b, nb, kb, v, β=3.0) 0.3428571428571429 - @test_approx_eq distsj(a, na, ka, c, nc, kc, v, β=3.0) 0.3142857142857143 - @test_approx_eq distsj(a, na, ka, d, nd, kd, v, β=3.0) 0.3428571428571429 - @test_approx_eq distsj(a, na, ka, t, nt, kt, v, β=3.0) 0.3142857142857143 - - @test distsj(b, nb, kb, b, nb, kb, v, β=3.0) == 0.0 - @test_approx_eq distsj(b, nb, kb, u, nu, ku, v, β=3.0) 0.9142857142857143 - @test_approx_eq distsj(b, nb, kb, a, na, ka, v, β=3.0) 0.3428571428571429 - @test_approx_eq distsj(b, nb, kb, c, nc, kc, v, β=3.0) 0.1428571428571429 - @test_approx_eq distsj(b, nb, kb, d, nd, kd, v, β=3.0) 0.1142857142857143 - @test_approx_eq distsj(b, nb, kb, t, nt, kt, v, β=3.0) 0.0857142857142857 - - @test distsj(c, nc, kc, c, nc, kc, v, β=3.0) == 0.0 - @test_approx_eq distsj(c, nc, kc, u, nu, ku, v, β=3.0) 0.9428571428571429 - @test_approx_eq distsj(c, nc, kc, a, na, ka, v, β=3.0) 0.3142857142857143 - @test_approx_eq distsj(c, nc, kc, b, nb, kb, v, β=3.0) 0.1428571428571429 - @test_approx_eq distsj(c, nc, kc, d, nd, kd, v, β=3.0) 0.0857142857142857 - @test_approx_eq distsj(c, nc, kc, t, nt, kt, v, β=3.0) 0.0571428571428571 - - @test distsj(d, nd, kd, d, nd, kd, v, β=3.0) == 0.0 - @test_approx_eq distsj(d, nd, kd, u, nu, ku, v, β=3.0) 0.9714285714285714 - @test_approx_eq distsj(d, nd, kd, a, na, ka, v, β=3.0) 0.3428571428571429 - @test_approx_eq distsj(d, nd, kd, b, nb, kb, v, β=3.0) 0.1142857142857143 - @test_approx_eq distsj(d, nd, kd, c, nc, kc, v, β=3.0) 0.0857142857142857 - @test_approx_eq distsj(d, nd, kd, t, nt, kt, v, β=3.0) 0.0285714285714286 - - @test distsj(t, nt, kt, t, nt, kt, v, β=3.0) == 0.0 - @test_approx_eq distsj(t, nt, kt, u, nu, ku, v, β=3.0) 1.0 - @test_approx_eq distsj(t, nt, kt, a, na, ka, v, β=3.0) 0.3142857142857143 - @test_approx_eq distsj(t, nt, kt, b, nb, kb, v, β=3.0) 0.0857142857142857 - @test_approx_eq distsj(t, nt, kt, c, nc, kc, v, β=3.0) 0.0571428571428571 - @test_approx_eq distsj(t, nt, kt, d, nd, kd, v, β=3.0) 0.0285714285714286 - - @test distsjupper(nt, kt, v, β=3.0) == 0.0 - @test_approx_eq distsjupper(nu, ku, v, β=3.0) 1.0 - @test_approx_eq distsjupper(na, ka, v, β=3.0) 0.3142857142857143 - @test_approx_eq distsjupper(nb, kb, v, β=3.0) 0.0857142857142857 - @test_approx_eq distsjupper(nc, kc, v, β=3.0) 0.0571428571428571 - @test_approx_eq distsjupper(nd, kd, v, β=3.0) 0.0285714285714286 - - @test distsj(u, nu, ku, t, nt, kt, v, β=3.0) <= - (distsj(u, nu, ku, b, nb, kb, v, β=3.0) + - distsj(b, nb, kb, t, nt, kt, v, β=3.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=3.0) <= - (distsj(a, na, ka, c, nc, kc, v, β=3.0) + - distsj(c, nc, kc, b, nb, kb, v, β=3.0)) - - @test distsj(b, nb, kb, c, nc, kc, v, β=3.0) <= - (distsj(b, nb, kb, d, nd, kd, v, β=3.0) + - distsj(d, nd, kd, c, nc, kc, v, β=3.0)) - - @test distsj(c, nc, kc, d, nd, kd, v, β=3.0) <= - (distsj(c, nc, kc, a, na, ka, v, β=3.0) + - distsj(a, na, ka, d, nd, kd, v, β=3.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=3.0) <= - (distsj(a, na, ka, u, nu, ku, v, β=3.0) + - distsj(u, nu, ku, b, nb, kb, v, β=3.0)) - - @test distsj(a, na, ka, b, nb, kb, v, β=3.0) <= - (distsj(a, na, ka, t, nt, kt, v, β=3.0) + - distsj(t, nt, kt, b, nb, kb, v, β=3.0)) - - @test distsj(a, na, ka, d, nd, kd, v, β=3.0) <= - (distsj(a, na, ka, u, nu, ku, v, β=3.0) + - distsj(u, nu, ku, d, nd, kd, v, β=3.0)) - - @test distsj(a, na, ka, d, nd, kd, v, β=3.0) <= - (distsj(a, na, ka, t, nt, kt, v, β=3.0) + - distsj(t, nt, kt, d, nd, kd, v, β=3.0)) + @test Kpax3.distsj(u, nu, ku, u, nu, ku, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(u, nu, ku, a, na, ka, v, β=3.0) 0.6857142857142857 + @test_approx_eq Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=3.0) 0.9142857142857143 + @test_approx_eq Kpax3.distsj(u, nu, ku, c, nc, kc, v, β=3.0) 0.9428571428571429 + @test_approx_eq Kpax3.distsj(u, nu, ku, d, nd, kd, v, β=3.0) 0.9714285714285714 + @test_approx_eq Kpax3.distsj(u, nu, ku, t, nt, kt, v, β=3.0) 1.0 + + @test Kpax3.distsjlower(nu, ku, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsjlower(na, ka, v, β=3.0) 0.68571428571428572063 + @test_approx_eq Kpax3.distsjlower(nb, kb, v, β=3.0) 0.91428571428571425717 + @test_approx_eq Kpax3.distsjlower(nc, kc, v, β=3.0) 0.94285714285714294913 + @test_approx_eq Kpax3.distsjlower(nd, kd, v, β=3.0) 0.97142857142857141906 + @test_approx_eq Kpax3.distsjlower(nt, kt, v, β=3.0) 1.0 + + @test Kpax3.distsj(a, na, ka, a, na, ka, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(a, na, ka, u, nu, ku, v, β=3.0) 0.6857142857142857 + @test_approx_eq Kpax3.distsj(a, na, ka, b, nb, kb, v, β=3.0) 0.3428571428571429 + @test_approx_eq Kpax3.distsj(a, na, ka, c, nc, kc, v, β=3.0) 0.3142857142857143 + @test_approx_eq Kpax3.distsj(a, na, ka, d, nd, kd, v, β=3.0) 0.3428571428571429 + @test_approx_eq Kpax3.distsj(a, na, ka, t, nt, kt, v, β=3.0) 0.3142857142857143 + + @test Kpax3.distsj(b, nb, kb, b, nb, kb, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(b, nb, kb, u, nu, ku, v, β=3.0) 0.9142857142857143 + @test_approx_eq Kpax3.distsj(b, nb, kb, a, na, ka, v, β=3.0) 0.3428571428571429 + @test_approx_eq Kpax3.distsj(b, nb, kb, c, nc, kc, v, β=3.0) 0.1428571428571429 + @test_approx_eq Kpax3.distsj(b, nb, kb, d, nd, kd, v, β=3.0) 0.1142857142857143 + @test_approx_eq Kpax3.distsj(b, nb, kb, t, nt, kt, v, β=3.0) 0.0857142857142857 + + @test Kpax3.distsj(c, nc, kc, c, nc, kc, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(c, nc, kc, u, nu, ku, v, β=3.0) 0.9428571428571429 + @test_approx_eq Kpax3.distsj(c, nc, kc, a, na, ka, v, β=3.0) 0.3142857142857143 + @test_approx_eq Kpax3.distsj(c, nc, kc, b, nb, kb, v, β=3.0) 0.1428571428571429 + @test_approx_eq Kpax3.distsj(c, nc, kc, d, nd, kd, v, β=3.0) 0.0857142857142857 + @test_approx_eq Kpax3.distsj(c, nc, kc, t, nt, kt, v, β=3.0) 0.0571428571428571 + + @test Kpax3.distsj(d, nd, kd, d, nd, kd, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(d, nd, kd, u, nu, ku, v, β=3.0) 0.9714285714285714 + @test_approx_eq Kpax3.distsj(d, nd, kd, a, na, ka, v, β=3.0) 0.3428571428571429 + @test_approx_eq Kpax3.distsj(d, nd, kd, b, nb, kb, v, β=3.0) 0.1142857142857143 + @test_approx_eq Kpax3.distsj(d, nd, kd, c, nc, kc, v, β=3.0) 0.0857142857142857 + @test_approx_eq Kpax3.distsj(d, nd, kd, t, nt, kt, v, β=3.0) 0.0285714285714286 + + @test Kpax3.distsj(t, nt, kt, t, nt, kt, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsj(t, nt, kt, u, nu, ku, v, β=3.0) 1.0 + @test_approx_eq Kpax3.distsj(t, nt, kt, a, na, ka, v, β=3.0) 0.3142857142857143 + @test_approx_eq Kpax3.distsj(t, nt, kt, b, nb, kb, v, β=3.0) 0.0857142857142857 + @test_approx_eq Kpax3.distsj(t, nt, kt, c, nc, kc, v, β=3.0) 0.0571428571428571 + @test_approx_eq Kpax3.distsj(t, nt, kt, d, nd, kd, v, β=3.0) 0.0285714285714286 + + @test Kpax3.distsjupper(nt, kt, v, β=3.0) == 0.0 + @test_approx_eq Kpax3.distsjupper(nu, ku, v, β=3.0) 1.0 + @test_approx_eq Kpax3.distsjupper(na, ka, v, β=3.0) 0.3142857142857143 + @test_approx_eq Kpax3.distsjupper(nb, kb, v, β=3.0) 0.0857142857142857 + @test_approx_eq Kpax3.distsjupper(nc, kc, v, β=3.0) 0.0571428571428571 + @test_approx_eq Kpax3.distsjupper(nd, kd, v, β=3.0) 0.0285714285714286 + + @test Kpax3.distsj(u, nu, ku, t, nt, kt, v, β=3.0) <= (Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=3.0) + Kpax3.distsj(b, nb, kb, t, nt, kt, v, β=3.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=3.0) <= (Kpax3.distsj(a, na, ka, c, nc, kc, v, β=3.0) + Kpax3.distsj(c, nc, kc, b, nb, kb, v, β=3.0)) + @test Kpax3.distsj(b, nb, kb, c, nc, kc, v, β=3.0) <= (Kpax3.distsj(b, nb, kb, d, nd, kd, v, β=3.0) + Kpax3.distsj(d, nd, kd, c, nc, kc, v, β=3.0)) + @test Kpax3.distsj(c, nc, kc, d, nd, kd, v, β=3.0) <= (Kpax3.distsj(c, nc, kc, a, na, ka, v, β=3.0) + Kpax3.distsj(a, na, ka, d, nd, kd, v, β=3.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=3.0) <= (Kpax3.distsj(a, na, ka, u, nu, ku, v, β=3.0) + Kpax3.distsj(u, nu, ku, b, nb, kb, v, β=3.0)) + @test Kpax3.distsj(a, na, ka, b, nb, kb, v, β=3.0) <= (Kpax3.distsj(a, na, ka, t, nt, kt, v, β=3.0) + Kpax3.distsj(t, nt, kt, b, nb, kb, v, β=3.0)) + @test Kpax3.distsj(a, na, ka, d, nd, kd, v, β=3.0) <= (Kpax3.distsj(a, na, ka, u, nu, ku, v, β=3.0) + Kpax3.distsj(u, nu, ku, d, nd, kd, v, β=3.0)) + @test Kpax3.distsj(a, na, ka, d, nd, kd, v, β=3.0) <= (Kpax3.distsj(a, na, ka, t, nt, kt, v, β=3.0) + Kpax3.distsj(t, nt, kt, d, nd, kd, v, β=3.0)) nothing end diff --git a/test/estimate/write.jl b/test/estimate/write.jl index b9c3535..91976a9 100644 --- a/test/estimate/write.jl +++ b/test/estimate/write.jl @@ -5,23 +5,22 @@ function test_write_results() ofile = "../build/test" partition = "data/proper_aa_partition.csv" - settings = KSettings(ifile, ofile, gamma=[0.4; 0.35; 0.25]) + settings = Kpax3.KSettings(ifile, ofile, gamma=[0.4; 0.35; 0.25]) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) - R = normalizepartition(partition, x.id) + R = Kpax3.normalizepartition(partition, x.id) k = maximum(R) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - state = AminoAcidState(x.data, R, priorR, priorC, settings) + state = Kpax3.AminoAcidState(x.data, R, priorR, priorC, settings) - writeresults(x, state, "../build/test_results", what=4) + Kpax3.writeresults(x, state, "../build/test_results", what=4) y1 = readstring("../build/test_results_partition.csv") - y2 = parse(Float64, - strip(readstring("../build/test_results_logposterior_value.txt"))) + y2 = parse(Float64, strip(readstring("../build/test_results_logposterior_value.txt"))) y3 = readstring("../build/test_results_attributes.csv") y4 = readstring("../build/test_results_characteristic.csv") y5 = readstring("../build/test_results_dataset.txt") diff --git a/test/mcmc/biased_random_walk.jl b/test/mcmc/biased_random_walk.jl index cd9c5f4..d967349 100644 --- a/test/mcmc/biased_random_walk.jl +++ b/test/mcmc/biased_random_walk.jl @@ -4,7 +4,7 @@ function test_mcmc_brw_init() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -30,15 +30,15 @@ function test_mcmc_brw_init() # -------------------------- # move unit 4 into cluster 1 R = [13; 13; 13; 42; 42; 76] - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) i = 4 hi = 2 hj = 1 - initsupportbrwmove!(i, hi, hj, data, support, state) + Kpax3.initsupportbrwmove!(i, hi, hj, data, support, state) @test support.vi == 1 @test support.ni == float(data[:, 5]) @@ -49,15 +49,15 @@ function test_mcmc_brw_init() # -------------------------------- # move unit 3 into its own cluster R = [13; 13; 13; 42; 42; 76] - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) k = 4 i = 3 hi = 1 - initsupportbrwsplit!(k, i, hi, data, priorC, settings, support, state) + Kpax3.initsupportbrwsplit!(k, i, hi, data, priorC, settings, support, state) len = 6 @@ -66,14 +66,10 @@ function test_mcmc_brw_init() for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end @test support.lp == lp @@ -86,15 +82,15 @@ function test_mcmc_brw_init() # -------------------------------- # move unit 6 into cluster 2 R = [13; 13; 13; 42; 42; 76] - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) i = 6 hi = 3 hj = 2 - initsupportbrwmerge!(i, hj, data, support, state) + Kpax3.initsupportbrwmerge!(i, hj, data, support, state) @test support.vj == 3 @test support.nj == vec(sum(data[:, [4; 5; 6]], 2)) @@ -108,7 +104,7 @@ function test_mcmc_brw() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1, op=[0.0; 0.0; 1.0]) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1, op=[0.0; 0.0; 1.0]) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -131,29 +127,29 @@ function test_mcmc_brw() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # [2; 2; 2; 1; 1; 3] => [2; 2; 2; 1; 1; 1] - state1 = AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) - support1 = MCMCSupport(state1, priorC) + state1 = Kpax3.AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) + support1 = Kpax3.MCMCSupport(state1, priorC) - state2 = AminoAcidState(data, [2; 2; 2; 1; 1; 1], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [2; 2; 2; 1; 1; 1], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) i = 6 hi = state1.R[i] hj = state1.R[5] - initsupportbrwmerge!(i, hj, data, support1, state1) + Kpax3.initsupportbrwmerge!(i, hj, data, support1, state1) - support1.lograR = logratiopriorrowmerge(state2.k, state1.v[hj], priorR) + support1.lograR = Kpax3.logratiopriorrowmerge(state2.k, state1.v[hj], priorR) - updatelogmarglikj!(priorC, support1) + Kpax3.updatelogmarglikj!(priorC, support1) - logmarglikbrwmerge!(state1.cl, state1.k, hi, hj, priorC, support1) + Kpax3.logmarglikbrwmerge!(state1.cl, state1.k, hi, hj, priorC, support1) - performbrwmerge!(i, hi, hj, settings, support1, state1) + Kpax3.performbrwmerge!(i, hi, hj, settings, support1, state1) @test state1.R == state2.R @test state1.k == state2.k @@ -177,26 +173,26 @@ function test_mcmc_brw() @test_approx_eq_eps support1.logmlik support2.logmlik ε # [2; 2; 2; 1; 1; 3] => [2; 2; 3; 1; 1; 3] - state1 = AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) - support1 = MCMCSupport(state1, priorC) + state1 = Kpax3.AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) + support1 = Kpax3.MCMCSupport(state1, priorC) - state2 = AminoAcidState(data, [2; 2; 3; 1; 1; 3], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [2; 2; 3; 1; 1; 3], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) i = 3 hi = state1.R[i] hj = state1.R[6] - initsupportbrwmove!(i, hi, hj, data, support1, state1) + Kpax3.initsupportbrwmove!(i, hi, hj, data, support1, state1) - support1.lograR = logratiopriorrowmove(state1.v[hi], state1.v[hj], priorR) + support1.lograR = Kpax3.logratiopriorrowmove(state1.v[hi], state1.v[hj], priorR) - updatelogmargliki!(priorC, support1) - updatelogmarglikj!(priorC, support1) + Kpax3.updatelogmargliki!(priorC, support1) + Kpax3.updatelogmarglikj!(priorC, support1) - logmarglikbrwmove!(state1.cl, state1.k, hi, hj, priorC, support1) + Kpax3.logmarglikbrwmove!(state1.cl, state1.k, hi, hj, priorC, support1) - performbrwmove!(i, hi, hj, support1, state1) + Kpax3.performbrwmove!(i, hi, hj, support1, state1) @test state1.R == state2.R @test state1.k == state2.k @@ -224,8 +220,8 @@ function test_mcmc_brw() @test_approx_eq_eps support1.logmlik support2.logmlik ε # [3; 3; 3; 2; 2; 4] => [3; 3; 1; 2; 2; 4] - state1 = AminoAcidState(data, [3; 3; 3; 2; 2; 4], priorR, priorC, settings) - resizestate!(state1, 4, settings) + state1 = Kpax3.AminoAcidState(data, [3; 3; 3; 2; 2; 4], priorR, priorC, settings) + Kpax3.resizestate!(state1, 4, settings) state1.R = [3; 3; 3; 2; 2; 4] @@ -240,25 +236,25 @@ function test_mcmc_brw() state1.unit[3] = copy(state1.unit[2]) state1.unit[2] = copy(state1.unit[1]) - support1 = MCMCSupport(state1, priorC) + support1 = Kpax3.MCMCSupport(state1, priorC) - state2 = AminoAcidState(data, [3; 3; 1; 2; 2; 4], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [3; 3; 1; 2; 2; 4], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) k = state2.k i = 3 hi = state1.R[i] - initsupportbrwsplit!(k, i, hi, data, priorC, settings, support1, state1) + Kpax3.initsupportbrwsplit!(k, i, hi, data, priorC, settings, support1, state1) - support1.lograR = logratiopriorrowsplit(k, state1.v[hi], priorR) + support1.lograR = Kpax3.logratiopriorrowsplit(k, state1.v[hi], priorR) - updatelogmargliki!(priorC, support1) - updatelogmarglikj!(priorC, support1) + Kpax3.updatelogmargliki!(priorC, support1) + Kpax3.updatelogmarglikj!(priorC, support1) - logmarglikbrwsplit!(state1.cl, state1.k, hi, priorC, support1) + Kpax3.logmarglikbrwsplit!(state1.cl, state1.k, hi, priorC, support1) - performbrwsplit!(i, hi, settings, support1, state1) + Kpax3.performbrwsplit!(i, hi, settings, support1, state1) @test state1.R == state2.R @test state1.k == state2.k @@ -293,26 +289,26 @@ function test_mcmc_brw() # [2; 2; 2; 1; 1; 3] => [2; 2; 4; 1; 1; 3] # allocate new resources - state1 = AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) - support1 = MCMCSupport(state1, priorC) + state1 = Kpax3.AminoAcidState(data, [2; 2; 2; 1; 1; 3], priorR, priorC, settings) + support1 = Kpax3.MCMCSupport(state1, priorC) - state2 = AminoAcidState(data, [2; 2; 4; 1; 1; 3], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [2; 2; 4; 1; 1; 3], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) k = state2.k i = 3 hi = state1.R[i] - initsupportbrwsplit!(k, i, hi, data, priorC, settings, support1, state1) + Kpax3.initsupportbrwsplit!(k, i, hi, data, priorC, settings, support1, state1) - support1.lograR = logratiopriorrowsplit(k, state1.v[hi], priorR) + support1.lograR = Kpax3.logratiopriorrowsplit(k, state1.v[hi], priorR) - updatelogmargliki!(priorC, support1) - updatelogmarglikj!(priorC, support1) + Kpax3.updatelogmargliki!(priorC, support1) + Kpax3.updatelogmarglikj!(priorC, support1) - logmarglikbrwsplit!(state1.cl, state1.k, hi, priorC, support1) + Kpax3.logmarglikbrwsplit!(state1.cl, state1.k, hi, priorC, support1) - performbrwsplit!(i, hi, settings, support1, state1) + Kpax3.performbrwsplit!(i, hi, settings, support1, state1) @test state1.R == state2.R @test state1.k == state2.k diff --git a/test/mcmc/diagnostics.jl b/test/mcmc/diagnostics.jl index f21c8f6..5e46133 100644 --- a/test/mcmc/diagnostics.jl +++ b/test/mcmc/diagnostics.jl @@ -5,7 +5,7 @@ function test_traceR() fileroot = "../build/mcmc_6" maxlag = 20 - (entropy, avgd) = traceR(fileroot, maxlag=maxlag) + (entropy, avgd) = Kpax3.traceR(fileroot, maxlag=maxlag) fpR = open(string(fileroot, "_row_partition.bin"), "r") @@ -33,7 +33,7 @@ function test_traceR() read!(fpR, R0) k[T] = k0[1] - copy!(R, 1 + n * (T - 1), normalizepartition(R0, n), 1, n) + copy!(R, 1 + n * (T - 1), Kpax3.normalizepartition(R0, n), 1, n) for i in 1:n v[R[i, T], T] += 1 @@ -55,7 +55,7 @@ function test_traceR() l = 1 z = zeros(Float64, N - l) for t in 1:(N - l) - z[t] = jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) + z[t] = Kpax3.jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) end @test_approx_eq_eps avgd[l] mean(z) ε @@ -63,7 +63,7 @@ function test_traceR() l = 5 z = zeros(Float64, N - l) for t in 1:(N - l) - z[t] = jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) + z[t] = Kpax3.jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) end @test_approx_eq_eps avgd[l] mean(z) ε @@ -71,7 +71,7 @@ function test_traceR() l = 13 z = zeros(Float64, N - l) for t in 1:(N - l) - z[t] = jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) + z[t] = Kpax3.jaccard(R[:, t], k[t], R[:, t+l], k[t+l], n) end @test_approx_eq_eps avgd[l] mean(z) ε @@ -84,7 +84,7 @@ function test_traceC() fileroot = "../build/mcmc_6" maxlag = 20 - (entropy, avgd) = traceC(fileroot, maxlag=maxlag) + (entropy, avgd) = Kpax3.traceC(fileroot, maxlag=maxlag) fpC = open(string(fileroot, "_col_partition.bin"), "r") @@ -196,7 +196,7 @@ function test_imsevar() z = 0.0306296450517703523763746176200584159232676029205322265625 - @test_approx_eq_eps imsevar(ac, N) z ε + @test_approx_eq_eps Kpax3.imsevar(ac, N) z ε nothing end @@ -204,20 +204,20 @@ end test_imsevar() function test_ess() - @test ess(1.0, 1.0, 10) == 10 - @test ess(2.0, 2.0, 100) == 100 + @test Kpax3.ess(1.0, 1.0, 10) == 10 + @test Kpax3.ess(2.0, 2.0, 100) == 100 - @test ess(2.0, 4.0, 10) == 5 - @test ess(2.0, 4.0, 100) == 50 + @test Kpax3.ess(2.0, 4.0, 10) == 5 + @test Kpax3.ess(2.0, 4.0, 100) == 50 - @test ess(4.0, 2.0, 10) == 20 - @test ess(4.0, 2.0, 100) == 200 + @test Kpax3.ess(4.0, 2.0, 10) == 20 + @test Kpax3.ess(4.0, 2.0, 100) == 200 - @test ess(4.0, 12.0, 10) == 3 - @test ess(4.0, 12.0, 100) == 33 + @test Kpax3.ess(4.0, 12.0, 10) == 3 + @test Kpax3.ess(4.0, 12.0, 100) == 33 - @test ess(4.0, 16.0, 10) == 2 - @test ess(4.0, 16.0, 100) == 25 + @test Kpax3.ess(4.0, 16.0, 10) == 2 + @test Kpax3.ess(4.0, 16.0, 100) == 25 nothing end diff --git a/test/mcmc/gibbs.jl b/test/mcmc/gibbs.jl index 1c85abe..fadea45 100644 --- a/test/mcmc/gibbs.jl +++ b/test/mcmc/gibbs.jl @@ -4,7 +4,7 @@ function test_mcmc_gibbs_init() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=3, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=3, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -27,8 +27,8 @@ function test_mcmc_gibbs_init() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 5 from cluster 2 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -36,15 +36,15 @@ function test_mcmc_gibbs_init() i = 5 hi = 2 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) @test support.k == 2 @test support.cl[1:support.k] == [1; 3] - @test support.t[1:support.k] == [clusterweight(state.v[1], priorR); - clusterweight(state.v[3], priorR)] + @test support.t[1:support.k] == [Kpax3.clusterweight(state.v[1], priorR); + Kpax3.clusterweight(state.v[3], priorR)] nothing end @@ -55,7 +55,7 @@ function test_mcmc_gibbs_move() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=4, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=4, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -78,8 +78,8 @@ function test_mcmc_gibbs_move() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 5 from cluster 2 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -89,16 +89,16 @@ function test_mcmc_gibbs_move() li = 3 lj = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) support.ni = vec(float(data[:, 4])) support.vi = 1 - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) - support.t[li] = clusterweight(support.vi, priorR) - support.t[lj] = clusterweight(1, state.k, priorR) + support.t[li] = Kpax3.clusterweight(support.vi, priorR) + support.t[lj] = Kpax3.clusterweight(1, state.k, priorR) g = 0 l = 0 @@ -116,45 +116,30 @@ function test_mcmc_gibbs_move() y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) - @test support.lq[1, l, b] == logmarglik(y, v, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, l, b] == logmarglik(y, v, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, l, b] == logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, l, b] == logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, l, b] == Kpax3.logmarglik(y, v, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, l, b] == Kpax3.logmarglik(y, v, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, l, b] == Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, l, b] == Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) g = 3 l = 2 y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) - @test support.lq[1, l, b] == logmarglik(y, v, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, l, b] == logmarglik(y, v, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, l, b] == logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, l, b] == logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, l, b] == Kpax3.logmarglik(y, v, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, l, b] == Kpax3.logmarglik(y, v, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, l, b] == Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, l, b] == Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) - @test_approx_eq_eps support.lpi[1, b] (priorC.logγ[1] + - support.lp[1, 1, b] + - support.lp[1, 3, b]) ε + @test_approx_eq_eps support.lpi[1, b] (priorC.logγ[1] + support.lp[1, 1, b] + support.lp[1, 3, b]) ε + @test_approx_eq_eps support.lpi[2, b] (priorC.logγ[2] + support.lp[2, 1, b] + support.lp[2, 3, b]) ε - @test_approx_eq_eps support.lpi[2, b] (priorC.logγ[2] + - support.lp[2, 1, b] + - support.lp[2, 3, b]) ε - - z[1] = log(exp(priorC.logω[state.k][1] + support.lp[3, 1, b]) + - exp(priorC.logω[state.k][2] + support.lp[4, 1, b])) - z[2] = log(exp(priorC.logω[state.k][1] + support.lp[3, 3, b]) + - exp(priorC.logω[state.k][2] + support.lp[4, 3, b])) + z[1] = log(exp(priorC.logω[state.k][1] + support.lp[3, 1, b]) + exp(priorC.logω[state.k][2] + support.lp[4, 1, b])) + z[2] = log(exp(priorC.logω[state.k][1] + support.lp[3, 3, b]) + exp(priorC.logω[state.k][2] + support.lp[4, 3, b])) @test_approx_eq_eps support.lpi[3, b] (priorC.logγ[3] + z[1] + z[2]) ε @@ -168,59 +153,41 @@ function test_mcmc_gibbs_move() @test_approx_eq_eps support.lr[2, 1, b] z[1] ε @test_approx_eq_eps support.lr[2, 2, b] z[2] ε - z[1] = log(exp(priorC.logω[state.k][1] + support.lq[3, 1, b]) + - exp(priorC.logω[state.k][2] + support.lq[4, 1, b])) - - log(exp(priorC.logω[state.k][1] + support.lp[3, 1, b]) + - exp(priorC.logω[state.k][2] + support.lp[4, 1, b])) - - z[2] = log(exp(priorC.logω[state.k][1] + support.lq[3, 2, b]) + - exp(priorC.logω[state.k][2] + support.lq[4, 2, b])) - - log(exp(priorC.logω[state.k][1] + support.lp[3, 3, b]) + - exp(priorC.logω[state.k][2] + support.lp[4, 3, b])) + z[1] = log(exp(priorC.logω[state.k][1] + support.lq[3, 1, b]) + exp(priorC.logω[state.k][2] + support.lq[4, 1, b])) - log(exp(priorC.logω[state.k][1] + support.lp[3, 1, b]) + exp(priorC.logω[state.k][2] + support.lp[4, 1, b])) + z[2] = log(exp(priorC.logω[state.k][1] + support.lq[3, 2, b]) + exp(priorC.logω[state.k][2] + support.lq[4, 2, b])) - log(exp(priorC.logω[state.k][1] + support.lp[3, 3, b]) + exp(priorC.logω[state.k][2] + support.lp[4, 3, b])) @test_approx_eq_eps support.lr[3, 1, b] z[1] ε @test_approx_eq_eps support.lr[3, 2, b] z[2] ε - gibbsupdateclusteri!(state.k, b, li, priorC, support) + Kpax3.gibbsupdateclusteri!(state.k, b, li, priorC, support) y = support.ni[b] v = support.vi - @test support.lq[1, li, b] == logmarglik(y, v, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, li, b] == logmarglik(y, v, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, li, b] == logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, li, b] == logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, li, b] == Kpax3.logmarglik(y, v, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, li, b] == Kpax3.logmarglik(y, v, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, li, b] == Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, li, b] == Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) z[1] = priorC.logω[state.k][1] + support.lq[3, li, b] z[2] = priorC.logω[state.k][2] + support.lq[4, li, b] @test_approx_eq_eps support.lpj[1, b] log(exp(z[1]) + exp(z[2])) ε - gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, - support) + Kpax3.gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, support) y = support.ni[b] v = 1 - z[1] = priorC.logω[state.k + 1][1] + logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - z[2] = priorC.logω[state.k + 1][2] + logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + z[1] = priorC.logω[state.k + 1][1] + Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + z[2] = priorC.logω[state.k + 1][2] + Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) @test_approx_eq_eps support.lpj[2, b] log(exp(z[1]) + exp(z[2])) ε - @test support.lq[1, lj, b] == logmarglik(data[b, i], 1, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, lj, b] == logmarglik(data[b, i], 1, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, lj, b] == logmarglik(data[b, i], 1, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, lj, b] == logmarglik(data[b, i], 1, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, lj, b] == Kpax3.logmarglik(data[b, i], 1, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, lj, b] == Kpax3.logmarglik(data[b, i], 1, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, lj, b] == Kpax3.logmarglik(data[b, i], 1, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, lj, b] == Kpax3.logmarglik(data[b, i], 1, priorC.A[4, b], priorC.B[4, b]) z[1] = priorC.logω[state.k + 1][1] + support.lq[3, lj, b] z[2] = priorC.logω[state.k + 1][2] + support.lq[4, lj, b] @@ -228,39 +195,39 @@ function test_mcmc_gibbs_move() @test_approx_eq_eps support.lpj[3, b] log(exp(z[1]) + exp(z[2])) ε end - gibbscomputeprobi!(li, support) + Kpax3.gibbscomputeprobi!(li, support) for b in 1:support.m - gibbscomputeprobg!(b, 1, li, support) - gibbscomputeprobg!(b, 2, li, support) - gibbscomputeprobj!(b, li, lj, support) + Kpax3.gibbscomputeprobg!(b, 1, li, support) + Kpax3.gibbscomputeprobg!(b, 2, li, support) + Kpax3.gibbscomputeprobj!(b, li, lj, support) end - st = AminoAcidState(data, [1; 1; 1; 2; 1; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(state.v[1], priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 1; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(state.v[1], priorR) + su.logmlik @test_approx_eq_eps support.t[1] t ε - st = AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(state.v[3], priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(state.v[3], priorR) + su.logmlik @test_approx_eq_eps support.t[2] t ε - st = AminoAcidState(data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(state.v[2] - 1, priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(state.v[2] - 1, priorR) + su.logmlik @test_approx_eq_eps support.t[li] t ε - st = AminoAcidState(data, [1; 1; 1; 2; 4; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(1, state.k, priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 4; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(1, state.k, priorR) + su.logmlik @test_approx_eq_eps support.t[lj] t ε - logc = gibbscomputenormconst(lj, support) + logc = Kpax3.gibbscomputenormconst(lj, support) @test_approx_eq_eps logc log(sum(exp(support.t[1:4]))) ε @@ -273,7 +240,7 @@ function test_mcmc_gibbs_merge() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=3, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=3, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -296,8 +263,8 @@ function test_mcmc_gibbs_merge() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 6 from cluster 3 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -307,12 +274,12 @@ function test_mcmc_gibbs_merge() li = 3 lj = 3 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) - support.t[lj] = clusterweight(1, state.k - 1, priorR) + support.t[lj] = Kpax3.clusterweight(1, state.k - 1, priorR) g = 0 l = 0 @@ -329,45 +296,30 @@ function test_mcmc_gibbs_merge() y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) + Kpax3.gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) - @test support.lq[1, l, b] == logmarglik(y, v, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, l, b] == logmarglik(y, v, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, l, b] == logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, l, b] == logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, l, b] == Kpax3.logmarglik(y, v, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, l, b] == Kpax3.logmarglik(y, v, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, l, b] == Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, l, b] == Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) g = 2 l = 2 y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) + Kpax3.gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) - @test support.lq[1, l, b] == logmarglik(y, v, priorC.A[1, b], - priorC.B[1, b]) - @test support.lq[2, l, b] == logmarglik(y, v, priorC.A[2, b], - priorC.B[2, b]) - @test support.lq[3, l, b] == logmarglik(y, v, priorC.A[3, b], - priorC.B[3, b]) - @test support.lq[4, l, b] == logmarglik(y, v, priorC.A[4, b], - priorC.B[4, b]) + @test support.lq[1, l, b] == Kpax3.logmarglik(y, v, priorC.A[1, b], priorC.B[1, b]) + @test support.lq[2, l, b] == Kpax3.logmarglik(y, v, priorC.A[2, b], priorC.B[2, b]) + @test support.lq[3, l, b] == Kpax3.logmarglik(y, v, priorC.A[3, b], priorC.B[3, b]) + @test support.lq[4, l, b] == Kpax3.logmarglik(y, v, priorC.A[4, b], priorC.B[4, b]) - @test_approx_eq_eps support.lpi[1, b] (priorC.logγ[1] + - support.lp[1, 1, b] + - support.lp[1, 2, b]) ε + @test_approx_eq_eps support.lpi[1, b] (priorC.logγ[1] + support.lp[1, 1, b] + support.lp[1, 2, b]) ε + @test_approx_eq_eps support.lpi[2, b] (priorC.logγ[2] + support.lp[2, 1, b] + support.lp[2, 2, b]) ε - @test_approx_eq_eps support.lpi[2, b] (priorC.logγ[2] + - support.lp[2, 1, b] + - support.lp[2, 2, b]) ε - - z[1] = log(exp(priorC.logω[support.k][1] + support.lp[3, 1, b]) + - exp(priorC.logω[support.k][2] + support.lp[4, 1, b])) - z[2] = log(exp(priorC.logω[support.k][1] + support.lp[3, 2, b]) + - exp(priorC.logω[support.k][2] + support.lp[4, 2, b])) + z[1] = log(exp(priorC.logω[support.k][1] + support.lp[3, 1, b]) + exp(priorC.logω[support.k][2] + support.lp[4, 1, b])) + z[2] = log(exp(priorC.logω[support.k][1] + support.lp[3, 2, b]) + exp(priorC.logω[support.k][2] + support.lp[4, 2, b])) @test_approx_eq_eps support.lpi[3, b] (priorC.logγ[3] + z[1] + z[2]) ε @@ -381,47 +333,39 @@ function test_mcmc_gibbs_merge() @test_approx_eq_eps support.lr[2, 1, b] z[1] ε @test_approx_eq_eps support.lr[2, 2, b] z[2] ε - z[1] = log(exp(priorC.logω[support.k][1] + support.lq[3, 1, b]) + - exp(priorC.logω[support.k][2] + support.lq[4, 1, b])) + - support.lpj[1, b] - - log(exp(priorC.logω[support.k][1] + support.lp[3, 1, b]) + - exp(priorC.logω[support.k][2] + support.lp[4, 1, b])) - z[2] = log(exp(priorC.logω[support.k][1] + support.lq[3, 2, b]) + - exp(priorC.logω[support.k][2] + support.lq[4, 2, b])) + - support.lpj[1, b] - - log(exp(priorC.logω[support.k][1] + support.lp[3, 2, b]) + - exp(priorC.logω[support.k][2] + support.lp[4, 2, b])) + z[1] = log(exp(priorC.logω[support.k][1] + support.lq[3, 1, b]) + exp(priorC.logω[support.k][2] + support.lq[4, 1, b])) + support.lpj[1, b] - log(exp(priorC.logω[support.k][1] + support.lp[3, 1, b]) + exp(priorC.logω[support.k][2] + support.lp[4, 1, b])) + z[2] = log(exp(priorC.logω[support.k][1] + support.lq[3, 2, b]) + exp(priorC.logω[support.k][2] + support.lq[4, 2, b])) + support.lpj[1, b] - log(exp(priorC.logω[support.k][1] + support.lp[3, 2, b]) + exp(priorC.logω[support.k][2] + support.lp[4, 2, b])) @test_approx_eq_eps support.lr[3, 1, b] z[1] ε @test_approx_eq_eps support.lr[3, 2, b] z[2] ε end - gibbscomputeprobi!(lj, support) + Kpax3.gibbscomputeprobi!(lj, support) for b in 1:support.m - gibbscomputeprobg!(b, 1, support) - gibbscomputeprobg!(b, 2, support) + Kpax3.gibbscomputeprobg!(b, 1, support) + Kpax3.gibbscomputeprobg!(b, 2, support) end - st = AminoAcidState(data, [1; 1; 1; 2; 2; 1], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(state.v[1], priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 1], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(state.v[1], priorR) + su.logmlik @test_approx_eq_eps support.t[1] t ε - st = AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(state.v[2], priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(state.v[2], priorR) + su.logmlik @test_approx_eq_eps support.t[2] t ε - st = AminoAcidState(data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) - t = clusterweight(1, state.k - 1, priorR) + su.logmlik + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) + t = Kpax3.clusterweight(1, state.k - 1, priorR) + su.logmlik @test_approx_eq_eps support.t[lj] t ε - logc = gibbscomputenormconst(lj, support) + logc = Kpax3.gibbscomputenormconst(lj, support) @test_approx_eq_eps logc log(sum(exp(support.t[1:3]))) ε @@ -434,7 +378,7 @@ function test_mcmc_gibbs_sample_cluster() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=4, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=4, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -457,14 +401,14 @@ function test_mcmc_gibbs_sample_cluster() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 5 from cluster 2 and put it into another cluster R = [1; 1; 1; 2; 2; 3] - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) support.t[1] = log(0.001) + log(0.4) support.t[2] = log(0.001) + log(0.3) @@ -477,7 +421,7 @@ function test_mcmc_gibbs_sample_cluster() g = 0 counter = zeros(Float64, 6) for t in 1:N - g = gibbssamplecluster(logc, 4, support) + g = Kpax3.gibbssamplecluster(logc, 4, support) counter[g] += 1 end @@ -494,7 +438,7 @@ function test_mcmc_gibbs_perform_move() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=4, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=4, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -517,8 +461,8 @@ function test_mcmc_gibbs_perform_move() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 5 from cluster 2 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -528,16 +472,16 @@ function test_mcmc_gibbs_perform_move() li = 3 lj = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) support.ni = vec(float(data[:, 4])) support.vi = 1 - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) - support.t[li] = clusterweight(support.vi, priorR) - support.t[lj] = clusterweight(1, state.k, priorR) + support.t[li] = Kpax3.clusterweight(support.vi, priorR) + support.t[lj] = Kpax3.clusterweight(1, state.k, priorR) g = 0 l = 0 @@ -555,35 +499,34 @@ function test_mcmc_gibbs_perform_move() y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) g = 3 l = 2 y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) - gibbsupdateclusteri!(state.k, b, li, priorC, support) - gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, - support) + Kpax3.gibbsupdateclusteri!(state.k, b, li, priorC, support) + Kpax3.gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, support) end - gibbscomputeprobi!(li, support) + Kpax3.gibbscomputeprobi!(li, support) for b in 1:support.m - gibbscomputeprobg!(b, 1, li, support) - gibbscomputeprobg!(b, 2, li, support) - gibbscomputeprobj!(b, li, lj, support) + Kpax3.gibbscomputeprobg!(b, 1, li, support) + Kpax3.gibbscomputeprobg!(b, 2, li, support) + Kpax3.gibbscomputeprobj!(b, li, lj, support) end # R = [1; 1; 1; 2; 3; 3] l = 2 - gibbsmove!(i, hi, support.cl[l], li, l, data, priorR, support, state) + Kpax3.gibbsmove!(i, hi, support.cl[l], li, l, data, priorR, support, state) - st = AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) @test state.R == st.R @test state.k == st.k @@ -621,7 +564,7 @@ function test_mcmc_gibbs_perform_merge() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=3, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=3, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -644,8 +587,8 @@ function test_mcmc_gibbs_perform_merge() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 6 from cluster 3 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -655,12 +598,12 @@ function test_mcmc_gibbs_perform_merge() li = 3 lj = 3 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) - support.t[lj] = clusterweight(1, state.k - 1, priorR) + support.t[lj] = Kpax3.clusterweight(1, state.k - 1, priorR) g = 0 l = 0 @@ -677,30 +620,30 @@ function test_mcmc_gibbs_perform_merge() y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) + Kpax3.gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) g = 2 l = 2 y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) + Kpax3.gibbsupdateclustergmerge!(y, v, b, l, g, support.k, priorC, support) end - gibbscomputeprobi!(lj, support) + Kpax3.gibbscomputeprobi!(lj, support) for b in 1:support.m - gibbscomputeprobg!(b, 1, support) - gibbscomputeprobg!(b, 2, support) + Kpax3.gibbscomputeprobg!(b, 1, support) + Kpax3.gibbscomputeprobg!(b, 2, support) end # R = [1; 1; 1; 2; 2; 1] l = 1 - gibbsmerge!(i, hi, support.cl[l], l, data, priorR, support, state) + Kpax3.gibbsmerge!(i, hi, support.cl[l], l, data, priorR, support, state) - st = AminoAcidState(data, [1; 1; 1; 2; 2; 1], priorR, priorC, settings) - su = MCMCSupport(st, priorC) + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 1], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) @test state.R == st.R @test state.k == st.k @@ -735,7 +678,7 @@ function test_mcmc_gibbs_perform_split() ofile = "../build/test" # state should be resized - settings = KSettings(ifile, ofile, maxclust=3, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=3, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -758,8 +701,8 @@ function test_mcmc_gibbs_perform_split() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # remove unit 5 from cluster 2 and put it into another cluster R = [1; 1; 1; 2; 2; 3] @@ -769,18 +712,18 @@ function test_mcmc_gibbs_perform_split() li = 3 lj = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - resizesupport!(support, state.k + 1) + Kpax3.resizesupport!(support, state.k + 1) support.ni = vec(float(data[:, 4])) support.vi = 1 - initsupportgibbs!(hi, priorR, state, support) + Kpax3.initsupportgibbs!(hi, priorR, state, support) - support.t[li] = clusterweight(support.vi, priorR) - support.t[lj] = clusterweight(1, state.k, priorR) + support.t[li] = Kpax3.clusterweight(support.vi, priorR) + support.t[lj] = Kpax3.clusterweight(1, state.k, priorR) g = 0 l = 0 @@ -798,35 +741,35 @@ function test_mcmc_gibbs_perform_split() y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) g = 3 l = 2 y = state.n1s[g, b] + float(data[b, i]) v = state.v[g] + 1 - gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) + Kpax3.gibbsupdateclustergmove!(y, v, b, l, g, state.k, priorC, support) - gibbsupdateclusteri!(state.k, b, li, priorC, support) - gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, + Kpax3.gibbsupdateclusteri!(state.k, b, li, priorC, support) + Kpax3.gibbsupdateclusterj!(data[b, i], state.k + 1, b, li, lj, priorC, support) end - gibbscomputeprobi!(li, support) + Kpax3.gibbscomputeprobi!(li, support) for b in 1:support.m - gibbscomputeprobg!(b, 1, li, support) - gibbscomputeprobg!(b, 2, li, support) - gibbscomputeprobj!(b, li, lj, support) + Kpax3.gibbscomputeprobg!(b, 1, li, support) + Kpax3.gibbscomputeprobg!(b, 2, li, support) + Kpax3.gibbscomputeprobj!(b, li, lj, support) end # R = [1; 1; 1; 2; 4; 3] l = 4 - gibbssplit!(i, hi, li, lj, data, priorR, settings, support, state) + Kpax3.gibbssplit!(i, hi, li, lj, data, priorR, settings, support, state) - st = AminoAcidState(data, [1; 1; 1; 2; 4; 3], priorR, priorC, settings) - su = MCMCSupport(st, priorC) + st = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 4; 3], priorR, priorC, settings) + su = Kpax3.MCMCSupport(st, priorC) @test state.R == st.R @test state.k == st.k diff --git a/test/mcmc/log_likelihoods.jl b/test/mcmc/log_likelihoods.jl index 56d91de..8332f20 100644 --- a/test/mcmc/log_likelihoods.jl +++ b/test/mcmc/log_likelihoods.jl @@ -4,7 +4,7 @@ function test_mcmc_logmarglikmerge() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -27,22 +27,22 @@ function test_mcmc_logmarglikmerge() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # [1; 1; 1; 2; 3; 3] => [1; 1; 1; 3; 3; 3] - state1 = AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) - support1 = MCMCSupport(state1, priorC) + state1 = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) + support1 = Kpax3.MCMCSupport(state1, priorC) ni = vec(sum(float(data[:, [4; 5; 6]]), 2)) vi = 3 - updatelogmargliki!(ni, vi, priorC, support1) + Kpax3.updatelogmargliki!(ni, vi, priorC, support1) - logmarglikmerge!(state1.cl, state1.k, 3, 2, priorC, support1) + Kpax3.logmarglikmerge!(state1.cl, state1.k, 3, 2, priorC, support1) - state2 = AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) @test_approx_eq_eps support1.logmlikcandidate support2.logmlik ε @@ -55,7 +55,7 @@ function test_mcmc_logmargliksplit() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -78,12 +78,12 @@ function test_mcmc_logmargliksplit() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # [1; 1; 1; 2; 2; 2] => [1; 1; 1; 2; 3; 3] - state1 = AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) - support1 = MCMCSupport(state1, priorC) + state1 = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) + support1 = Kpax3.MCMCSupport(state1, priorC) support1.ni = vec(sum(float(data[:, 4]), 2)) support1.vi = 1 @@ -91,13 +91,13 @@ function test_mcmc_logmargliksplit() support1.nj = vec(sum(float(data[:, [5; 6]]), 2)) support1.vj = 2 - updatelogmargliki!(priorC, support1) - updatelogmarglikj!(priorC, support1) + Kpax3.updatelogmargliki!(priorC, support1) + Kpax3.updatelogmarglikj!(priorC, support1) - logmargliksplit!(state1.cl, state1.k, 2, priorC, support1) + Kpax3.logmargliksplit!(state1.cl, state1.k, 2, priorC, support1) - state2 = AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) - support2 = MCMCSupport(state2, priorC) + state2 = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 3; 3], priorR, priorC, settings) + support2 = Kpax3.MCMCSupport(state2, priorC) @test_approx_eq_eps support1.logmlikcandidate support2.logmlik ε diff --git a/test/mcmc/merge.jl b/test/mcmc/merge.jl index 65cee8d..c0b0194 100644 --- a/test/mcmc/merge.jl +++ b/test/mcmc/merge.jl @@ -5,7 +5,7 @@ function test_mcmc_merge_init() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -28,8 +28,8 @@ function test_mcmc_merge_init() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 42; 42; 76] k = length(unique(R)) - 1 @@ -38,49 +38,27 @@ function test_mcmc_merge_init() S = 1 u = 5 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportmerge!(ij, k, data, priorC, support) + Kpax3.initsupportmerge!(ij, k, data, priorC, support) wi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end ci = Float64[log(sum(exp(support.wi.w[:, b]))) for b in 1:m] wj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end cj = Float64[log(sum(exp(support.wj.w[:, b]))) for b in 1:m] @@ -111,7 +89,7 @@ function test_mcmc_merge_updatei() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -134,8 +112,8 @@ function test_mcmc_merge_updatei() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 42; 42; 76] k = length(unique(R)) - 1 @@ -144,43 +122,24 @@ function test_mcmc_merge_updatei() S = 1 u = 5 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportmerge!(ij, k, data, priorC, support) + Kpax3.initsupportmerge!(ij, k, data, priorC, support) lcp = zeros(Float64, 2) for b in 1:m - lcp[1] += computeclusteriseqprobs!(data[b, u], b, priorC, support) - lcp[2] += computeclusterjseqprobs!(data[b, u], b, priorC, support) + lcp[1] += Kpax3.computeclusteriseqprobs!(data[b, u], b, priorC, support) + lcp[2] += Kpax3.computeclusterjseqprobs!(data[b, u], b, priorC, support) end - updateclusteri!(u, data, support) + Kpax3.updateclusteri!(u, data, support) wi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[1, col], priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[2, col], priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[3, col], priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[4, col], priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end zi = copy(wi) @@ -190,37 +149,15 @@ function test_mcmc_merge_updatei() wj = zeros(Float64, 4, m) zj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) - - zj[1, col] = wj[1, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[1, col], priorC.B[1, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) - zj[2, col] = wj[2, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[2, col], priorC.B[2, col]) - - zj[3, col] = wj[3, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[3, col], priorC.B[3, col]) - - zj[4, col] = wj[4, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[4, col], priorC.B[4, col]) + zj[1, col] = wj[1, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + zj[2, col] = wj[2, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + zj[3, col] = wj[3, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + zj[4, col] = wj[4, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end @@ -252,7 +189,7 @@ function test_mcmc_merge_updatej() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -275,8 +212,8 @@ function test_mcmc_merge_updatej() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 42; 42; 76] k = length(unique(R)) - 1 @@ -285,81 +222,40 @@ function test_mcmc_merge_updatej() S = 1 u = 5 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportmerge!(ij, k, data, priorC, support) + Kpax3.initsupportmerge!(ij, k, data, priorC, support) lcp = zeros(Float64, 2) for b in 1:m - lcp[1] += computeclusteriseqprobs!(data[b, u], b, priorC, support) - lcp[2] += computeclusterjseqprobs!(data[b, u], b, priorC, support) + lcp[1] += Kpax3.computeclusteriseqprobs!(data[b, u], b, priorC, support) + lcp[2] += Kpax3.computeclusterjseqprobs!(data[b, u], b, priorC, support) end - updateclusterj!(u, data, support) + Kpax3.updateclusterj!(u, data, support) wi = zeros(Float64, 4, m) zi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) - - zi[1, col] = wi[1, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[1, col], priorC.B[1, col]) - - zi[2, col] = wi[2, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[2, col], priorC.B[2, col]) - - zi[3, col] = wi[3, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[3, col], priorC.B[3, col]) - - zi[4, col] = wi[4, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[4, col], priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) + + zi[1, col] = wi[1, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + zi[2, col] = wi[2, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + zi[3, col] = wi[3, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + zi[4, col] = wi[4, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end ci = Float64[log(sum(exp(support.wi.w[:, b]))) for b in 1:m] wj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[1, col], priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[2, col], priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[3, col], priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[4, col], priorC.B[4, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end zj = copy(wj) diff --git a/test/mcmc/partition_ratios.jl b/test/mcmc/partition_ratios.jl index 2d3e87e..5edd57a 100644 --- a/test/mcmc/partition_ratios.jl +++ b/test/mcmc/partition_ratios.jl @@ -10,41 +10,38 @@ function test_mcmc_partition_ratios() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - state = AminoAcidState(x.data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(x.data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) support.vi = 8 support.vj = 7 for (α, θ) in ((0.4, -0.3), (0.4, 0.0), (0.4, 2.1), (0.0, 2.1), (-2.4, 10)) - ep = EwensPitman(α, θ) + ep = Kpax3.EwensPitman(α, θ) - lr1 = logdPriorRow(50, 6, [22; 8; 7; 5; 1; 7], ep) - - logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) + lr1 = Kpax3.logdPriorRow(50, 6, [22; 8; 7; 5; 1; 7], ep) - Kpax3.logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) - logratiopriorrowsplit!(6, ep, support) + Kpax3.logratiopriorrowsplit!(6, ep, support) @test_approx_eq_eps support.lograR lr1 ε - logratiopriorrowmerge!(5, ep, support) + Kpax3.logratiopriorrowmerge!(5, ep, support) @test_approx_eq_eps support.lograR -lr1 ε - lr2 = logdPriorRow(50, 6, [22; 14; 7; 5; 1; 1], ep) - - logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) + lr2 = Kpax3.logdPriorRow(50, 6, [22; 14; 7; 5; 1; 1], ep) - Kpax3.logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) - @test_approx_eq_eps logratiopriorrowsplit(6, 15, ep) lr2 ε - @test_approx_eq_eps logratiopriorrowmerge(5, 14, ep) -lr2 ε + @test_approx_eq_eps Kpax3.logratiopriorrowsplit(6, 15, ep) lr2 ε + @test_approx_eq_eps Kpax3.logratiopriorrowmerge(5, 14, ep) -lr2 ε - lr3 = logdPriorRow(50, 5, [22; 14; 8; 5; 1], ep) - - logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) + lr3 = Kpax3.logdPriorRow(50, 5, [22; 14; 8; 5; 1], ep) - Kpax3.logdPriorRow(50, 5, [22; 15; 7; 5; 1], ep) - @test_approx_eq_eps logratiopriorrowmove(15, 7, ep) lr3 ε + @test_approx_eq_eps Kpax3.logratiopriorrowmove(15, 7, ep) lr3 ε end nothing diff --git a/test/mcmc/posterior.jl b/test/mcmc/posterior.jl index d38d20f..e993621 100644 --- a/test/mcmc/posterior.jl +++ b/test/mcmc/posterior.jl @@ -11,10 +11,10 @@ # compute log(normalization constant) as accurate as possible include("data/partitions.jl") -function computelogp(b::Int, +function Kpax3.computelogp(b::Int, c::Vector{UInt8}, n1s::Matrix{Float64}, - priorC::AminoAcidPriorCol) + priorC::Kpax3.AminoAcidPriorCol) k = size(n1s, 1) logp = 0.0 @@ -22,20 +22,19 @@ function computelogp(b::Int, logp = priorC.logγ[1] for g in 1:k - logp += logmarglik(n1s[g, b], v[g], priorC.A[1, b], priorC.B[1, b]) + logp += Kpax3.logmarglik(n1s[g, b], v[g], priorC.A[1, b], priorC.B[1, b]) end elseif c1[1] == UInt8(2) logp = priorC.logγ[2] for g in 1:k - logp += logmarglik(n1s[g, b], v[g], priorC.A[2, b], priorC.B[2, b]) + logp += Kpax3.logmarglik(n1s[g, b], v[g], priorC.A[2, b], priorC.B[2, b]) end else logp = priorC.logγ[3] for g in 1:k - logp += priorC.logω[k][c[g] - 2] + - logmarglik(n1s[g, b], v[g], priorC.A[c[g], b], priorC.B[c[g], b]) + logp += priorC.logω[k][c[g] - 2] + Kpax3.logmarglik(n1s[g, b], v[g], priorC.A[c[g], b], priorC.B[c[g], b]) end end @@ -57,17 +56,17 @@ function addvalue!(b::Int, nothing end -function computelognormconst(ck, +function Kpax3.computelognormconst(ck, k::Int, lumpp::Float64, data::Matrix{UInt8}, po::TestPartition, γ::Vector{Float64}, r::Float64, - priorR::PriorRowPartition) + priorR::Kpax3.PriorRowPartition) (m, n) = size(data) - priorC = AminoAcidPriorCol(data, γ, r) + priorC = Kpax3.AminoAcidPriorCol(data, γ, r) st = po.index[po.k .== k][1] en = any(po.k .== k + 1) ? po.index[po.k .== k + 1][1] - 1 : st @@ -102,13 +101,13 @@ function computelognormconst(ck, end end - logprR = logdPriorRow(R, priorR) + logprR = Kpax3.logdPriorRow(R, priorR) for c1 in ck, c2 in ck, c3 in ck, c4 in ck - logp[1] += computelogp(1, c1, n1s, priorC) - logp[2] += computelogp(2, c2, n1s, priorC) - logp[3] += computelogp(3, c3, n1s, priorC) - logp[4] += computelogp(4, c4, n1s, priorC) + logp[1] += Kpax3.computelogp(1, c1, n1s, priorC) + logp[2] += Kpax3.computelogp(2, c2, n1s, priorC) + logp[3] += Kpax3.computelogp(3, c3, n1s, priorC) + logp[4] += Kpax3.computelogp(4, c4, n1s, priorC) logpost = logprR + logp[1] + logp[2] + logp[3] + logp[4] @@ -128,14 +127,14 @@ function lognormconst(cs, po::TestPartition, γ::Vector{Float64}, r::Float64, - priorR::PriorRowPartition) + priorR::Kpax3.PriorRowPartition) # log unnormalized maximum posterior probability lumpp = -Inf println("Computing 'lumpp'...") for k in 1:size(data, 2) println("k = ", k) - t1, t2 = computelognormconst(cs[k], k, 0.0, data, po, γ, r, priorR) + t1, t2 = Kpax3.computelognormconst(cs[k], k, 0.0, data, po, γ, r, priorR) if t1 > lumpp lumpp = t1 @@ -150,7 +149,7 @@ function lognormconst(cs, println("Computing 'z'...") for k in 1:size(data, 2) println("k = ", k) - t1, t2 = computelognormconst(cs[k], k, lumpp, data, po, γ, r, priorR) + t1, t2 = Kpax3.computelognormconst(cs[k], k, lumpp, data, po, γ, r, priorR) z += t2 end println("Done.") @@ -165,7 +164,7 @@ function computeProbs(cs, po::TestPartition, γ::Vector{Float64}, r::Float64, - priorR::PriorRowPartition) + priorR::Kpax3.PriorRowPartition) (m, n) = size(data) P = zeros(Float64, div(n * (n - 1), 2)) @@ -184,7 +183,7 @@ function computeProbs(cs, for k in 1:(n - 1) println("k = ", k) - priorC = AminoAcidPriorCol(data, γ, r) + priorC = Kpax3.AminoAcidPriorCol(data, γ, r) st = po.index[po.k .== k][1] en = po.index[po.k .== k + 1][1] - 1 @@ -209,7 +208,7 @@ function computeProbs(cs, end end - logprR = logdPriorRow(R, priorR) + logprR = Kpax3.logdPriorRow(R, priorR) idx = 1 for i in 1:(n - 1) @@ -220,10 +219,10 @@ function computeProbs(cs, end for c1 in cs[k], c2 in cs[k], c3 in cs[k], c4 in cs[k] - logp[1] += computelogp(1, c1, n1s, priorC) - logp[2] += computelogp(2, c2, n1s, priorC) - logp[3] += computelogp(3, c3, n1s, priorC) - logp[4] += computelogp(4, c4, n1s, priorC) + logp[1] += Kpax3.computelogp(1, c1, n1s, priorC) + logp[2] += Kpax3.computelogp(2, c2, n1s, priorC) + logp[3] += Kpax3.computelogp(3, c3, n1s, priorC) + logp[4] += Kpax3.computelogp(4, c4, n1s, priorC) tmp = exp(logpost - lumpp) @@ -242,7 +241,7 @@ function computeProbs(cs, k = n println("k = ", k) - priorC = AminoAcidPriorCol(data, γ, r) + priorC = Kpax3.AminoAcidPriorCol(data, γ, r) v = ones(Float64, k) n1s = zeros(Float64, k, m) @@ -258,7 +257,7 @@ function computeProbs(cs, end end - logprR = logdPriorRow(R, priorR) + logprR = Kpax3.logdPriorRow(R, priorR) idx = 1 for i in 1:(n - 1) @@ -269,10 +268,10 @@ function computeProbs(cs, end for c1 in cs[k], c2 in cs[k], c3 in cs[k], c4 in cs[k] - logp[1] += computelogp(1, c1, n1s, priorC) - logp[2] += computelogp(2, c2, n1s, priorC) - logp[3] += computelogp(3, c3, n1s, priorC) - logp[4] += computelogp(4, c4, n1s, priorC) + logp[1] += Kpax3.computelogp(1, c1, n1s, priorC) + logp[2] += Kpax3.computelogp(2, c2, n1s, priorC) + logp[3] += Kpax3.computelogp(3, c3, n1s, priorC) + logp[4] += Kpax3.computelogp(4, c4, n1s, priorC) tmp = exp(logpost - lumpp) @@ -289,11 +288,11 @@ function computeProbs(cs, (exp(log(P) - lz), exp(log(S) - lz), exp(log(K) - lz)) end -settings = KSettings(ifile, ofile, alpha=α, theta=θ) +settings = Kpax3.KSettings(ifile, ofile, alpha=α, theta=θ) -x = AminoAcidData(settings) +x = Kpax3.AminoAcidData(settings) -priorR = EwensPitman(settings.α, settings.θ) +priorR = Kpax3.EwensPitman(settings.α, settings.θ) po = TestPartition(size(x.data, 2)) cs = ((UInt8[1], UInt8[2], UInt8[3], UInt8[4]), (UInt8[1; 1], UInt8[2; 2], UInt8[3; 3], UInt8[3; 4], UInt8[4; 3], @@ -401,7 +400,7 @@ function test_mcmc_algorithm() partition = "data/mcmc_6.csv" - x = AminoAcidData(KSettings(ifile, ofile)) + x = Kpax3.AminoAcidData(Kpax3.KSettings(ifile, ofile)) n = 6 @@ -409,8 +408,7 @@ function test_mcmc_algorithm() α = 0.0 θ = 1.0 - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, - op=[0.6; 0.2; 0.2]) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, op=[0.6; 0.2; 0.2]) trueProbK = [0.0572011678382854799052026351091626565903425216674804687500000; 0.3147244396041969372035396190767642110586166381835937500000000; @@ -456,11 +454,11 @@ function test_mcmc_algorithm() 0.0326157471566144094299311007034702925011515617370606], (4, 3))' - kpax3mcmc(x, partition, settings) + Kpax3.kpax3mcmc(x, partition, settings) - (k, estimK) = readposteriork(settings.ofile) - (id, estimP) = readposteriorP(settings.ofile) - (site, aa, freq, estimS) = readposteriorC(settings.ofile) + (k, estimK) = Kpax3.readposteriork(settings.ofile) + (id, estimP) = Kpax3.readposteriorP(settings.ofile) + (site, aa, freq, estimS) = Kpax3.readposteriorC(settings.ofile) @test isapprox(estimK, trueProbK, rtol=0.02) @test isapprox(estimP, trueProbP, rtol=0.02) @@ -470,8 +468,7 @@ function test_mcmc_algorithm() α = 0.5 θ = -0.25 - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, - op=[0.6; 0.2; 0.2]) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, op=[0.6; 0.2; 0.2]) trueProbK = [0.20304357310850917883726651780307292938232421875000000000; 0.21850248716493331224697271863988135010004043579101562500; @@ -517,11 +514,11 @@ function test_mcmc_algorithm() 0.0257256929731574761344159441023293766193091869354248], (4, 3))' - kpax3mcmc(x, partition, settings) + Kpax3.kpax3mcmc(x, partition, settings) - (k, estimK) = readposteriork(settings.ofile) - (id, estimP) = readposteriorP(settings.ofile) - (site, aa, freq, estimS) = readposteriorC(settings.ofile) + (k, estimK) = Kpax3.readposteriork(settings.ofile) + (id, estimP) = Kpax3.readposteriorP(settings.ofile) + (site, aa, freq, estimS) = Kpax3.readposteriorC(settings.ofile) @test isapprox(estimK, trueProbK, rtol=0.02) @test isapprox(estimP, trueProbP, rtol=0.02) @@ -531,8 +528,7 @@ function test_mcmc_algorithm() α = 0.5 θ = 0.0 - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, - op=[0.6; 0.2; 0.2]) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, op=[0.6; 0.2; 0.2]) trueProbK = [0.08297365650265563219445397180606960318982601165771484375; 0.17858186829001693185503540917125064879655838012695312500; @@ -578,11 +574,11 @@ function test_mcmc_algorithm() 0.0303205997137780264294448784312407951802015304565430], (4, 3))' - kpax3mcmc(x, partition, settings) + Kpax3.kpax3mcmc(x, partition, settings) - (k, estimK) = readposteriork(settings.ofile) - (id, estimP) = readposteriorP(settings.ofile) - (site, aa, freq, estimS) = readposteriorC(settings.ofile) + (k, estimK) = Kpax3.readposteriork(settings.ofile) + (id, estimP) = Kpax3.readposteriorP(settings.ofile) + (site, aa, freq, estimS) = Kpax3.readposteriorC(settings.ofile) @test isapprox(estimK, trueProbK, rtol=0.02) @test isapprox(estimP, trueProbP, rtol=0.02) @@ -592,8 +588,7 @@ function test_mcmc_algorithm() α = -1 θ = 4 - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, - op=[0.6; 0.2; 0.2]) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1, alpha=α, theta=θ, op=[0.6; 0.2; 0.2]) trueProbK = [0.013987232861628222380101504995764116756618022918701171875; 0.277957780373217555602849415663513354957103729248046875000; @@ -637,11 +632,11 @@ function test_mcmc_algorithm() 0.0366354411681910074882750905089778825640678405761719], (4, 3))' - kpax3mcmc(x, partition, settings) + Kpax3.kpax3mcmc(x, partition, settings) - (k, estimK) = readposteriork(settings.ofile) - (id, estimP) = readposteriorP(settings.ofile) - (site, aa, freq, estimS) = readposteriorC(settings.ofile) + (k, estimK) = Kpax3.readposteriork(settings.ofile) + (id, estimP) = Kpax3.readposteriorP(settings.ofile) + (site, aa, freq, estimS) = Kpax3.readposteriorC(settings.ofile) @test isapprox(estimK, trueProbK, rtol=0.02) @test isapprox(estimP, trueProbP, rtol=0.02) diff --git a/test/mcmc/split.jl b/test/mcmc/split.jl index c692014..540c55d 100644 --- a/test/mcmc/split.jl +++ b/test/mcmc/split.jl @@ -5,7 +5,7 @@ function test_mcmc_split_init() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -28,8 +28,8 @@ function test_mcmc_split_init() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 13; 13; 76] k = length(unique(R)) + 1 @@ -38,10 +38,10 @@ function test_mcmc_split_init() S = 3 u = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportsplit!(ij, k, data, priorC, settings, support) + Kpax3.initsupportsplit!(ij, k, data, priorC, settings, support) len = 4 @@ -50,55 +50,29 @@ function test_mcmc_split_init() for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end @test support.lp == lp wi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end ci = Float64[log(sum(exp(support.wi.w[:, b]))) for b in 1:m] wj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end cj = Float64[log(sum(exp(support.wj.w[:, b]))) for b in 1:m] @@ -129,7 +103,7 @@ function test_mcmc_split_updatei() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -152,8 +126,8 @@ function test_mcmc_split_updatei() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 13; 13; 76] k = length(unique(R)) + 1 @@ -162,10 +136,10 @@ function test_mcmc_split_updatei() S = 3 u = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportsplit!(ij, k, data, priorC, settings, support) + Kpax3.initsupportsplit!(ij, k, data, priorC, settings, support) len = 4 @@ -174,49 +148,26 @@ function test_mcmc_split_updatei() for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end @test support.lp == lp lcp = zeros(Float64, 2) for b in 1:m - lcp[1] += computeclusteriseqprobs!(data[b, u], b, priorC, support) - lcp[2] += computeclusterjseqprobs!(data[b, u], b, priorC, support) + lcp[1] += Kpax3.computeclusteriseqprobs!(data[b, u], b, priorC, support) + lcp[2] += Kpax3.computeclusterjseqprobs!(data[b, u], b, priorC, support) end - updateclusteri!(u, data, support) + Kpax3.updateclusteri!(u, data, support) wi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[1, col], priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[2, col], priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[3, col], priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[4, col], priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end zi = copy(wi) @@ -225,37 +176,15 @@ function test_mcmc_split_updatei() wj = zeros(Float64, 4, m) zj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) - - zj[1, col] = wj[1, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[1, col], priorC.B[1, col]) - - zj[2, col] = wj[2, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[2, col], priorC.B[2, col]) - - zj[3, col] = wj[3, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[3, col], priorC.B[3, col]) - - zj[4, col] = wj[4, col] + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[4, col], priorC.B[4, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) + + zj[1, col] = wj[1, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + zj[2, col] = wj[2, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + zj[3, col] = wj[3, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + zj[4, col] = wj[4, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end cj = Float64[log(sum(exp(support.wj.w[:, b]))) for b in 1:m] @@ -284,7 +213,7 @@ function test_mcmc_split_updatej() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -307,8 +236,8 @@ function test_mcmc_split_updatej() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 13; 13; 76] k = length(unique(R)) + 1 @@ -317,10 +246,10 @@ function test_mcmc_split_updatej() S = 3 u = 4 - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportsplit!(ij, k, data, priorC, settings, support) + Kpax3.initsupportsplit!(ij, k, data, priorC, settings, support) len = 4 @@ -329,87 +258,42 @@ function test_mcmc_split_updatej() for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end @test support.lp == lp lcp = zeros(Float64, 2) for b in 1:m - lcp[1] += computeclusteriseqprobs!(data[b, u], b, priorC, support) - lcp[2] += computeclusterjseqprobs!(data[b, u], b, priorC, support) + lcp[1] += Kpax3.computeclusteriseqprobs!(data[b, u], b, priorC, support) + lcp[2] += Kpax3.computeclusterjseqprobs!(data[b, u], b, priorC, support) end - updateclusterj!(u, data, support) + Kpax3.updateclusterj!(u, data, support) wi = zeros(Float64, 4, m) zi = zeros(Float64, 4, m) for col in 1:m - wi[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[1]], 1, priorC.A[1, col], - priorC.B[1, col]) - - wi[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[1]], 1, priorC.A[2, col], - priorC.B[2, col]) - - wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[1]], 1, priorC.A[3, col], - priorC.B[3, col]) - - wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[1]], 1, priorC.A[4, col], - priorC.B[4, col]) - - zi[1, col] = wi[1, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[1, col], priorC.B[1, col]) - - zi[2, col] = wi[2, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[2, col], priorC.B[2, col]) - - zi[3, col] = wi[3, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[3, col], priorC.B[3, col]) - - zi[4, col] = wi[4, col] + - logcondmarglik(data[col, u], data[col, ij[1]], 1, - priorC.A[4, col], priorC.B[4, col]) + wi[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + wi[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + wi[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + wi[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) + + zi[1, col] = wi[1, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[1, col], priorC.B[1, col]) + zi[2, col] = wi[2, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[2, col], priorC.B[2, col]) + zi[3, col] = wi[3, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[3, col], priorC.B[3, col]) + zi[4, col] = wi[4, col] + Kpax3.logcondmarglik(data[col, u], data[col, ij[1]], 1, priorC.A[4, col], priorC.B[4, col]) end ci = Float64[log(sum(exp(support.wi.w[:, b]))) for b in 1:m] wj = zeros(Float64, 4, m) for col in 1:m - wj[1, col] = priorC.logγ[1] + - logmarglik(data[col, ij[2]], 1, priorC.A[1, col], - priorC.B[1, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[1, col], priorC.B[1, col]) - - wj[2, col] = priorC.logγ[2] + - logmarglik(data[col, ij[2]], 1, priorC.A[2, col], - priorC.B[2, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[2, col], priorC.B[2, col]) - - wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + - logmarglik(data[col, ij[2]], 1, priorC.A[3, col], - priorC.B[3, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[3, col], priorC.B[3, col]) - - wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + - logmarglik(data[col, ij[2]], 1, priorC.A[4, col], - priorC.B[4, col]) + - logcondmarglik(data[col, u], data[col, ij[2]], 1, - priorC.A[4, col], priorC.B[4, col]) + wj[1, col] = priorC.logγ[1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[1, col], priorC.B[1, col]) + wj[2, col] = priorC.logγ[2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[2, col], priorC.B[2, col]) + wj[3, col] = priorC.logγ[3] + priorC.logω[k][1] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[3, col], priorC.B[3, col]) + wj[4, col] = priorC.logγ[3] + priorC.logω[k][2] + Kpax3.logmarglik(data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) + Kpax3.logcondmarglik(data[col, u], data[col, ij[2]], 1, priorC.A[4, col], priorC.B[4, col]) end zj = copy(wj) @@ -441,7 +325,7 @@ function test_mcmc_updatelogmarglik() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -464,8 +348,8 @@ function test_mcmc_updatelogmarglik() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [13; 13; 13; 13; 13; 76] k = length(unique(R)) + 1 @@ -483,21 +367,21 @@ function test_mcmc_updatelogmarglik() lpi = zeros(Float64, 4, m) lpj = zeros(Float64, 4, m) for b in 1:m - lpi[1, b] = logmarglik(ni[b], vi, priorC.A[1, b], priorC.B[1, b]) - lpi[2, b] = logmarglik(ni[b], vi, priorC.A[2, b], priorC.B[2, b]) - lpi[3, b] = logmarglik(ni[b], vi, priorC.A[3, b], priorC.B[3, b]) - lpi[4, b] = logmarglik(ni[b], vi, priorC.A[4, b], priorC.B[4, b]) - - lpj[1, b] = logmarglik(nj[b], vj, priorC.A[1, b], priorC.B[1, b]) - lpj[2, b] = logmarglik(nj[b], vj, priorC.A[2, b], priorC.B[2, b]) - lpj[3, b] = logmarglik(nj[b], vj, priorC.A[3, b], priorC.B[3, b]) - lpj[4, b] = logmarglik(nj[b], vj, priorC.A[4, b], priorC.B[4, b]) + lpi[1, b] = Kpax3.logmarglik(ni[b], vi, priorC.A[1, b], priorC.B[1, b]) + lpi[2, b] = Kpax3.logmarglik(ni[b], vi, priorC.A[2, b], priorC.B[2, b]) + lpi[3, b] = Kpax3.logmarglik(ni[b], vi, priorC.A[3, b], priorC.B[3, b]) + lpi[4, b] = Kpax3.logmarglik(ni[b], vi, priorC.A[4, b], priorC.B[4, b]) + + lpj[1, b] = Kpax3.logmarglik(nj[b], vj, priorC.A[1, b], priorC.B[1, b]) + lpj[2, b] = Kpax3.logmarglik(nj[b], vj, priorC.A[2, b], priorC.B[2, b]) + lpj[3, b] = Kpax3.logmarglik(nj[b], vj, priorC.A[3, b], priorC.B[3, b]) + lpj[4, b] = Kpax3.logmarglik(nj[b], vj, priorC.A[4, b], priorC.B[4, b]) end - state = AminoAcidState(data, R, priorR, priorC, settings) - support = MCMCSupport(state, priorC) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + support = Kpax3.MCMCSupport(state, priorC) - initsupportsplit!(ij, k, data, priorC, settings, support) + Kpax3.initsupportsplit!(ij, k, data, priorC, settings, support) support.ni = copy(ni) support.vi = copy(vi) @@ -505,8 +389,8 @@ function test_mcmc_updatelogmarglik() support.nj = copy(nj) support.vj = copy(vj) - updatelogmargliki!(priorC, support) - updatelogmarglikj!(priorC, support) + Kpax3.updatelogmargliki!(priorC, support) + Kpax3.updatelogmarglikj!(priorC, support) @test support.lpi == lpi @test support.lpj == lpj @@ -514,8 +398,8 @@ function test_mcmc_updatelogmarglik() fill!(support.lpi, 0.0) fill!(support.lpj, 0.0) - updatelogmargliki!(ni, vi, priorC, support) - updatelogmarglikj!(nj, vj, priorC, support) + Kpax3.updatelogmargliki!(ni, vi, priorC, support) + Kpax3.updatelogmarglikj!(nj, vj, priorC, support) @test support.lpi == lpi @test support.lpj == lpj diff --git a/test/mcmc/weight.jl b/test/mcmc/weight.jl index 6461b78..25a45d9 100644 --- a/test/mcmc/weight.jl +++ b/test/mcmc/weight.jl @@ -4,29 +4,29 @@ function test_mcmc_clusterweight() n = 10 k = 2 - priorR = EwensPitman(0.5, -0.1) - @test_approx_eq_eps clusterweight(n, priorR) log(n - 0.5) ε + priorR = Kpax3.EwensPitman(0.5, -0.1) + @test_approx_eq_eps Kpax3.clusterweight(n, priorR) log(n - 0.5) ε - priorR = EwensPitman(0.5, 0.0) - @test_approx_eq_eps clusterweight(n, priorR) log(n - 0.5) ε + priorR = Kpax3.EwensPitman(0.5, 0.0) + @test_approx_eq_eps Kpax3.clusterweight(n, priorR) log(n - 0.5) ε - priorR = EwensPitman(0, 2.0) - @test_approx_eq_eps clusterweight(n, priorR) log(n) ε + priorR = Kpax3.EwensPitman(0, 2.0) + @test_approx_eq_eps Kpax3.clusterweight(n, priorR) log(n) ε - priorR = EwensPitman(-2, 5) - @test_approx_eq_eps clusterweight(n, priorR) log(n + 2.0) ε + priorR = Kpax3.EwensPitman(-2, 5) + @test_approx_eq_eps Kpax3.clusterweight(n, priorR) log(n + 2.0) ε - priorR = EwensPitman(0.5, -0.1) - @test_approx_eq_eps clusterweight(n, k, priorR) log(0.5 * k - 0.1) ε + priorR = Kpax3.EwensPitman(0.5, -0.1) + @test_approx_eq_eps Kpax3.clusterweight(n, k, priorR) log(0.5 * k - 0.1) ε - priorR = EwensPitman(0.5, 0.0) - @test_approx_eq_eps clusterweight(n, k, priorR) log(0.5 * k) ε + priorR = Kpax3.EwensPitman(0.5, 0.0) + @test_approx_eq_eps Kpax3.clusterweight(n, k, priorR) log(0.5 * k) ε - priorR = EwensPitman(0, 2.0) - @test_approx_eq_eps clusterweight(n, k, priorR) log(2) ε + priorR = Kpax3.EwensPitman(0, 2.0) + @test_approx_eq_eps Kpax3.clusterweight(n, k, priorR) log(2) ε - priorR = EwensPitman(-2, 5) - @test_approx_eq_eps clusterweight(n, k, priorR) log(-2.0 * (k - 5)) ε + priorR = Kpax3.EwensPitman(-2, 5) + @test_approx_eq_eps Kpax3.clusterweight(n, k, priorR) log(-2.0 * (k - 5)) ε nothing end diff --git a/test/misc/basic_functions.jl b/test/misc/basic_functions.jl index 34d25cf..c646d9b 100644 --- a/test/misc/basic_functions.jl +++ b/test/misc/basic_functions.jl @@ -1,6 +1,6 @@ # This file is part of Kpax3. License is MIT. -function test_basic_functions_shuffle() +function test_basic_functions_shuffleunits() x = [1; 2; 3; 4; 5; 6] y = [1; 2; 3; 4; 5; 6] @@ -15,13 +15,13 @@ function test_basic_functions_shuffle() v2 = 0 for i in 1:N - shuffle!(x) + Kpax3.shuffleunits!(x) if x == [3; 1; 2; 4; 5; 6] v1 += 1 end - shuffle!(y, S) + Kpax3.shuffleunits!(y, S) if y == [2; 1; 3; 4; 5; 6] v2 += 1 @@ -37,4 +37,4 @@ function test_basic_functions_shuffle() nothing end -test_basic_functions_shuffle() +test_basic_functions_shuffleunits() diff --git a/test/misc/partition_functions.jl b/test/misc/partition_functions.jl index c15c55e..594ee65 100644 --- a/test/misc/partition_functions.jl +++ b/test/misc/partition_functions.jl @@ -7,27 +7,25 @@ function test_partition_functions_initializepartition() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) - R = initializepartition(settings) + R = Kpax3.initializepartition(settings) @test isa(R, Vector{Int}) @test minimum(R) >= 1 @test maximum(R) <= 6 - R = initializepartition(settings, kset=2:3) + R = Kpax3.initializepartition(settings, kset=2:3) @test isa(R, Vector{Int}) @test minimum(R) >= 1 @test maximum(R) <= 3 - (data, id, ref) = readfasta(ifile, true, - UInt8['?', '*', '#', 'b', 'j', 'x', 'z'], - 100000000, false, 0) + (data, id, ref) = Kpax3.readfasta(ifile, true, UInt8['?', '*', '#', 'b', 'j', 'x', 'z'], 100000000, false, 0) n = size(data, 2) - d = distaamtn84(data, ref) + d = Kpax3.distaamtn84(data, ref) D = zeros(Float64, n, n) idx = 0 @@ -36,15 +34,15 @@ function test_partition_functions_initializepartition() D[i, j] = D[j, i] = d[idx] end - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) - R = initializepartition(x.data, D, settings) + R = Kpax3.initializepartition(x.data, D, settings) @test isa(R, Vector{Int}) @test minimum(R) >= 1 @test maximum(R) <= 6 - R = initializepartition(x.data, D, settings, kset=2:3) + R = Kpax3.initializepartition(x.data, D, settings, kset=2:3) @test isa(R, Vector{Int}) @test minimum(R) >= 1 @@ -59,7 +57,7 @@ function test_partition_functions_encodepartition() R = zeros(Int, 6) S = [3; 3; 3; 2; 2; 1] - encodepartition!(R, S) + Kpax3.encodepartition!(R, S) @test R == [1; 2; 3; 22; 23; 36] @@ -71,7 +69,7 @@ test_partition_functions_encodepartition() function test_partition_functions_decodepartition() R = [1; 2; 3; 22; 23; 36] - decodepartition!(R) + Kpax3.decodepartition!(R) @test R == [1; 1; 1; 4; 4; 6] diff --git a/test/model/likelihoods.jl b/test/model/likelihoods.jl index 55c4d3a..b6f5b42 100644 --- a/test/model/likelihoods.jl +++ b/test/model/likelihoods.jl @@ -1,65 +1,50 @@ # This file is part of Kpax3. License is MIT. function test_likelihoods_marginal() - for (α, β) in ([0.1, 0.1], [0.5, 0.5], [1.0, 1.0], [10.0, 10.0], - [100.0, 100.0], [0.2, 0.1], [1.0, 0.5], [2.0, 1.0], - [20.0, 10.0], [200.0, 100.0], [0.1, 0.2], [0.5, 1.0], - [1.0, 2.0], [10.0, 20.0], [100.0, 200.0]) - for (n, y) in ([ 1.0, 0.0], [ 1.0, 1.0], - [ 5.0, 0.0], [ 5.0, 1.0], [ 5.0, 3.0], [ 5.0, 5.0], - [ 10.0, 0.0], [ 10.0, 1.0], [ 10.0, 5.0], [ 10.0, 10.0], - [100.0, 0.0], [100.0, 1.0], [100.0, 10.0], [100.0, 100.0]) - logp = lgamma(α + y) + lgamma(β + n - y) - lgamma(α + β + n) + - lgamma(α + β) - lgamma(α) - lgamma(β) + for (α, β) in ([0.1, 0.1], [0.5, 0.5], [1.0, 1.0], [10.0, 10.0], [100.0, 100.0], [0.2, 0.1], [1.0, 0.5], [2.0, 1.0], [20.0, 10.0], [200.0, 100.0], [0.1, 0.2], [0.5, 1.0], [1.0, 2.0], [10.0, 20.0], [100.0, 200.0]) + for (n, y) in ([1.0, 0.0], [1.0, 1.0], [5.0, 0.0], [5.0, 1.0], [5.0, 3.0], [5.0, 5.0], [10.0, 0.0], [10.0, 1.0], [10.0, 5.0], [10.0, 10.0], [100.0, 0.0], [100.0, 1.0], [100.0, 10.0], [100.0, 100.0]) + logp = lgamma(α + y) + lgamma(β + n - y) - lgamma(α + β + n) + lgamma(α + β) - lgamma(α) - lgamma(β) logcp0 = log(β + n - y) - log(α + β + n) logcp1 = log(α + y) - log(α + β + n) - @test_approx_eq_eps marglik(y, n, α, β) exp(logp) ε - @test_approx_eq_eps logmarglik(y, n, α, β) logp ε + @test_approx_eq_eps Kpax3.marglik(y, n, α, β) exp(logp) ε + @test_approx_eq_eps Kpax3.logmarglik(y, n, α, β) logp ε - @test_approx_eq_eps condmarglik(0x00, y, n, α, β) exp(logcp0) ε - @test_approx_eq_eps condmarglik(0x01, y, n, α, β) exp(logcp1) ε + @test_approx_eq_eps Kpax3.condmarglik(0x00, y, n, α, β) exp(logcp0) ε + @test_approx_eq_eps Kpax3.condmarglik(0x01, y, n, α, β) exp(logcp1) ε - @test_approx_eq_eps logcondmarglik(0x00, y, n, α, β) logcp0 ε - @test_approx_eq_eps logcondmarglik(0x01, y, n, α, β) logcp1 ε + @test_approx_eq_eps Kpax3.logcondmarglik(0x00, y, n, α, β) logcp0 ε + @test_approx_eq_eps Kpax3.logcondmarglik(0x01, y, n, α, β) logcp1 ε end end - for (α, β) in ([0.1, 0.1], [0.5, 0.5], [1.0, 1.0], [10.0, 10.0], - [100.0, 100.0], [0.2, 0.1], [1.0, 0.5], [2.0, 1.0], - [20.0, 10.0], [200.0, 100.0], [0.1, 0.2], [0.5, 1.0], - [1.0, 2.0], [10.0, 20.0], [100.0, 200.0]) - for (n, y) in (( 1.0, [ 0.0, 0.0, 1.0, 0.0, 1.0]), - ( 10.0, [ 2.0, 8.0, 5.0, 10.0, 0.0]), - (100.0, [100.0, 2.0, 72.0, 34.0, 0.0])) + for (α, β) in ([0.1, 0.1], [0.5, 0.5], [1.0, 1.0], [10.0, 10.0], [100.0, 100.0], [0.2, 0.1], [1.0, 0.5], [2.0, 1.0], [20.0, 10.0], [200.0, 100.0], [0.1, 0.2], [0.5, 1.0], [1.0, 2.0], [10.0, 20.0], [100.0, 200.0]) + for (n, y) in ((1.0, [0.0, 0.0, 1.0, 0.0, 1.0]), (10.0, [2.0, 8.0, 5.0, 10.0, 0.0]), (100.0, [100.0, 2.0, 72.0, 34.0, 0.0])) m = length(y) n1s = cld(m, 2) a = fill(α, m) b = fill(β, m) - q = marglik(y, n, a, b) - logq = logmarglik(y, n, a, b) + q = Kpax3.marglik(y, n, a, b) + logq = Kpax3.logmarglik(y, n, a, b) - q0 = condmarglik(fill(0x00, m), y, n, a, b) - logq0 = logcondmarglik(fill(0x00, m), y, n, a, b) + q0 = Kpax3.condmarglik(fill(0x00, m), y, n, a, b) + logq0 = Kpax3.logcondmarglik(fill(0x00, m), y, n, a, b) - q1 = condmarglik(fill(0x01, m), y, n, a, b) - logq1 = logcondmarglik(fill(0x01, m), y, n, a, b) + q1 = Kpax3.condmarglik(fill(0x01, m), y, n, a, b) + logq1 = Kpax3.logcondmarglik(fill(0x01, m), y, n, a, b) - qx = condmarglik([fill(0x01, n1s); fill(0x00, m - n1s)], y, n, a, b) - logqx = logcondmarglik([fill(0x01, n1s); fill(0x00, m - n1s)], - y, n, a, b) + qx = Kpax3.condmarglik([fill(0x01, n1s); fill(0x00, m - n1s)], y, n, a, b) + logqx = Kpax3.logcondmarglik([fill(0x01, n1s); fill(0x00, m - n1s)], y, n, a, b) - logp = lgamma(a + y) + lgamma(b + n - y) - lgamma(a + b + n) + - lgamma(a + b) - lgamma(a) - lgamma(b) + logp = lgamma(a + y) + lgamma(b + n - y) - lgamma(a + b + n) + lgamma(a + b) - lgamma(a) - lgamma(b) logcp0 = log(b + n - y) - log(a + b + n) logcp1 = log(a + y) - log(a + b + n) - logcpx = log([a[1:n1s] + y[1:n1s]; - b[(n1s + 1):m] + n - y[(n1s + 1):m]]) - log(a + b + n) + logcpx = log([a[1:n1s] + y[1:n1s]; b[(n1s + 1):m] + n - y[(n1s + 1):m]]) - log(a + b + n) for i in 1:m @test_approx_eq_eps q[i] exp(logp[i]) ε @@ -86,7 +71,7 @@ function test_likelihoods_loglik() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -109,12 +94,12 @@ function test_likelihoods_loglik() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [1; 1; 1; 4; 6; 6] - state = AminoAcidState(data, R, priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) copy!(state.R, R) # fill C with harmless wrong values, just in case @@ -141,30 +126,26 @@ function test_likelihoods_loglik() state.unit[4] = [4; 0; 0; 0; 0; 0] state.unit[6] = [5; 6; 0; 0; 0; 0] - support = MCMCSupport(state, priorC); + support = Kpax3.MCMCSupport(state, priorC); - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) loglik = zeros(Float64, 3) linearidx = Int[state.C[1, b] + 4 * (b - 1) for b in 1:m] - loglik[1] = sum(logmarglik(vec(state.n1s[1, :]), state.v[1], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[1] = sum(Kpax3.logmarglik(vec(state.n1s[1, :]), state.v[1], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[4, b] + 4 * (b - 1) for b in 1:m] - loglik[2] = sum(logmarglik(vec(state.n1s[4, :]), state.v[4], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[2] = sum(Kpax3.logmarglik(vec(state.n1s[4, :]), state.v[4], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[6, b] + 4 * (b - 1) for b in 1:m] - loglik[3] = sum(logmarglik(vec(state.n1s[6, :]), state.v[6], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[3] = sum(Kpax3.logmarglik(vec(state.n1s[6, :]), state.v[6], priorC.A[linearidx], priorC.B[linearidx])) ll = loglik[1] + loglik[2] + loglik[3] - @test_approx_eq_eps loglikelihood(state.C, state.cl, state.k, state.v, - state.n1s, priorC) ll ε - @test_approx_eq_eps loglikelihood(state.C, state.cl, state.k, support) ll ε + @test_approx_eq_eps Kpax3.loglikelihood(state.C, state.cl, state.k, state.v, state.n1s, priorC) ll ε + @test_approx_eq_eps Kpax3.loglikelihood(state.C, state.cl, state.k, support) ll ε nothing end @@ -175,7 +156,7 @@ function test_likelihoods_logmarginal() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -198,8 +179,8 @@ function test_likelihoods_logmarginal() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [3; 3; 1; 1; 5; 5] g = sort(unique(R)) @@ -230,13 +211,11 @@ function test_likelihoods_logmarginal() loglik = -66.7559125873377894322402426041662693023681640625 logpp = logpR + logpC[1] + loglik - state = AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, - copy(v), copy(n1s), deepcopy(unit), logpR, - copy(logpC), loglik, logpp) + state = Kpax3.AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, copy(v), copy(n1s), deepcopy(unit), logpR, copy(logpC), loglik, logpp) - support = MCMCSupport(state, priorC) + support = Kpax3.MCMCSupport(state, priorC) - logmlik = logmarglikelihood(state.cl, state.k, support.lp, priorC) + logmlik = Kpax3.logmarglikelihood(state.cl, state.k, support.lp, priorC) lml = 0.0 tmp = zeros(Float64, 3) @@ -250,8 +229,7 @@ function test_likelihoods_logmarginal() tmp[1] += support.lp[1, g, b] tmp[2] += support.lp[2, g, b] - tmp[3] += log(exp(priorC.logω[k][1] + support.lp[3, g, b]) + - exp(priorC.logω[k][2] + support.lp[4, g, b])) + tmp[3] += log(exp(priorC.logω[k][1] + support.lp[3, g, b]) + exp(priorC.logω[k][2] + support.lp[4, g, b])) end lml += log(exp(tmp[1]) + exp(tmp[2]) + exp(tmp[3])) diff --git a/test/model/loss_binder.jl b/test/model/loss_binder.jl index 760f7a2..71ee949 100644 --- a/test/model/loss_binder.jl +++ b/test/model/loss_binder.jl @@ -18,7 +18,7 @@ function test_loss_binder() 1 1 1 1 1 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -32,7 +32,7 @@ function test_loss_binder() 0 0 1 1 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -45,7 +45,7 @@ function test_loss_binder() 0 1 0 1 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -59,7 +59,7 @@ function test_loss_binder() 0 0 1 1 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -72,7 +72,7 @@ function test_loss_binder() 0 0 1 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -86,7 +86,7 @@ function test_loss_binder() 0 0 0 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -99,7 +99,7 @@ function test_loss_binder() 0 1 0 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -113,7 +113,7 @@ function test_loss_binder() 0 0 0 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -126,7 +126,7 @@ function test_loss_binder() 0 0 0 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε @@ -140,7 +140,7 @@ function test_loss_binder() 0 0 0 0 0 1] losscorrect = sum(abs(A - P)) / 2 - lossfunction = loss_binder(R, P) + lossfunction = Kpax3.loss_binder(R, P) @test_approx_eq_eps lossfunction losscorrect ε diff --git a/test/model/partition_cols.jl b/test/model/partition_cols.jl index 556e33b..295f33a 100644 --- a/test/model/partition_cols.jl +++ b/test/model/partition_cols.jl @@ -1,20 +1,19 @@ # This file is part of Kpax3. License is MIT. - #= R = [1; 1; 2; 2; 3; 1] k = length(unique(R)) -priorR = EwensPitman(settings.α, settings.θ) -priorC = AminoAcidPriorCol(data, settings.γ, settings.r) +priorR = Kpax3.EwensPitman(settings.α, settings.θ) +priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) ss = UInt8[1; 2; 3] -obj = AminoAcidState(data, R, priorR, priorC, settings) +obj = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) M = -Inf for s1 in ss, s2 in ss, s3 in ss, s4 in ss S = [s1; s2; s3; s4] - lp = logcondpostS(S, obj.cl, obj.k, obj.v, obj.n1s, priorC) + lp = Kpax3.logcondpostS(S, obj.cl, obj.k, obj.v, obj.n1s, priorC) if lp > M M = lp @@ -24,7 +23,7 @@ end trueSp = zeros(Float64, 3, 4) for s1 in ss, s2 in ss, s3 in ss, s4 in ss S = [s1; s2; s3; s4] - lp = logcondpostS(S, obj.cl, obj.k, obj.v, obj.n1s, priorC) + lp = Kpax3.logcondpostS(S, obj.cl, obj.k, obj.v, obj.n1s, priorC) trueSp[s1, 1] += exp(lp - M) trueSp[s2, 2] += exp(lp - M) @@ -38,12 +37,12 @@ for i in 1:12 @printf("%.100f\n", trueSp[i]) end -rpostpartitioncols!(obj.C, obj.cl, obj.k, obj.v, obj.n1s, priorC); +Kpax3.rpostpartitioncols!(obj.C, obj.cl, obj.k, obj.v, obj.n1s, priorC); obj.C[obj.cl[1:obj.k], :] obj.C[obj.cl[1:obj.k], :] = Ctest1 -p = exp(logcondpostC(obj.C, obj.cl, obj.k, obj.v, obj.n1s, priorC)) +p = exp(Kpax3.logcondpostC(obj.C, obj.cl, obj.k, obj.v, obj.n1s, priorC)) @printf("%.100f\n", p) =# @@ -99,11 +98,9 @@ function test_partition_cols_constructor() B2[4, :] = 1.0 for k in 1:n - for γ in ([1.0; 0.0; 0.0], [0.0; 1.0; 0.0], [0.0; 0.0; 1.0], - [0.4; 0.3; 0.3], [0.5; 0.3; 0.2], [0.7; 0.2; 0.1], - [0.1; 0.1; 0.1], [0.3; 0.1; 0.1], [0.0; 0.2; 0.1]) - x1 = AminoAcidPriorCol(data, γ, r1) - x2 = AminoAcidPriorCol(data, γ, r2) + for γ in ([1.0; 0.0; 0.0], [0.0; 1.0; 0.0], [0.0; 0.0; 1.0], [0.4; 0.3; 0.3], [0.5; 0.3; 0.2], [0.7; 0.2; 0.1], [0.1; 0.1; 0.1], [0.3; 0.1; 0.1], [0.0; 0.2; 0.1]) + x1 = Kpax3.AminoAcidPriorCol(data, γ, r1) + x2 = Kpax3.AminoAcidPriorCol(data, γ, r2) @test_approx_eq_eps x1.logγ[1] log(γ[1] / sum(γ)) ε @test_approx_eq_eps x2.logγ[2] log(γ[2] / sum(γ)) ε @@ -138,21 +135,19 @@ function test_partition_cols_functions() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=6, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=6, maxunit=1) R = [1; 1; 2; 2; 3; 1] k = length(unique(R)) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, R, priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) C = zeros(UInt8, settings.maxclust, m) - cs = (UInt8[1; 1; 1], UInt8[2; 2; 2], UInt8[3; 3; 3], UInt8[3; 3; 4], - UInt8[3; 4; 3], UInt8[4; 3; 3], UInt8[3; 4; 4], UInt8[4; 3; 4], - UInt8[4; 4; 3], UInt8[4; 4; 4]) + cs = (UInt8[1; 1; 1], UInt8[2; 2; 2], UInt8[3; 3; 3], UInt8[3; 3; 4], UInt8[3; 4; 3], UInt8[4; 3; 3], UInt8[3; 4; 4], UInt8[4; 3; 4], UInt8[4; 4; 3], UInt8[4; 4; 4]) logp1 = zeros(Float64, (2 + 2^k)^m) logp2 = zeros(Float64, (2 + 2^k)^m) @@ -169,9 +164,9 @@ function test_partition_cols_functions() state.C[state.cl[2], :] = C[2, :] = tmp[2, :] state.C[state.cl[3], :] = C[3, :] = tmp[3, :] - logp1[l] = logpriorC(state.C, state.cl, k, priorC) - logp2[l] = logpriorC(C, k, priorC) - logp3[l] = logcondpostC(state.C, state.cl, k, state.v, state.n1s, priorC) + logp1[l] = Kpax3.logpriorC(state.C, state.cl, k, priorC) + logp2[l] = Kpax3.logpriorC(C, k, priorC) + logp3[l] = Kpax3.logcondpostC(state.C, state.cl, k, state.v, state.n1s, priorC) end M = maximum(logp1) @@ -194,7 +189,7 @@ function test_partition_cols_functions() for s1 in ss, s2 in ss, s3 in ss, s4 in ss l += 1 S = [s1; s2; s3; s4] - logp4[l] = logcondpostS(S, state.cl, k, state.v, state.n1s, priorC) + logp4[l] = Kpax3.logcondpostS(S, state.cl, k, state.v, state.n1s, priorC) end M = maximum(logp4) @@ -218,12 +213,12 @@ function test_partition_cols_simulations() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, [1; 1; 2; 2; 3; 1], priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, [1; 1; 2; 2; 3; 1], priorR, priorC, settings) N = 1000000 @@ -247,7 +242,7 @@ function test_partition_cols_simulations() trueCp = 0.023444249569984754177909280770109035074710845947265625 for t in 1:N - rpostpartitioncols!(state.C, state.cl, state.k, state.v, state.n1s, priorC) + Kpax3.rpostpartitioncols!(state.C, state.cl, state.k, state.v, state.n1s, priorC) for b in 1:m if state.C[state.cl[1], b] == 0x01 diff --git a/test/model/partition_rows.jl b/test/model/partition_rows.jl index fc7d8db..7f1a5a1 100644 --- a/test/model/partition_rows.jl +++ b/test/model/partition_rows.jl @@ -4,7 +4,7 @@ function test_partition_rows_functions() include("../data/partitions.jl") for (α, θ) in ((0.4, -0.3), (0.4, 0.0), (0.4, 2.1), (0.0, 2.1), (-2.4, 3)) - ep = EwensPitman(α, θ) + ep = Kpax3.EwensPitman(α, θ) for i in 1:6 po = TestPartition(i) @@ -13,8 +13,8 @@ function test_partition_rows_functions() qr = 0.0 for j in 1:po.B - pr += dPriorRow(po.partition[:, j], ep) - qr += exp(logdPriorRow(po.partition[:, j], ep)) + pr += Kpax3.dPriorRow(po.partition[:, j], ep) + qr += exp(Kpax3.logdPriorRow(po.partition[:, j], ep)) end @test_approx_eq_eps pr 1.0 ε @@ -24,14 +24,12 @@ function test_partition_rows_functions() qr = 0.0 for j in 1:(po.C - 1) - pr += (po.index[j + 1] - po.index[j]) * - dPriorRow(i, po.k[j], po.blocksize[:, j], ep) - qr += (po.index[j + 1] - po.index[j]) * - exp(logdPriorRow(i, po.k[j], po.blocksize[:, j], ep)) + pr += (po.index[j + 1] - po.index[j]) * Kpax3.dPriorRow(i, po.k[j], po.blocksize[:, j], ep) + qr += (po.index[j + 1] - po.index[j]) * exp(Kpax3.logdPriorRow(i, po.k[j], po.blocksize[:, j], ep)) end - pr += dPriorRow(i, po.k[po.C], po.blocksize[:, po.C], ep) - qr += exp(logdPriorRow(i, po.k[po.C], po.blocksize[:, po.C], ep)) + pr += Kpax3.dPriorRow(i, po.k[po.C], po.blocksize[:, po.C], ep) + qr += exp(Kpax3.logdPriorRow(i, po.k[po.C], po.blocksize[:, po.C], ep)) @test_approx_eq_eps pr 1.0 ε @test_approx_eq_eps qr 1.0 ε diff --git a/test/optimizer/crossover.jl b/test/optimizer/crossover.jl index d6c93ee..60daf8b 100644 --- a/test/optimizer/crossover.jl +++ b/test/optimizer/crossover.jl @@ -17,7 +17,7 @@ # Each cutpoint greater than 1 has probability 1 / 5 of being selected # # COLUMN 2 -# If cutpoint == 7, crossover breaks the second child: +# If cutpoint == 7, Kpax3.crossover breaks the second child: # # B1 = [1 0 0 0 0 0; # 0 1 0 0 0 0; @@ -39,7 +39,7 @@ # Pr(B2 = [1; 2; 3; 3; 3; 6] | cutpoint = 7) = 1 / 2 # # COLUMN 3 -# If cutpoint == 14, crossover does not break anything +# If cutpoint == 14, Kpax3.crossover does not break anything # # B1 = [1 0 0 0 0 0; # 1 0 0 0 0 0; @@ -60,7 +60,7 @@ # Pr(B2 = [1; 2; 3; 3; 3; 6] | cutpoint = 14) = 1 # # COLUMN 4 -# If cutpoint == 21, crossover breaks the second child: +# If cutpoint == 21, Kpax3.crossover breaks the second child: # # B1 = [1 0 0 0 0 0; # 1 0 0 0 0 0; @@ -101,7 +101,7 @@ # Pr(B2 = [1; 2; 3; 4; 5; 6] | cutpoint = 21) = (1 / 4) * (1 / 5) = 1 / 20 # # COLUMN 5 -# If cutpoint == 28, crossover breaks the second child: +# If cutpoint == 28, Kpax3.crossover breaks the second child: # # B1 = [1 0 0 0 0 0; # 1 0 0 0 0 0; @@ -126,7 +126,7 @@ # Pr(B2 = [1; 2; 3; 4; 5; 6] | cutpoint = 28) = 1 / 5 # # COLUMN 6 -# If cutpoint == 35, crossover breaks the first child: +# If cutpoint == 35, Kpax3.crossover breaks the first child: # # A1 = [1 0 0 0 0 0; # 1 0 0 0 0 0; @@ -149,7 +149,7 @@ # Pr(B2 = [1; 2; 3; 4; 5; 6] | cutpoint = 35) = 1 # # SUMMARY -# Unique partitions that are possible to be obtained from this crossover: +# Unique partitions that are possible to be obtained from this Kpax3.crossover: # # Pr(B1 = [1; 2; 3; 4; 5; 5]) = Pr(B1 = R2) = 1 / 5 # Pr(B1 = [1; 1; 3; 4; 5; 5]) = 2 / 5 @@ -159,48 +159,38 @@ # Pr(B1 = [1; 1; 3; 3; 3; 6]) = (1 / 5) * (1 / 6) = 1 / 30 # # Pr(B2 = [1; 1; 3; 3; 3; 6]) = (1 / 5) * (1 / 2) = 1 / 10 -# Pr(B2 = [1; 2; 3; 3; 3; 6]) = (1 / 5) * (1 / 2) + -# (1 / 5) * 1 + -# (1 / 5) * (1 / 10) = 8 / 25 +# Pr(B2 = [1; 2; 3; 3; 3; 6]) = (1 / 5) * (1 / 2) + (1 / 5) * 1 + (1 / 5) * (1 / 10) = 8 / 25 # Pr(B2 = [1; 2; 3; 1; 1; 6]) = (1 / 5) * (1 / 10) = 1 / 50 # Pr(B2 = [1; 2; 3; 2; 1; 6]) = (1 / 5) * (1 / 20) = 1 / 100 # Pr(B2 = [1; 2; 3; 3; 1; 6]) = (1 / 5) * (1 / 20) = 1 / 100 -# Pr(B2 = [1; 2; 3; 4; 1; 6]) = (1 / 5) * (1 / 20) + -# (1 / 5) * (1 / 5) = 1 / 20 +# Pr(B2 = [1; 2; 3; 4; 1; 6]) = (1 / 5) * (1 / 20) + (1 / 5) * (1 / 5) = 1 / 20 # Pr(B2 = [1; 2; 3; 1; 2; 6]) = (1 / 5) * (1 / 20) = 1 / 100 # Pr(B2 = [1; 2; 3; 2; 2; 6]) = (1 / 5) * (1 / 10) = 1 / 50 # Pr(B2 = [1; 2; 3; 3; 2; 6]) = (1 / 5) * (1 / 20) = 1 / 100 -# Pr(B2 = [1; 2; 3; 4; 2; 6]) = (1 / 5) * (1 / 20) + -# (1 / 5) * (1 / 5) = 1 / 20 +# Pr(B2 = [1; 2; 3; 4; 2; 6]) = (1 / 5) * (1 / 20) + (1 / 5) * (1 / 5) = 1 / 20 # Pr(B2 = [1; 2; 3; 1; 3; 6]) = (1 / 5) * (1 / 20) = 1 / 100 # Pr(B2 = [1; 2; 3; 2; 3; 6]) = (1 / 5) * (1 / 20) = 1 / 100 -# Pr(B2 = [1; 2; 3; 4; 3; 6]) = (1 / 5) * (1 / 20) + -# (1 / 5) * (1 / 5) = 1 / 20 -# Pr(B2 = [1; 2; 3; 4; 4; 6]) = (1 / 5) * (1 / 20) + -# (1 / 5) * (1 / 5) = 1 / 20 +# Pr(B2 = [1; 2; 3; 4; 3; 6]) = (1 / 5) * (1 / 20) + (1 / 5) * (1 / 5) = 1 / 20 +# Pr(B2 = [1; 2; 3; 4; 4; 6]) = (1 / 5) * (1 / 20) + (1 / 5) * (1 / 5) = 1 / 20 # Pr(B2 = [1; 2; 3; 1; 5; 6]) = (1 / 5) * (1 / 20) = 1 / 100 # Pr(B2 = [1; 2; 3; 2; 5; 6]) = (1 / 5) * (1 / 20) = 1 / 100 # Pr(B2 = [1; 2; 3; 3; 5; 6]) = (1 / 5) * (1 / 20) = 1 / 100 -# Pr(B2 = [1; 2; 3; 4; 5; 6]) = (1 / 5) * (1 / 20) + -# (1 / 5) * (1 / 5) + -# (1 / 5) * 1 = 1 / 4 +# Pr(B2 = [1; 2; 3; 4; 5; 6]) = (1 / 5) * (1 / 20) + (1 / 5) * (1 / 5) + (1 / 5) * 1 = 1 / 4 function test_crossover() - support = GASupport(10, 6) + support = Kpax3.GASupport(10, 6) R1 = [1; 1; 2; 2; 2; 3] R2 = [1; 2; 3; 4; 5; 5] N = 1000000 - pr = [1 / 5; 2 / 5; 1 / 5; 1 / 15; 1 / 10; 1 / 30; 1 / 10; 8 / 25; 1 / 50; - 1 / 100; 1 / 100; 1 / 20; 1 / 100; 1 / 50; 1 / 100; 1 / 20; 1 / 100; - 1 / 100; 1 / 20; 1 / 20; 1 / 100; 1 / 100; 1 / 100; 1 / 4] + pr = [1 / 5; 2 / 5; 1 / 5; 1 / 15; 1 / 10; 1 / 30; 1 / 10; 8 / 25; 1 / 50; 1 / 100; 1 / 100; 1 / 20; 1 / 100; 1 / 50; 1 / 100; 1 / 20; 1 / 100; 1 / 100; 1 / 20; 1 / 20; 1 / 100; 1 / 100; 1 / 100; 1 / 4] tmp = zeros(Float64, length(pr)) for i in 1:N - crossover!(R1, R2, support) + Kpax3.crossover!(R1, R2, support) if support.oi.R == [1; 2; 3; 4; 5; 5] tmp[ 1] += 1 diff --git a/test/optimizer/local_mode.jl b/test/optimizer/local_mode.jl index f97eb75..798f46f 100644 --- a/test/optimizer/local_mode.jl +++ b/test/optimizer/local_mode.jl @@ -7,10 +7,10 @@ #R = [1; 3; 2; 2; 1; 4] k = length(unique(R)) -priorR = EwensPitman(settings.α, settings.θ) -priorC = AminoAcidPriorCol(data, settings.γ, settings.r) +priorR = Kpax3.EwensPitman(settings.α, settings.θ) +priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) -state = AminoAcidState(data, R, priorR, priorC, settings) +state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) C = zeros(UInt8, n, m) @@ -84,8 +84,7 @@ for c1 in cs[state.k], c2 in cs[state.k], c3 in cs[state.k], c4 in cs[state.k] state.C[state.cl[l], :] = tmp[l, :] end - logpnew = logcondpostC(state.C, state.cl, state.k, state.v, state.n1s, - priorC) + logpnew = Kpax3.logcondpostC(state.C, state.cl, state.k, state.v, state.n1s, priorC) if logpnew > logpold logpold = logpnew @@ -100,7 +99,7 @@ function test_local_mode() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile, gamma=[0.3; 0.35; 0.35]) + settings = Kpax3.KSettings(ifile, ofile, gamma=[0.3; 0.35; 0.35]) data = UInt8[1 1 1 1 0 0; 0 0 1 1 0 0; @@ -109,8 +108,8 @@ function test_local_mode() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) # k = 1 R = [1; 1; 1; 1; 1; 1] @@ -122,19 +121,19 @@ function test_local_mode() n1s = zeros(Float64, 6, 4) n1s[1, :] = sum(float(data), 2)' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε # k = 2 R = [1; 1; 1; 1; 2; 2] @@ -144,22 +143,21 @@ function test_local_mode() cl = [1; 2; 0; 0; 0; 0] v = [4; 2; 0; 0; 0; 0] n1s = zeros(Float64, 6, 4) - n1s[1:2, :] = hcat(sum(float(data[:, R .== 1]), 2), - sum(float(data[:, R .== 2]), 2))' + n1s[1:2, :] = hcat(sum(float(data[:, R .== 1]), 2), sum(float(data[:, R .== 2]), 2))' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε # k = 3 R = [1; 1; 2; 2; 3; 3] @@ -169,23 +167,21 @@ function test_local_mode() cl = [1; 2; 3; 0; 0; 0] v = [2; 2; 2; 0; 0; 0] n1s = zeros(Float64, 6, 4) - n1s[1:3, :] = hcat(sum(float(data[:, R .== 1]), 2), - sum(float(data[:, R .== 2]), 2), - sum(float(data[:, R .== 3]), 2))' + n1s[1:3, :] = hcat(sum(float(data[:, R .== 1]), 2), sum(float(data[:, R .== 2]), 2), sum(float(data[:, R .== 3]), 2))' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε # k = 4 R = [1; 3; 2; 2; 1; 4] @@ -195,24 +191,21 @@ function test_local_mode() cl = [1; 2; 3; 4; 0; 0] v = [2; 2; 1; 1; 0; 0] n1s = zeros(Float64, 6, 4) - n1s[1:4, :] = hcat(sum(float(data[:, R .== 1]), 2), - sum(float(data[:, R .== 2]), 2), - sum(float(data[:, R .== 3]), 2), - sum(float(data[:, R .== 4]), 2))' + n1s[1:4, :] = hcat(sum(float(data[:, R .== 1]), 2), sum(float(data[:, R .== 2]), 2), sum(float(data[:, R .== 3]), 2), sum(float(data[:, R .== 4]), 2))' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε # k = 5 R = [1; 2; 3; 3; 4; 5] @@ -222,25 +215,21 @@ function test_local_mode() cl = [1; 2; 3; 4; 5; 0] v = [1; 1; 2; 1; 1; 0] n1s = zeros(Float64, 6, 4) - n1s[1:5, :] = hcat(sum(float(data[:, R .== 1]), 2), - sum(float(data[:, R .== 2]), 2), - sum(float(data[:, R .== 3]), 2), - sum(float(data[:, R .== 4]), 2), - sum(float(data[:, R .== 5]), 2))' + n1s[1:5, :] = hcat(sum(float(data[:, R .== 1]), 2), sum(float(data[:, R .== 2]), 2), sum(float(data[:, R .== 3]), 2), sum(float(data[:, R .== 4]), 2), sum(float(data[:, R .== 5]), 2))' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε # k = 6 R = [1; 2; 3; 4; 5; 6] @@ -250,19 +239,19 @@ function test_local_mode() v = [1; 1; 1; 1; 1; 1] n1s = float(data)' - s = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) + s = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(s.v, s.n1s, s.C, s.cl, s.k, s.logpC, priorC) @test s.C == C - @test_approx_eq_eps s.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps s.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps s.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps s.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε - t = AminoAcidState(data, R, priorR, priorC, settings) - computelocalmode!(t, priorC) + t = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) + Kpax3.computelocalmode!(t, priorC) @test t.C == C - @test_approx_eq_eps t.logpC[1] logpriorC(C, cl, k, priorC) ε - @test_approx_eq_eps t.logpC[2] logcondpostC(C, cl, k, v, n1s, priorC) ε + @test_approx_eq_eps t.logpC[1] Kpax3.logpriorC(C, cl, k, priorC) ε + @test_approx_eq_eps t.logpC[2] Kpax3.logcondpostC(C, cl, k, v, n1s, priorC) ε nothing end diff --git a/test/optimizer/mutation.jl b/test/optimizer/mutation.jl index ae346bd..291cc8d 100644 --- a/test/optimizer/mutation.jl +++ b/test/optimizer/mutation.jl @@ -28,14 +28,13 @@ function test_mutation() R = [1; 1; 1] v = [3; 0; 0] - o = KOffspring(copy(R), copy(v)) + o = Kpax3.KOffspring(copy(R), copy(v)) mrate = 1 / 5 N = 1000000 - pr = [64 / 125; 16 / 125; 16 / 125; 2 / 125; 2 / 125; 16 / 125; 2 / 125; - 2 / 125; 2 / 125; 1 / 500; 1 / 500; 2 / 125; 1 / 500; 1 / 500] + pr = [64 / 125; 16 / 125; 16 / 125; 2 / 125; 2 / 125; 16 / 125; 2 / 125; 2 / 125; 2 / 125; 1 / 500; 1 / 500; 2 / 125; 1 / 500; 1 / 500] tmp = zeros(Float64, length(pr)) @@ -43,7 +42,7 @@ function test_mutation() copy!(o.R, R) copy!(o.v, v) - mutation!(o, mrate) + Kpax3.mutation!(o, mrate) if o.R == [1; 1; 1] @test o.v == [3; 0; 0] diff --git a/test/optimizer/selection.jl b/test/optimizer/selection.jl index 2a3ab4f..aa6da91 100644 --- a/test/optimizer/selection.jl +++ b/test/optimizer/selection.jl @@ -4,7 +4,7 @@ function test_selection() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) data = UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -27,14 +27,14 @@ function test_selection() (m, n) = size(data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = [AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings); - AminoAcidState(data, [1; 2; 3; 4; 5; 6], priorR, priorC, settings); - AminoAcidState(data, [1; 1; 2; 2; 3; 3], priorR, priorC, settings); - AminoAcidState(data, [1; 1; 1; 1; 2; 2], priorR, priorC, settings); - AminoAcidState(data, [1; 2; 3; 1; 2; 3], priorR, priorC, settings)] + state = [Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings); + Kpax3.AminoAcidState(data, [1; 2; 3; 4; 5; 6], priorR, priorC, settings); + Kpax3.AminoAcidState(data, [1; 1; 2; 2; 3; 3], priorR, priorC, settings); + Kpax3.AminoAcidState(data, [1; 1; 1; 1; 2; 2], priorR, priorC, settings); + Kpax3.AminoAcidState(data, [1; 2; 3; 1; 2; 3], priorR, priorC, settings)] popsize = 5 @@ -79,7 +79,7 @@ function test_selection() i2 = 0 for i in 1:N - (i1, i2) = selection(logpp) + (i1, i2) = Kpax3.selection(logpp) tmp[i1] += 1 tmp[i2] += 1 diff --git a/test/runtests.jl b/test/runtests.jl index d48b8fe..b3c781c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,48 +1,54 @@ # This file is part of Kpax3. License is MIT. -importall Base.Test; +importall Base.Test +import Kpax3 -cd(joinpath(Pkg.dir("Kpax3"), "test")); -include(realpath(joinpath("..", "src", "boot.jl"))); +cd(dirname(@__FILE__)) -ε = 1.0e-13; -srand(1427371200); +ε = 1.0e-13 +srand(1427371200) -tests = ["data_processing/data_processing"; - "distances/simovici_jaroszewicz"; - "distances/jaccard"; - "misc/basic_functions"; - "misc/partition_functions"; - "types/settings"; - "types/data"; - "types/prior_col"; - "types/prior_row"; - "types/state"; - "types/state_list"; - "types/support"; - "model/likelihoods"; - "model/partition_cols"; - "model/partition_rows"; - "model/loss_binder"; - "optimizer/local_mode"; - "optimizer/selection"; - "optimizer/crossover"; - "optimizer/mutation"; - "mcmc/partition_ratios"; - "mcmc/log_likelihoods"; - "mcmc/weight"; - "mcmc/merge"; - "mcmc/split"; - "mcmc/gibbs"; - "mcmc/biased_random_walk"; - "mcmc/posterior"; - "mcmc/diagnostics"; - "estimate/write" -]; +function runtests() + tests = ["data_processing/data_processing"; + "distances/simovici_jaroszewicz"; + "distances/jaccard"; + "misc/basic_functions"; + "misc/partition_functions"; + "types/settings"; + "types/data"; + "types/prior_col"; + "types/prior_row"; + "types/state"; + "types/state_list"; + "types/support"; + "model/likelihoods"; + "model/partition_cols"; + "model/partition_rows"; + "model/loss_binder" + "optimizer/local_mode"; + "optimizer/selection"; + "optimizer/crossover"; + "optimizer/mutation"; + "mcmc/partition_ratios"; + "mcmc/log_likelihoods"; + "mcmc/weight"; + "mcmc/merge"; + "mcmc/split"; + "mcmc/gibbs"; + "mcmc/biased_random_walk"; + "mcmc/posterior"; + "mcmc/diagnostics"; + "estimate/write" + ] -for t in tests - f = string(t, ".jl"); - @printf("Going through tests in '%s'... ", f); - include(f); - @printf("PASSED!\n"); + for t in tests + f = string(t, ".jl") + @printf("Going through tests in '%s'... ", f) + include(f) + @printf("PASSED!\n") + end + + nothing end + +runtests() diff --git a/test/types/data.jl b/test/types/data.jl index d2044e8..7268f3d 100644 --- a/test/types/data.jl +++ b/test/types/data.jl @@ -3,21 +3,21 @@ function test_data_exceptions() f = "../build/test" - @test_throws KFASTAError NucleotideData(KSettings("data/empty_file.fasta",f)) - @test_throws KFASTAError NucleotideData(KSettings("data/no_1st_seq.fasta",f)) - @test_throws KFASTAError NucleotideData(KSettings("data/no_id_char.fasta",f)) - @test_throws KFASTAError NucleotideData(KSettings("data/no_nth_seq.fasta",f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/empty_file.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/no_1st_seq.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/no_id_char.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/no_nth_seq.fasta", f)) - @test_throws KFASTAError NucleotideData(KSettings("data/utf8_id.fasta", f)) - @test_throws KFASTAError NucleotideData(KSettings("data/utf8_seq.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/utf8_id.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.NucleotideData(Kpax3.KSettings("data/utf8_seq.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/empty_file.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/no_1st_seq.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/no_id_char.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/no_nth_seq.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/empty_file.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/no_1st_seq.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/no_id_char.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/no_nth_seq.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/utf8_id.fasta", f)) - @test_throws KFASTAError AminoAcidData(KSettings("data/utf8_seq.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/utf8_id.fasta", f)) + @test_throws Kpax3.KFASTAError Kpax3.AminoAcidData(Kpax3.KSettings("data/utf8_seq.fasta", f)) nothing end @@ -27,7 +27,7 @@ test_data_exceptions() function test_data_blanks() f = "../build/test" - nt = NucleotideData(KSettings("data/blanks.fasta", f)) + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/blanks.fasta", f)) @test nt.data == UInt8[0 1; 1 0; 1 0; @@ -41,13 +41,11 @@ function test_data_blanks() 0 1; 1 0] @test nt.id == String["ID1", "ID5"] - @test nt.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] - @test nt.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', - 'g'] + @test nt.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] + @test nt.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g'] @test nt.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] - nt = NucleotideData(KSettings("data/blanks.fasta", f, l=1)) + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/blanks.fasta", f, l=1)) @test nt.data == UInt8[0 1; 1 0; 1 0; @@ -61,13 +59,11 @@ function test_data_blanks() 0 1; 1 0] @test nt.id == String["ID1", "ID5"] - @test nt.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] - @test nt.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', - 'g'] + @test nt.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] + @test nt.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g'] @test nt.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] - aa = AminoAcidData(KSettings("data/blanks.fasta", f)) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/blanks.fasta", f)) @test aa.data == UInt8[0 1; 1 0; 1 0; @@ -81,13 +77,11 @@ function test_data_blanks() 0 1; 1 0] @test aa.id == String["ID1", "ID5"] - @test aa.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] - @test aa.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', - 'g'] + @test aa.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] + @test aa.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g'] @test aa.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] - aa = AminoAcidData(KSettings("data/blanks.fasta", f, l=1)) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/blanks.fasta", f, l=1)) @test aa.data == UInt8[0 1; 1 0; 1 0; @@ -101,10 +95,8 @@ function test_data_blanks() 0 1; 1 0] @test aa.id == String["ID1", "ID5"] - @test aa.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', - 'a'] - @test aa.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', - 'g'] + @test aa.ref == UInt8['a', 't', 'g', '.', '.', '.', 'g', '.', '.', 'a', '.', 'a'] + @test aa.val == UInt8['a', 'g', 'a', 'g', 'c', 'g', 'c', 'g', 'a', 'g', 'c', 'g'] @test aa.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6] nothing @@ -115,7 +107,7 @@ test_data_blanks() function test_data_proper_dna_file() f = "../build/test" - nt = NucleotideData(KSettings("data/proper_nt.fasta", f)) + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/proper_nt.fasta", f)) @test nt.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -135,13 +127,11 @@ function test_data_proper_dna_file() 0 1 0 0 1 0; 1 0 1 1 0 1] @test nt.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - 'a'] - @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', - 'a', 'g', 't', 'a', 't', 'c', 'g'] + @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a'] + @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g'] @test nt.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] - nt = NucleotideData(KSettings("data/proper_nt.fasta", f, l=1)) + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/proper_nt.fasta", f, l=1)) @test nt.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -161,14 +151,12 @@ function test_data_proper_dna_file() 0 1 0 0 1 0; 1 0 1 1 0 1] @test nt.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - 'a'] - @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', - 'a', 'g', 't', 'a', 't', 'c', 'g'] + @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a'] + @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g'] @test nt.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] # consider all characters - nt = NucleotideData(KSettings("data/proper_nt.fasta", f, + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/proper_nt.fasta", f, miss=zeros(UInt8, 1))) @test nt.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; @@ -192,12 +180,9 @@ function test_data_proper_dna_file() 1 0 1 1 1 1; 0 1 0 0 0 0] @test nt.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - '.'] - @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c', - 'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x'] - @test nt.key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, - 9] + @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', '.'] + @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'x', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g', 'a', 'x'] + @test nt.key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9] nothing end @@ -207,7 +192,7 @@ test_data_proper_dna_file() function test_data_proper_protein_file() f = "../build/test" - aa = AminoAcidData(KSettings("data/proper_aa.fasta", f)) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/proper_aa.fasta", f)) @test aa.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -227,13 +212,11 @@ function test_data_proper_protein_file() 1 1 0 1 0 0; 0 0 1 0 1 1] @test aa.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - 'f'] - @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', - 'e', 'l', 'm', 'c', 'y', 'a', 't'] + @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f'] + @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't'] @test aa.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] - aa = AminoAcidData(KSettings("data/proper_aa.fasta", f, l=1)) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/proper_aa.fasta", f, l=1)) @test aa.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -253,14 +236,12 @@ function test_data_proper_protein_file() 1 1 0 1 0 0; 0 0 1 0 1 1] @test aa.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - 'f'] - @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', - 'e', 'l', 'm', 'c', 'y', 'a', 't'] + @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f'] + @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't'] @test aa.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] # consider all characters - aa = AminoAcidData(KSettings("data/proper_aa.fasta", f, miss=zeros(UInt8,1))) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/proper_aa.fasta", f, miss=zeros(UInt8,1))) @test aa.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -283,12 +264,9 @@ function test_data_proper_protein_file() 1 0 1 1 1 1; 0 1 0 0 0 0] @test aa.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - '.'] - @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l', - 't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x'] - @test aa.key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, - 9] + @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', '.'] + @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'x', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't', 'f', 'x'] + @test aa.key == [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9] nothing end @@ -298,17 +276,17 @@ test_data_proper_protein_file() function test_data_input_output() f = "../build/test" - nt = NucleotideData(KSettings("data/proper_nt.fasta", f)) + nt = Kpax3.NucleotideData(Kpax3.KSettings("data/proper_nt.fasta", f)) # TODO: Test exception when saving to a location without writing permissions - save("../build/nt.jld", nt) + Kpax3.save("../build/nt.jld", nt) @test isfile("../build/nt.jld") - @test_throws SystemError loadnt("../build/non_existent.file") + @test_throws SystemError Kpax3.loadnt("../build/non_existent.file") - nt = loadnt("../build/nt.jld") + nt = Kpax3.loadnt("../build/nt.jld") - @test isa(nt, NucleotideData) + @test isa(nt, Kpax3.NucleotideData) @test nt.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -328,22 +306,20 @@ function test_data_input_output() 0 1 0 0 1 0; 1 0 1 1 0 1] @test nt.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', - 'a'] - @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', - 'a', 'g', 't', 'a', 't', 'c', 'g'] + @test nt.ref == UInt8['a', '.', 'g', '.', '.', '.', 'g', '.', '.', '.', '.', 'a'] + @test nt.val == UInt8['c', 't', 'a', 'g', 'a', 'g', 'c', 'g', 'a', 'c', 'g', 'a', 'g', 't', 'a', 't', 'c', 'g'] @test nt.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] - aa = AminoAcidData(KSettings("data/proper_aa.fasta", f)) + aa = Kpax3.AminoAcidData(Kpax3.KSettings("data/proper_aa.fasta", f)) # TODO: Test exception when saving to a location without writing permissions - save("../build/aa.jld", aa) + Kpax3.save("../build/aa.jld", aa) @test isfile("../build/aa.jld") - @test_throws SystemError loadaa("../build/non_existent.file") + @test_throws SystemError Kpax3.loadaa("../build/non_existent.file") - aa = loadaa("../build/aa.jld") - @test isa(aa, AminoAcidData) + aa = Kpax3.loadaa("../build/aa.jld") + @test isa(aa, Kpax3.AminoAcidData) @test aa.data == UInt8[0 0 0 0 0 1; 1 1 1 1 1 0; 0 0 1 0 1 1; @@ -363,10 +339,8 @@ function test_data_input_output() 1 1 0 1 0 0; 0 0 1 0 1 1] @test aa.id == String["ID1", "ID2", "ID3", "ID4", "ID5", "ID6"] - @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', - 'f'] - @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', - 'e', 'l', 'm', 'c', 'y', 'a', 't'] + @test aa.ref == UInt8['m', '.', 'a', '.', '.', '.', 'v', '.', '.', '.', '.', 'f'] + @test aa.val == UInt8['e', 'k', 'i', 'k', 'l', 'v', 'l', 'v', 'c', 'l', 't', 'e', 'l', 'm', 'c', 'y', 'a', 't'] @test aa.key == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8] nothing diff --git a/test/types/prior_col.jl b/test/types/prior_col.jl index 47561e7..1b4d472 100644 --- a/test/types/prior_col.jl +++ b/test/types/prior_col.jl @@ -25,13 +25,13 @@ function test_prior_col_exceptions() γ = [0.6; 0.35; 0.05] r = log(0.001) / log(0.95) - @test_throws KInputError AminoAcidPriorCol(data, [1.0; 1.0; 1.0; 1.0], r) + @test_throws Kpax3.KInputError Kpax3.AminoAcidPriorCol(data, [1.0; 1.0; 1.0; 1.0], r) - @test_throws KDomainError AminoAcidPriorCol(data, [-1.0; 1.0; 1.0], r) - @test_throws KDomainError AminoAcidPriorCol(data, [1.0; -1.0; 1.0], r) - @test_throws KDomainError AminoAcidPriorCol(data, [1.0; 1.0; -1.0], r) - @test_throws KDomainError AminoAcidPriorCol(data, γ, 0.0) - @test_throws KDomainError AminoAcidPriorCol(data, γ, -1.0) + @test_throws Kpax3.KDomainError Kpax3.AminoAcidPriorCol(data, [-1.0; 1.0; 1.0], r) + @test_throws Kpax3.KDomainError Kpax3.AminoAcidPriorCol(data, [1.0; -1.0; 1.0], r) + @test_throws Kpax3.KDomainError Kpax3.AminoAcidPriorCol(data, [1.0; 1.0; -1.0], r) + @test_throws Kpax3.KDomainError Kpax3.AminoAcidPriorCol(data, γ, 0.0) + @test_throws Kpax3.KDomainError Kpax3.AminoAcidPriorCol(data, γ, -1.0) nothing end @@ -63,7 +63,7 @@ function test_prior_col_constructor() γ = [0.6; 0.35; 0.05] r = log(0.001) / log(0.95) - priorC = AminoAcidPriorCol(data, γ, r) + priorC = Kpax3.AminoAcidPriorCol(data, γ, r) logγ = [log(γ[1]); log(γ[2]); log(γ[3])] logω = Vector{Float64}[[log(k - 1) - log(k); -log(k)] for k in 1:n] diff --git a/test/types/prior_row.jl b/test/types/prior_row.jl index 4018298..9f0e5be 100644 --- a/test/types/prior_row.jl +++ b/test/types/prior_row.jl @@ -1,23 +1,23 @@ # This file is part of Kpax3. License is MIT. function test_prior_row_exceptions() - @test_throws KDomainError EwensPitman(1.0, 0.0) - @test_throws KDomainError EwensPitman(2.0, 0.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(1.0, 0.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(2.0, 0.0) - @test_throws KDomainError EwensPitman(0.5, -1.0) - @test_throws KDomainError EwensPitman(0.5, -0.5) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.5, -1.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.5, -0.5) - @test_throws KDomainError EwensPitman(0.0, -1.0) - @test_throws KDomainError EwensPitman(0.0, 0.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.0, -1.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.0, 0.0) - @test_throws KDomainError EwensPitman(0.5, 0) - @test_throws KDomainError EwensPitman(0.0, 0) - @test_throws KDomainError EwensPitman(0.5, 1) - @test_throws KDomainError EwensPitman(0.0, 1) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.5, 0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.0, 0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.5, 1) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(0.0, 1) - @test_throws KDomainError EwensPitman(-1.0, 0) - @test_throws KDomainError EwensPitman(-1.0, -1) - @test_throws KDomainError EwensPitman(-1.0, 1.0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(-1.0, 0) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(-1.0, -1) + @test_throws Kpax3.KDomainError Kpax3.EwensPitman(-1.0, 1.0) nothing end @@ -25,21 +25,21 @@ end test_prior_row_exceptions() function test_prior_row_constructor() - priorR = EwensPitman(0.5, -0.1) - @test isa(priorR, EwensPitmanPAUT) + priorR = Kpax3.EwensPitman(0.5, -0.1) + @test isa(priorR, Kpax3.EwensPitmanPAUT) @test priorR.α == 0.5 @test priorR.θ == -0.1 - priorR = EwensPitman(0.5, 0.0) - @test isa(priorR, EwensPitmanPAZT) + priorR = Kpax3.EwensPitman(0.5, 0.0) + @test isa(priorR, Kpax3.EwensPitmanPAZT) @test priorR.α == 0.5 - priorR = EwensPitman(0, 2.0) - @test isa(priorR, EwensPitmanZAPT) + priorR = Kpax3.EwensPitman(0, 2.0) + @test isa(priorR, Kpax3.EwensPitmanZAPT) @test priorR.θ == 2.0 - priorR = EwensPitman(-2, 5) - @test isa(priorR, EwensPitmanNAPT) + priorR = Kpax3.EwensPitman(-2, 5) + @test isa(priorR, Kpax3.EwensPitmanNAPT) @test priorR.α == -2.0 @test priorR.L == 5 diff --git a/test/types/settings.jl b/test/types/settings.jl index f8bcc44..afa8a9a 100644 --- a/test/types/settings.jl +++ b/test/types/settings.jl @@ -4,29 +4,29 @@ function test_settings_exceptions() ifile = "data/proper_aa.fasta" ofile = "../build/test" - @test_throws KDomainError KSettings(ifile, ofile, miss=UInt8[63; 0]) - @test_throws KDomainError KSettings(ifile, ofile, l=-1) - @test_throws KInputError KSettings(ifile, ofile, gamma=[1.0; 0.0]) - @test_throws KDomainError KSettings(ifile, ofile, gamma=[1.0; 0.0; -1.0]) - @test_throws KDomainError KSettings(ifile, ofile, r=0.0) - @test_throws KDomainError KSettings(ifile, ofile, r=-1.0) - @test_throws KDomainError KSettings(ifile, ofile, maxclust=0) - @test_throws KDomainError KSettings(ifile, ofile, maxunit=0) - @test_throws KDomainError KSettings(ifile, ofile, verbosestep=-1) - @test_throws KDomainError KSettings(ifile, ofile, popsize=-1) - @test_throws KDomainError KSettings(ifile, ofile, popsize=0) - @test_throws KDomainError KSettings(ifile, ofile, popsize=1) - @test_throws KDomainError KSettings(ifile, ofile, maxiter=0) - @test_throws KDomainError KSettings(ifile, ofile, maxgap=-1) - @test_throws KDomainError KSettings(ifile, ofile, xrate=-1.0) - @test_throws KDomainError KSettings(ifile, ofile, xrate=2.0) - @test_throws KDomainError KSettings(ifile, ofile, mrate=-1.0) - @test_throws KDomainError KSettings(ifile, ofile, mrate=2.0) - @test_throws KDomainError KSettings(ifile, ofile, T=0) - @test_throws KDomainError KSettings(ifile, ofile, burnin=-1) - @test_throws KDomainError KSettings(ifile, ofile, tstep=-1) - @test_throws KInputError KSettings(ifile, ofile, op=[1.0; 0.0]) - @test_throws KDomainError KSettings(ifile, ofile, op=[1.0; -1.0; 0.0]) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, miss=UInt8[63; 0]) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, l=-1) + @test_throws Kpax3.KInputError Kpax3.KSettings(ifile, ofile, gamma=[1.0; 0.0]) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, gamma=[1.0; 0.0; -1.0]) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, r=0.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, r=-1.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, maxclust=0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, maxunit=0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, verbosestep=-1) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, popsize=-1) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, popsize=0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, popsize=1) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, maxiter=0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, maxgap=-1) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, xrate=-1.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, xrate=2.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, mrate=-1.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, mrate=2.0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, T=0) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, burnin=-1) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, tstep=-1) + @test_throws Kpax3.KInputError Kpax3.KSettings(ifile, ofile, op=[1.0; 0.0]) + @test_throws Kpax3.KDomainError Kpax3.KSettings(ifile, ofile, op=[1.0; -1.0; 0.0]) nothing end @@ -57,12 +57,7 @@ function test_settings_constructor() tstep = 2 op = [0.7; 0.3; 0.0] - settings = KSettings(ifile, ofile, protein=protein, miss=miss, l=l, alpha=α, - theta=θ, gamma=γ, r=r, maxclust=maxclust, - maxunit=maxunit, verbose=verbose, - verbosestep=verbosestep, popsize=popsize, - maxiter=maxiter, maxgap=maxgap, xrate=xrate, - mrate=mrate, T=T, burnin=burnin, tstep=tstep, op=op) + settings = Kpax3.KSettings(ifile, ofile, protein=protein, miss=miss, l=l, alpha=α, theta=θ, gamma=γ, r=r, maxclust=maxclust, maxunit=maxunit, verbose=verbose, verbosestep=verbosestep, popsize=popsize, maxiter=maxiter, maxgap=maxgap, xrate=xrate, mrate=mrate, T=T, burnin=burnin, tstep=tstep, op=op) @test settings.ifile == ifile @test settings.ofile == ofile @@ -86,30 +81,25 @@ function test_settings_constructor() @test isa(settings.op, StatsBase.WeightVec) @test StatsBase.values(settings.op) == op - settings = KSettings(ifile, ofile, protein=true, miss=zeros(UInt8, 0)) + settings = Kpax3.KSettings(ifile, ofile, protein=true, miss=zeros(UInt8, 0)) @test settings.protein @test settings.miss == UInt8['?', '*', '#', '-', 'b', 'j', 'x', 'z'] - settings = KSettings(ifile, ofile, protein=true, - miss=UInt8['?', '*', '#', 'b', 'j', 'x', 'z']) + settings = Kpax3.KSettings(ifile, ofile, protein=true, miss=UInt8['?', '*', '#', 'b', 'j', 'x', 'z']) @test settings.protein @test settings.miss == UInt8['?', '*', '#', 'b', 'j', 'x', 'z'] - settings = KSettings(ifile, ofile, protein=false, miss=zeros(UInt8, 0)) + settings = Kpax3.KSettings(ifile, ofile, protein=false, miss=zeros(UInt8, 0)) @test !settings.protein - @test settings.miss == UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', - 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] + @test settings.miss == UInt8['?', '*', '#', '-', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] - settings = KSettings(ifile, ofile, protein=false, - miss=UInt8['?', '*', '#', 'b', 'd', 'h', 'k', 'm', 'n', - 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z']) + settings = Kpax3.KSettings(ifile, ofile, protein=false, miss=UInt8['?', '*', '#', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z']) @test !settings.protein - @test settings.miss == UInt8['?', '*', '#', 'b', 'd', 'h', 'k', 'm', 'n', - 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] + @test settings.miss == UInt8['?', '*', '#', 'b', 'd', 'h', 'k', 'm', 'n', 'r', 's', 'v', 'w', 'x', 'y', 'j', 'z'] nothing end diff --git a/test/types/state.jl b/test/types/state.jl index 3cf4c38..1f62cae 100644 --- a/test/types/state.jl +++ b/test/types/state.jl @@ -28,7 +28,7 @@ function test_state_constructor() (m, n) = size(data) # test constructor - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) R = [13; 13; 42; 42; 76; 76] @@ -49,10 +49,10 @@ function test_state_constructor() n1s[2, :] = vec(sum(float(data[:, R .== 42]), 2)) n1s[3, :] = vec(sum(float(data[:, R .== 76]), 2)) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, R, priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, R, priorR, priorC, settings) @test state.R == [1; 1; 2; 2; 3; 3] @@ -66,45 +66,34 @@ function test_state_constructor() @test state.v == v @test state.n1s == n1s - @test state.unit == Vector{Int}[sum(state.R .== g) > 0 ? - find(state.R .== g) : - [0] for g in 1:maxclust] + @test state.unit == Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:maxclust] - @test state.logpR == logdPriorRow(n, k, v, priorR) - @test_approx_eq_eps state.logpC[1] logpriorC(state.C, state.cl, state.k, - priorC) ε - @test_approx_eq_eps state.logpC[2] logcondpostC(state.C, state.cl, - state.k, state.v, - state.n1s, priorC) ε + @test state.logpR == Kpax3.logdPriorRow(n, k, v, priorR) + @test_approx_eq_eps state.logpC[1] Kpax3.logpriorC(state.C, state.cl, state.k, priorC) ε + @test_approx_eq_eps state.logpC[2] Kpax3.logcondpostC(state.C, state.cl, state.k, state.v, state.n1s, priorC) ε loglik = zeros(Float64, 3) linearidx = Int[state.C[cl[1], b] + 4 * (b - 1) for b in 1:m] - loglik[1] = sum(logmarglik(vec(state.n1s[cl[1], :]), state.v[cl[1]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[1] = sum(Kpax3.logmarglik(vec(state.n1s[cl[1], :]), state.v[cl[1]], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[cl[2], b] + 4 * (b - 1) for b in 1:m] - loglik[2] = sum(logmarglik(vec(state.n1s[cl[2], :]), state.v[cl[2]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[2] = sum(Kpax3.logmarglik(vec(state.n1s[cl[2], :]), state.v[cl[2]], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[cl[3], b] + 4 * (b - 1) for b in 1:m] - loglik[3] = sum(logmarglik(vec(state.n1s[cl[3], :]), state.v[cl[3]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[3] = sum(Kpax3.logmarglik(vec(state.n1s[cl[3], :]), state.v[cl[3]], priorC.A[linearidx], priorC.B[linearidx])) ll = loglik[1] + loglik[2] + loglik[3] @test_approx_eq_eps state.loglik ll ε - @test_approx_eq_eps state.logpp (logdPriorRow(n, k, v, priorR) + - logpriorC(state.C, state.cl, state.k, - priorC) + ll) ε + @test_approx_eq_eps state.logpp (Kpax3.logdPriorRow(n, k, v, priorR) + Kpax3.logpriorC(state.C, state.cl, state.k, priorC) + ll) ε - settings = KSettings("data/mcmc_6.fasta", "../build/test", - maxclust=1, maxunit=1) - x = AminoAcidData(settings) - state = optimumstate(x, "data/mcmc_6.csv", settings) + settings = Kpax3.KSettings("data/mcmc_6.fasta", "../build/test", maxclust=1, maxunit=1) + x = Kpax3.AminoAcidData(settings) + state = Kpax3.optimumstate(x, "data/mcmc_6.csv", settings) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) n = 6 R = [1; 1; 2; 2; 3; 4] @@ -135,41 +124,30 @@ function test_state_constructor() @test state.v == v @test state.n1s == n1s - @test state.unit == Vector{Int}[sum(state.R .== g) > 0 ? - find(state.R .== g) : - [0] for g in 1:maxclust] + @test state.unit == Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:maxclust] - @test state.logpR == logdPriorRow(n, k, v, priorR) - @test_approx_eq_eps state.logpC[1] logpriorC(state.C, state.cl, state.k, - priorC) ε - @test_approx_eq_eps state.logpC[2] logcondpostC(state.C, state.cl, - state.k, state.v, - state.n1s, priorC) ε + @test state.logpR == Kpax3.logdPriorRow(n, k, v, priorR) + @test_approx_eq_eps state.logpC[1] Kpax3.logpriorC(state.C, state.cl, state.k, priorC) ε + @test_approx_eq_eps state.logpC[2] Kpax3.logcondpostC(state.C, state.cl, state.k, state.v, state.n1s, priorC) ε loglik = zeros(Float64, 4) linearidx = Int[state.C[cl[1], b] + 4 * (b - 1) for b in 1:m] - loglik[1] = sum(logmarglik(vec(state.n1s[cl[1], :]), state.v[cl[1]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[1] = sum(Kpax3.logmarglik(vec(state.n1s[cl[1], :]), state.v[cl[1]], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[cl[2], b] + 4 * (b - 1) for b in 1:m] - loglik[2] = sum(logmarglik(vec(state.n1s[cl[2], :]), state.v[cl[2]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[2] = sum(Kpax3.logmarglik(vec(state.n1s[cl[2], :]), state.v[cl[2]], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[cl[3], b] + 4 * (b - 1) for b in 1:m] - loglik[3] = sum(logmarglik(vec(state.n1s[cl[3], :]), state.v[cl[3]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[3] = sum(Kpax3.logmarglik(vec(state.n1s[cl[3], :]), state.v[cl[3]], priorC.A[linearidx], priorC.B[linearidx])) linearidx = Int[state.C[cl[4], b] + 4 * (b - 1) for b in 1:m] - loglik[4] = sum(logmarglik(vec(state.n1s[cl[4], :]), state.v[cl[4]], - priorC.A[linearidx], priorC.B[linearidx])) + loglik[4] = sum(Kpax3.logmarglik(vec(state.n1s[cl[4], :]), state.v[cl[4]], priorC.A[linearidx], priorC.B[linearidx])) ll = loglik[1] + loglik[2] + loglik[3] + loglik[4] @test_approx_eq_eps state.loglik ll ε - @test_approx_eq_eps state.logpp (logdPriorRow(n, k, v, priorR) + - logpriorC(state.C, state.cl, state.k, - priorC) + ll) ε + @test_approx_eq_eps state.logpp (Kpax3.logdPriorRow(n, k, v, priorR) + Kpax3.logpriorC(state.C, state.cl, state.k, priorC) + ll) ε nothing end @@ -203,12 +181,12 @@ function test_state_resizestate() # resizestate!(state, k) # k < 2 * maxclust => len = maxclust - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) len = 4 @@ -230,15 +208,14 @@ function test_state_resizestate() n1s = zeros(Float64, len, m) n1s[1, :] = copy(vec(state.n1s[1, :])) - unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] - for g in 1:len] + unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:len] logpR = state.logpR logpC = copy(state.logpC) loglik = state.loglik logpp = state.logpp - resizestate!(state, 3) + Kpax3.resizestate!(state, 3) @test state.R == R @test state.C == C @@ -255,12 +232,12 @@ function test_state_resizestate() # resizestate!(state, k) # k > 2 * maxclust => len = k - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) len = 5 @@ -282,15 +259,14 @@ function test_state_resizestate() n1s = zeros(Float64, len, m) n1s[1, :] = copy(vec(state.n1s[1, :])) - unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] - for g in 1:len] + unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:len] logpR = state.logpR logpC = copy(state.logpC) loglik = state.loglik logpp = state.logpp - resizestate!(state, 5) + Kpax3.resizestate!(state, 5) @test state.R == R @test state.C == C @@ -307,12 +283,12 @@ function test_state_resizestate() # resizestate!(state, k, settings) # k < 2 * maxclust => len = maxclust - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) len = 4 @@ -334,15 +310,14 @@ function test_state_resizestate() n1s = zeros(Float64, len, m) n1s[1, :] = copy(vec(state.n1s[1, :])) - unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] - for g in 1:len] + unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:len] logpR = state.logpR logpC = copy(state.logpC) loglik = state.loglik logpp = state.logpp - resizestate!(state, 3, settings) + Kpax3.resizestate!(state, 3, settings) @test state.R == R @test state.C == C @@ -359,12 +334,12 @@ function test_state_resizestate() # resizestate!(state, k, settings) # k > 2 * maxclust => len = k - settings = KSettings(ifile, ofile, maxclust=2, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=2, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) len = 5 @@ -386,15 +361,14 @@ function test_state_resizestate() n1s = zeros(Float64, len, m) n1s[1, :] = copy(vec(state.n1s[1, :])) - unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] - for g in 1:len] + unit = Vector{Int}[sum(state.R .== g) > 0 ? find(state.R .== g) : [0] for g in 1:len] logpR = state.logpR logpC = copy(state.logpC) loglik = state.loglik logpp = state.logpp - resizestate!(state, 5, settings) + Kpax3.resizestate!(state, 5, settings) @test state.R == R @test state.C == C @@ -439,10 +413,10 @@ function test_state_copy_basic() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [3; 3; 1; 1; 5; 5] g = sort(unique(R)) @@ -473,11 +447,8 @@ function test_state_copy_basic() loglik = -66.7559125873377894322402426041662693023681640625 logpp = logpR + logpC[1] + loglik - state1 = AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, - copy(v), copy(n1s), deepcopy(unit), logpR, - copy(logpC), loglik, logpp) - - state2 = copystate(state1) + state1 = Kpax3.AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, copy(v), copy(n1s), deepcopy(unit), logpR, copy(logpC), loglik, logpp) + state2 = Kpax3.copystate(state1) @test state2.R == R @test state2.C == C @@ -506,12 +477,10 @@ function test_state_copy_basic() state1.unit[1] = [1; 2; 3; 4] state1.unit[2] = [5; 0] state1.unit[3] = [6] - state1.logpR = logdPriorRow(n, state1.k, state1.v[1:state1.k], priorR) - state1.logpC[1] = logpriorC(state1.C, state1.cl, state1.k, priorC) - state1.logpC[2] = logcondpostC(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) - state1.loglik = loglikelihood(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) + state1.logpR = Kpax3.logdPriorRow(n, state1.k, state1.v[1:state1.k], priorR) + state1.logpC[1] = Kpax3.logpriorC(state1.C, state1.cl, state1.k, priorC) + state1.logpC[2] = Kpax3.logcondpostC(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) + state1.loglik = Kpax3.loglikelihood(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) state1.logpp = state1.logpR + state1.logpC[1] + state1.loglik @test state2.R == R @@ -557,10 +526,10 @@ function test_state_copy_with_resize() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [3; 3; 1; 1; 5; 5] g = sort(unique(R)) @@ -591,15 +560,13 @@ function test_state_copy_with_resize() loglik = -66.7559125873377894322402426041662693023681640625 logpp = logpR + logpC[1] + loglik - state1 = AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, - copy(v), copy(n1s), deepcopy(unit), logpR, - copy(logpC), loglik, logpp) + state1 = Kpax3.AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, copy(v), copy(n1s), deepcopy(unit), logpR, copy(logpC), loglik, logpp) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - state2 = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state2 = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) - copystate!(state2, state1) + Kpax3.copystate!(state2, state1) l = state1.cl[1:state1.k] @@ -634,12 +601,10 @@ function test_state_copy_with_resize() state1.unit[3] = [2; 3; 0; 0; 0; 0] state1.unit[4] = [4; 5; 0; 0; 0; 0] state1.unit[5] = [6; 0; 0; 0; 0; 0] - state1.logpR = logdPriorRow(n, state1.k, state1.v[[1; 3; 4; 5]], priorR) - state1.logpC[1] = logpriorC(state1.C, state1.cl, state1.k, priorC) - state1.logpC[2] = logcondpostC(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) - state1.loglik = loglikelihood(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) + state1.logpR = Kpax3.logdPriorRow(n, state1.k, state1.v[[1; 3; 4; 5]], priorR) + state1.logpC[1] = Kpax3.logpriorC(state1.C, state1.cl, state1.k, priorC) + state1.logpC[2] = Kpax3.logcondpostC(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) + state1.loglik = Kpax3.loglikelihood(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) state1.logpp = state1.logpR + state1.logpC[1] + state1.loglik @test state2.R != state1.R @@ -687,10 +652,10 @@ function test_state_copy_without_resize() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) R = [3; 3; 1; 1; 5; 5] g = sort(unique(R)) @@ -721,14 +686,12 @@ function test_state_copy_without_resize() loglik = -66.7559125873377894322402426041662693023681640625 logpp = logpR + logpC[1] + loglik - state1 = AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, - copy(v), copy(n1s), deepcopy(unit), logpR, - copy(logpC), loglik, logpp) + state1 = Kpax3.AminoAcidState(copy(R), copy(C), copy(emptycluster), copy(cl), k, copy(v), copy(n1s), deepcopy(unit), logpR, copy(logpC), loglik, logpp) - settings = KSettings(ifile, ofile, maxclust=6, maxunit=6) - state2 = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + settings = Kpax3.KSettings(ifile, ofile, maxclust=6, maxunit=6) + state2 = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) - copystate!(state2, state1) + Kpax3.copystate!(state2, state1) l = state1.cl[1:state1.k] @@ -763,12 +726,10 @@ function test_state_copy_without_resize() state1.unit[3] = [2; 3; 0; 0; 0; 0] state1.unit[4] = [4; 5; 0; 0; 0; 0] state1.unit[5] = [6; 0; 0; 0; 0; 0] - state1.logpR = logdPriorRow(n, state1.k, state1.v[[1; 3; 4; 5]], priorR) - state1.logpC[1] = logpriorC(state1.C, state1.cl, state1.k, priorC) - state1.logpC[2] = logcondpostC(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) - state1.loglik = loglikelihood(state1.C, state1.cl, state1.k, state1.v, - state1.n1s, priorC) + state1.logpR = Kpax3.logdPriorRow(n, state1.k, state1.v[[1; 3; 4; 5]], priorR) + state1.logpC[1] = Kpax3.logpriorC(state1.C, state1.cl, state1.k, priorC) + state1.logpC[2] = Kpax3.logcondpostC(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) + state1.loglik = Kpax3.loglikelihood(state1.C, state1.cl, state1.k, state1.v, state1.n1s, priorC) state1.logpp = state1.logpR + state1.logpC[1] + state1.loglik @test state2.R != state1.R @@ -816,15 +777,15 @@ function test_state_update_with_resize() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=1, maxunit=1) + settings = Kpax3.KSettings(ifile, ofile, maxclust=1, maxunit=1) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state1 = AminoAcidState(data, [1; 1; 1; 1; 2; 3], priorR, priorC, settings) - state2 = AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + state1 = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 2; 3], priorR, priorC, settings) + state2 = Kpax3.AminoAcidState(data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) - updatestate!(state2, data, [1; 1; 1; 1; 2; 3], priorR, priorC, settings) + Kpax3.updatestate!(state2, data, [1; 1; 1; 1; 2; 3], priorR, priorC, settings) @test state2.R == state1.R @test state2.C == state1.C @@ -871,15 +832,15 @@ function test_state_update_without_resize() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=6, maxunit=6) + settings = Kpax3.KSettings(ifile, ofile, maxclust=6, maxunit=6) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) - state1 = AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) - state2 = AminoAcidState(data, [1; 1; 2; 2; 3; 3], priorR, priorC, settings) + state1 = Kpax3.AminoAcidState(data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) + state2 = Kpax3.AminoAcidState(data, [1; 1; 2; 2; 3; 3], priorR, priorC, settings) - updatestate!(state2, data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) + Kpax3.updatestate!(state2, data, [1; 1; 1; 2; 2; 2], priorR, priorC, settings) l = state1.cl[1:state1.k] @@ -928,22 +889,22 @@ function test_state_initializestate() (m, n) = size(data) - settings = KSettings(ifile, ofile, maxclust=6, maxunit=6) + settings = Kpax3.KSettings(ifile, ofile, maxclust=6, maxunit=6) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(data, settings.γ, settings.r) D = zeros(Float64, n, n) for j in 1:(n - 1), i in (j + 1):n D[i, j] = D[j, i] = sum(data[:, j] .!= data[:, i]) / m end - s = initializestate(data, D, 1:6, priorR, priorC, settings) + s = Kpax3.initializestate(data, D, 1:6, priorR, priorC, settings) @test isa(s.R, Vector{Int}) @test all(s.R .> 0) - t = AminoAcidState(data, s.R, priorR, priorC, settings) + t = Kpax3.AminoAcidState(data, s.R, priorR, priorC, settings) l = t.cl[1:t.k] diff --git a/test/types/state_list.jl b/test/types/state_list.jl index 02fb6e2..15d0bfc 100644 --- a/test/types/state_list.jl +++ b/test/types/state_list.jl @@ -4,19 +4,18 @@ function test_state_list_constructor() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) (m, n) = size(x.data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - slist = AminoAcidStateList(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, - settings) + slist = Kpax3.AminoAcidStateList(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, settings) - @test isa(slist.state, Vector{AminoAcidState}) + @test isa(slist.state, Vector{Kpax3.AminoAcidState}) @test isa(slist.logpp, Vector{Float64}) @test isa(slist.rank, Vector{Int}) @test all(slist.logpp .< 0.0) @@ -28,7 +27,7 @@ function test_state_list_constructor() @test slist.state[1].R == [3; 3; 3; 1; 1; 2] for i in 1:settings.popsize - t = AminoAcidState(x.data, slist.state[i].R, priorR, priorC, settings) + t = Kpax3.AminoAcidState(x.data, slist.state[i].R, priorR, priorC, settings) l = t.cl[1:t.k] @@ -50,10 +49,10 @@ function test_state_list_constructor() @test_approx_eq_eps slist.logpp[i] slist.state[i].logpp ε end - state = AminoAcidState(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, settings) - slist = AminoAcidStateList(settings.popsize, state) + state = Kpax3.AminoAcidState(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, settings) + slist = Kpax3.AminoAcidStateList(settings.popsize, state) - @test isa(slist.state, Vector{AminoAcidState}) + @test isa(slist.state, Vector{Kpax3.AminoAcidState}) @test isa(slist.logpp, Vector{Float64}) @test isa(slist.rank, Vector{Int}) @test all(slist.logpp .< 0.0) @@ -91,19 +90,19 @@ function test_state_list_copy_basic() ifile = "data/proper_aa.fasta" ofile = "../build/test" - settings = KSettings(ifile, ofile) + settings = Kpax3.KSettings(ifile, ofile) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) (m, n) = size(x.data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - s1 = AminoAcidStateList(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, settings) - s2 = AminoAcidStateList(x.data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) + s1 = Kpax3.AminoAcidStateList(x.data, [3; 3; 3; 1; 1; 2], priorR, priorC, settings) + s2 = Kpax3.AminoAcidStateList(x.data, [1; 1; 1; 1; 1; 1], priorR, priorC, settings) - copystatelist!(s2, s1, settings.popsize) + Kpax3.copystatelist!(s2, s1, settings.popsize) for i in 1:settings.popsize j = s1.rank[i] diff --git a/test/types/support.jl b/test/types/support.jl index 19a925d..af7cf5b 100644 --- a/test/types/support.jl +++ b/test/types/support.jl @@ -5,33 +5,29 @@ function test_support_mcmc_constructor() ofile = "../build/test" maxclust = 1 - settings = KSettings(ifile, ofile, maxclust=maxclust) + settings = Kpax3.KSettings(ifile, ofile, maxclust=maxclust) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) (m, n) = size(x.data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - state = AminoAcidState(x.data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) + state = Kpax3.AminoAcidState(x.data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) g = 0 lp = zeros(Float64, 4, 3, m) for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end - support = MCMCSupport(state, priorC) + support = Kpax3.MCMCSupport(state, priorC) @test support.m == m @test support.n == n @@ -44,7 +40,7 @@ function test_support_mcmc_constructor() @test support.vi == 0 @test support.ni == zeros(Float64, m) @test support.ui == zeros(Int, n) - @test isa(support.wi, KWeight) + @test isa(support.wi, Kpax3.KWeight) @test support.wi.c == zeros(Float64, m) @test support.wi.w == zeros(Float64, 4, m) @test support.wi.z == zeros(Float64, 4, m) @@ -53,7 +49,7 @@ function test_support_mcmc_constructor() @test support.vj == 0 @test support.nj == zeros(Float64, m) @test support.uj == zeros(Int, n) - @test isa(support.wj, KWeight) + @test isa(support.wj, Kpax3.KWeight) @test support.wj.c == zeros(Float64, m) @test support.wj.w == zeros(Float64, 4, m) @test support.wj.z == zeros(Float64, 4, m) @@ -78,8 +74,7 @@ function test_support_mcmc_constructor() tmp[1] += lp[1, g, b] tmp[2] += lp[2, g, b] - tmp[3] += log(exp(priorC.logω[state.k][1] + lp[3, g, b]) + - exp(priorC.logω[state.k][2] + lp[4, g, b])) + tmp[3] += log(exp(priorC.logω[state.k][1] + lp[3, g, b]) + exp(priorC.logω[state.k][2] + lp[4, g, b])) end logmlik += log(exp(tmp[1]) + exp(tmp[2]) + exp(tmp[3])) @@ -99,56 +94,48 @@ function test_support_mcmc_resize() ofile = "../build/test" maxclust = 1 - settings = KSettings(ifile, ofile, maxclust=maxclust) + settings = Kpax3.KSettings(ifile, ofile, maxclust=maxclust) - x = AminoAcidData(settings) + x = Kpax3.AminoAcidData(settings) (m, n) = size(x.data) - priorR = EwensPitman(settings.α, settings.θ) - priorC = AminoAcidPriorCol(x.data, settings.γ, settings.r) + priorR = Kpax3.EwensPitman(settings.α, settings.θ) + priorC = Kpax3.AminoAcidPriorCol(x.data, settings.γ, settings.r) - state = AminoAcidState(x.data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) + state = Kpax3.AminoAcidState(x.data, [1; 1; 1; 2; 2; 3], priorR, priorC, settings) g = 0 lp = zeros(Float64, 4, 3, m) for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end - support = MCMCSupport(state, priorC) + support = Kpax3.MCMCSupport(state, priorC) # do nothing - resizesupport!(support, 3) + Kpax3.resizesupport!(support, 3) @test support.lp == lp @test support.lq == zeros(Float64, 4, 3, m) @test support.lr == zeros(Float64, 3, 3, m) - resizesupport!(support, 6) + Kpax3.resizesupport!(support, 6) g = 0 lp = zeros(Float64, 4, 6, m) for b in 1:m, l in 1:state.k g = state.cl[l] - lp[1, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], - priorC.B[1, b]) - lp[2, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], - priorC.B[2, b]) - lp[3, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], - priorC.B[3, b]) - lp[4, g, b] = logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], - priorC.B[4, b]) + lp[1, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[1, b], priorC.B[1, b]) + lp[2, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[2, b], priorC.B[2, b]) + lp[3, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[3, b], priorC.B[3, b]) + lp[4, g, b] = Kpax3.logmarglik(state.n1s[g, b], state.v[g], priorC.A[4, b], priorC.B[4, b]) end @test support.lp == lp @@ -164,16 +151,16 @@ function test_support_ga_constructor() m = 18 n = 6 - support = GASupport(m, n) + support = Kpax3.GASupport(m, n) @test support.m == m @test support.n == n - @test isa(support.oi, KOffspring) + @test isa(support.oi, Kpax3.KOffspring) @test support.oi.R == zeros(Int, n) @test support.oi.v == zeros(Int, n) - @test isa(support.oj, KOffspring) + @test isa(support.oj, Kpax3.KOffspring) @test support.oj.R == zeros(Int, n) @test support.oj.v == zeros(Int, n)