From 894f4d1cd146d37587040268550a481d5dea59b0 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Fri, 11 Nov 2011 15:07:19 +0100 Subject: Added Test for mlr --- algorithm.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'algorithm.rb') diff --git a/algorithm.rb b/algorithm.rb index 6cecfca..0e4ba50 100644 --- a/algorithm.rb +++ b/algorithm.rb @@ -76,6 +76,37 @@ class AlgorithmTest < Test::Unit::TestCase assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.235749338271022, 0.000001 } end + + def test_mlr + n_prop = [ [ -2.0, -2.0 ], + [ -1.0, -1.0 ], + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 2.0, 2.0 ] ] + + q_prop = [ 1.0, 1.0 ] + + #acts = [ -2.0, + # -1.0, + # 0.0, + # 1.0, + # 2.0 ] + + acts = [ 0.0, + 0.5, + 1.0, + 1.5, + 2.0 ] + + maxcols = 2 + res1 = OpenTox::Algorithm::Neighbors::mlr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) + maxcols = 1 + res2 = OpenTox::Algorithm::Neighbors::mlr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) + assert_in_delta res1, 1.4958008960423, 10E-06 + assert_equal res1, res2 + end + + =begin def test_clustering # Parameters -- cgit v1.2.3 From adc053d9e5592039d7b53b08477b781419356750 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Fri, 11 Nov 2011 16:30:58 +0100 Subject: Added PCR test --- algorithm.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'algorithm.rb') diff --git a/algorithm.rb b/algorithm.rb index 0e4ba50..fdc311c 100644 --- a/algorithm.rb +++ b/algorithm.rb @@ -105,6 +105,38 @@ class AlgorithmTest < Test::Unit::TestCase assert_in_delta res1, 1.4958008960423, 10E-06 assert_equal res1, res2 end + + def test_pcr + n_prop = [ [ -2.0, -2.0 ], + [ -1.0, -1.0 ], + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 2.0, 2.0 ] ] + + q_prop = [ 1.0, 1.0 ] + + #acts = [ -2.0, + # -1.0, + # 0.0, + # 1.0, + # 2.0 ] + + acts = [ 0.0, + 0.5, + 1.0, + 1.5, + 2.0 ] + + maxcols = 2 + res1 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) + #puts res1 + #maxcols = 1 + #res2 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) + #puts res2 + assert_in_delta res1, 1.51255020120858, 10E-06 + #assert_equal res1, res2 + end + =begin -- cgit v1.2.3 From 5cfa964fa28e79f8aa129ddd96362bc7d47af3e1 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Mon, 14 Nov 2011 16:28:43 +0100 Subject: Integrated PCR/PLSR tests --- algorithm.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'algorithm.rb') diff --git a/algorithm.rb b/algorithm.rb index fdc311c..9f56387 100644 --- a/algorithm.rb +++ b/algorithm.rb @@ -129,12 +129,12 @@ class AlgorithmTest < Test::Unit::TestCase maxcols = 2 res1 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - #puts res1 - #maxcols = 1 - #res2 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - #puts res2 - assert_in_delta res1, 1.51255020120858, 10E-06 - #assert_equal res1, res2 + + maxcols = 1 + res2 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) + + assert_in_delta res1, 1.4958008960423, 10E-06 + assert_equal res1, res2 end -- cgit v1.2.3 From 82f8512dc5e2de822433e2dcec3b579962e6ae2a Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Thu, 9 Feb 2012 15:42:36 +0100 Subject: Fixed tests --- algorithm.rb | 115 ----------------------------------------------------------- 1 file changed, 115 deletions(-) (limited to 'algorithm.rb') diff --git a/algorithm.rb b/algorithm.rb index 9f56387..6c6ba73 100644 --- a/algorithm.rb +++ b/algorithm.rb @@ -24,121 +24,6 @@ class AlgorithmTest < Test::Unit::TestCase end end - def test_p_sum_support - params = {} - params[:compound_features_hits] = { "c:c" => 10, "c:c:c" => 5, "O:N" => 2} - params[:training_compound] = "http://localhost/compound/InChI=1S/CH2O/c1-2/h1H2" - params[:training_compound_features_hits] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} - params[:weights] = { "c:c" => 0.95, "c:c:c" => 0.96, "O:N" => 0.97, "O:O" => 0.98} - params[:features] = (params[:compound_features_hits].keys + params[:training_compound_features_hits].keys).uniq - 2.times{ - params[:mode] = "min" - assert_in_delta OpenTox::Algorithm.p_sum_support(params), 12.8762796504849, 0.00001 - params[:mode] = "max" - assert_in_delta OpenTox::Algorithm.p_sum_support(params), 18.8034091184372, 0.00001 - } - end - - def test_tanimoto - params = {} - params[:training_compound] = "http://localhost/compound/InChI=1S/CH2O/c1-2/h1H2" - weights = { "c:c" => 0.95, "c:c:c" => 0.96, "O:N" => 0.97, "O:O" => 0.98} - params[:compound_features_hits] = { "c:c" => 10, "c:c:c" => 5, "O:N" => 2} - features_a = params[:compound_features_hits].keys - params[:training_compound_features_hits] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} - features_b = params[:training_compound_features_hits].keys - 2.times{ - params[:nr_hits] = false - #test without weights - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, nil, params), 0.5, 0.000001 - - #test with weights - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, weights, params), 0.498056105472291, 0.000001 - - #test with weights and nr_hits true - params[:nr_hits] = true - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, weights, params), 0.472823526091916, 0.000001 - } - - params[:training_compound_features_hits] = {"c:c" => 2, "O:N" => 2} - features_c = params[:training_compound_features_hits].keys - - 2.times{ - params[:nr_hits] = false - #test without weights - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, nil, params), 0.666666666666667, 0.000001 - - #test with weights - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.666545393630348, 0.000001 - - #test with weights and nr_hits true - params[:nr_hits] = true - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.235749338271022, 0.000001 - } - end - - def test_mlr - n_prop = [ [ -2.0, -2.0 ], - [ -1.0, -1.0 ], - [ 0.0, 0.0 ], - [ 1.0, 1.0 ], - [ 2.0, 2.0 ] ] - - q_prop = [ 1.0, 1.0 ] - - #acts = [ -2.0, - # -1.0, - # 0.0, - # 1.0, - # 2.0 ] - - acts = [ 0.0, - 0.5, - 1.0, - 1.5, - 2.0 ] - - maxcols = 2 - res1 = OpenTox::Algorithm::Neighbors::mlr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - maxcols = 1 - res2 = OpenTox::Algorithm::Neighbors::mlr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - assert_in_delta res1, 1.4958008960423, 10E-06 - assert_equal res1, res2 - end - - def test_pcr - n_prop = [ [ -2.0, -2.0 ], - [ -1.0, -1.0 ], - [ 0.0, 0.0 ], - [ 1.0, 1.0 ], - [ 2.0, 2.0 ] ] - - q_prop = [ 1.0, 1.0 ] - - #acts = [ -2.0, - # -1.0, - # 0.0, - # 1.0, - # 2.0 ] - - acts = [ 0.0, - 0.5, - 1.0, - 1.5, - 2.0 ] - - maxcols = 2 - res1 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - - maxcols = 1 - res2 = OpenTox::Algorithm::Neighbors::pcr(:n_prop => n_prop, :q_prop => q_prop, :acts => acts, :maxcols => maxcols) - - assert_in_delta res1, 1.4958008960423, 10E-06 - assert_equal res1, res2 - end - - - =begin def test_clustering # Parameters -- cgit v1.2.3