[med-svn] [libbpp-phyl] 01/01: Some tests redesign.

Julien Dutheil jdutheil-guest at moszumanska.debian.org
Sat Jul 15 14:23:08 UTC 2017


This is an automated email from the git hooks/post-receive script.

jdutheil-guest pushed a commit to branch master
in repository libbpp-phyl.

commit b8320086850a8cb7148fdf3b3efac6d77ace27b2
Author: Julien Y. Dutheil <dutheil at evolbio.mpg.de>
Date:   Sat Jul 15 16:13:47 2017 +0200

    Some tests redesign.
    
    Should hopefully make test_mapping more stable, and have
    test_likelihood_clock pass on mips architecture?
---
 debian/patches/more_verbose_clock_test.patch |  22 -----
 debian/patches/series                        |   3 +-
 debian/patches/test_likelihood_clock.patch   |  56 ++++++++++++
 debian/patches/test_mapping.patch            | 130 +++++++++++++++++++++++++++
 4 files changed, 188 insertions(+), 23 deletions(-)

diff --git a/debian/patches/more_verbose_clock_test.patch b/debian/patches/more_verbose_clock_test.patch
deleted file mode 100644
index 1f6f796..0000000
--- a/debian/patches/more_verbose_clock_test.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-diff --git a/test/test_likelihood_clock.cpp b/test/test_likelihood_clock.cpp
-index fa70e89..fa5a005 100644
---- a/test/test_likelihood_clock.cpp
-+++ b/test/test_likelihood_clock.cpp
-@@ -70,7 +70,7 @@ void fitModelH(SubstitutionModel* model, DiscreteDistribution* rdist, const Tree
-   ApplicationTools::displayResult("* likelihood after full optimization", tl.getValue());
-   tl.getParameters().printParameters(cout);
-   if (abs(tl.getValue() - finalValue) > 0.001)
--    throw Exception("Incorrect final value.");
-+    throw Exception("Incorrect final value:" + TextTools::toString(tl.getValue()) + "<>" + TextTools::toString(finalValue));
- }
- 
- void fitModelHClock(SubstitutionModel* model, DiscreteDistribution* rdist, const Tree& tree, const SiteContainer& sites,
-@@ -92,7 +92,7 @@ void fitModelHClock(SubstitutionModel* model, DiscreteDistribution* rdist, const
-   ApplicationTools::displayResult("* likelihood after full optimization", tl.getValue());
-   tl.getParameters().printParameters(cout);
-   if (abs(tl.getValue() - finalValue) > 0.001)
--    throw Exception("Incorrect final value.");
-+    throw Exception("Incorrect final value:" + TextTools::toString(tl.getValue()) + "<>" + TextTools::toString(finalValue));
- }
- 
- int main() {
diff --git a/debian/patches/series b/debian/patches/series
index b0c2c8c..4c27f7d 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,4 +2,5 @@ relax_test_timeout.patch
 0001-Decreased-threshold-for-application-to-a-broader-ran.patch
 0002-Fixed-unit-tests-compilation-on-some-platforms.patch
 remove_deprecated_warnings.patch
-more_verbose_clock_test.patch
+test_likelihood_clock.patch
+test_mapping.patch
diff --git a/debian/patches/test_likelihood_clock.patch b/debian/patches/test_likelihood_clock.patch
new file mode 100644
index 0000000..8d3ba01
--- /dev/null
+++ b/debian/patches/test_likelihood_clock.patch
@@ -0,0 +1,56 @@
+--- a/test/test_likelihood_clock.cpp
++++ b/test/test_likelihood_clock.cpp
+@@ -41,7 +41,7 @@ knowledge of the CeCILL license and that
+ #include <Bpp/Seq/Alphabet/AlphabetTools.h>
+ #include <Bpp/Phyl/TreeTemplate.h>
+ #include <Bpp/Phyl/Model/Nucleotide/T92.h>
+-#include <Bpp/Phyl/Model/RateDistribution/GammaDiscreteRateDistribution.h>
++#include <Bpp/Phyl/Model/RateDistribution/ConstantRateDistribution.h>
+ #include <Bpp/Phyl/Simulation/HomogeneousSequenceSimulator.h>
+ #include <Bpp/Phyl/Likelihood/RHomogeneousTreeLikelihood.h>
+ #include <Bpp/Phyl/Likelihood/RHomogeneousClockTreeLikelihood.h>
+@@ -82,7 +82,7 @@ void fitModelHClock(SubstitutionModel* m
+   ApplicationTools::displayResult("Test model", model->getName());
+   cout << setprecision(20) << tl.getValue() << endl;
+   ApplicationTools::displayResult("* initial likelihood", tl.getValue());
+-  if (abs(tl.getValue() - initialValue) > 0.001)
++  if (abs(tl.getValue() - initialValue) > 0.0001)
+     throw Exception("Incorrect initial value.");
+   unique_ptr<OutputStream> messenger(new StlOutputStream(new ofstream("messages.txt", ios::out)));
+   unique_ptr<OutputStream> profiler(new StlOutputStream(new ofstream("profile.txt", ios::out)));
+@@ -91,8 +91,8 @@ void fitModelHClock(SubstitutionModel* m
+   cout << setprecision(20) << tl.getValue() << endl;
+   ApplicationTools::displayResult("* likelihood after full optimization", tl.getValue());
+   tl.getParameters().printParameters(cout);
+-  if (abs(tl.getValue() - finalValue) > 0.001)
+-    throw Exception("Incorrect final value.");
++  if (abs(tl.getValue() - finalValue) > 0.0001)
++    throw Exception("Incorrect final value:" + TextTools::toString(tl.getValue()) + "<>" + TextTools::toString(finalValue));
+ }
+ 
+ int main() {
+@@ -103,7 +103,7 @@ int main() {
+ 
+   const NucleicAlphabet* alphabet = &AlphabetTools::DNA_ALPHABET;
+   SubstitutionModel* model = new T92(alphabet, 3.);
+-  DiscreteDistribution* rdist = new GammaDiscreteRateDistribution(4, 1.0);
++  DiscreteDistribution* rdist = new ConstantRateDistribution();
+ 
+   VectorSiteContainer sites(alphabet);
+   sites.addSequence(BasicSequence("A", "AAATGGCTGTGCACGTC", alphabet));
+@@ -112,13 +112,13 @@ int main() {
+   sites.addSequence(BasicSequence("D", "CAACGGGAGTGCGCCTA", alphabet));
+ 
+   try {
+-    fitModelH(model, rdist, *tree, sites, 93.017264552603336369, 71.265543199977557265);
++    fitModelH(model, rdist, *tree, sites, 94.3957, 71.2657);
+   } catch (Exception& ex) {
+     cerr << ex.what() << endl;
+     return 1;
+   }
+   try {
+-    fitModelHClock(model, rdist, *tree, sites, 92.27912072473920090943, 71.26554020984087856050);
++    fitModelHClock(model, rdist, *tree, sites, 92.3295, 71.2657);
+   } catch (Exception& ex) {
+     cerr << ex.what() << endl;
+     return 1;
diff --git a/debian/patches/test_mapping.patch b/debian/patches/test_mapping.patch
new file mode 100644
index 0000000..d3463d8
--- /dev/null
+++ b/debian/patches/test_mapping.patch
@@ -0,0 +1,130 @@
+diff --git a/test/test_mapping.cpp b/test/test_mapping.cpp
+index cb649d9..b74a24e 100644
+--- a/test/test_mapping.cpp
++++ b/test/test_mapping.cpp
+@@ -64,7 +64,8 @@ using namespace bpp;
+ using namespace std;
+ 
+ int main() {
+-  TreeTemplate<Node>* tree = TreeTemplateTools::parenthesisToTree("((A:0.001, B:0.002):0.008,C:0.01,D:0.1);");
++  try {
++  TreeTemplate<Node>* tree = TreeTemplateTools::parenthesisToTree("((A:0.001, B:0.002):0.008,C:0.01,D:0.02);");
+   vector<int> ids = tree->getNodesId();
+   ids.pop_back(); //Ignore root
+ 
+@@ -79,23 +80,12 @@ int main() {
+   TotalSubstitutionRegister* totReg = new TotalSubstitutionRegister(model);
+   ComprehensiveSubstitutionRegister* detReg = new ComprehensiveSubstitutionRegister(model);
+ 
+-
+-  cout << "test mem" << endl;
+-  ProteicAlphabet* alphabet2 = new ProteicAlphabet();
+-  ReversibleSubstitutionModel* model2 = new JTT92(alphabet2);
+-  AlphabetIndex1* ind = new GranthamAAVolumeIndex();
+-  for (size_t i = 0; i < 1000000; i++) {
+-    cout << i << endl;
+-    unique_ptr<DecompositionReward> d(new DecompositionReward(model2, ind));
+-  }
+-  cout << "done" << endl;
+-
+-  unsigned int n = 20000;
++  size_t n = 50000;
+   vector< vector<double> > realMap(n);
+   vector< vector< vector<double> > > realMapTotal(n);
+   vector< vector< vector<double> > > realMapDetailed(n);
+   VectorSiteContainer sites(tree->getLeavesNames(), alphabet);
+-  for (unsigned int i = 0; i < n; ++i) {
++  for (size_t i = 0; i < n; ++i) {
+     ApplicationTools::displayGauge(i, n - 1, '=');
+     unique_ptr<RASiteSimulationResult> result(simulator.dSimulateSite());
+     realMap[i].resize(ids.size());
+@@ -108,12 +98,10 @@ int main() {
+       result->getSubstitutionCount(ids[j], *totReg, realMapTotal[i][j]);
+       result->getSubstitutionCount(ids[j], *detReg, realMapDetailed[i][j]);
+       if (realMapTotal[i][j][0] != realMap[i][j]) {
+-        cerr << "Error, total substitution register provides wrong result." << endl;
+-        return 1;
++        throw Exception("Error, total substitution register provides wrong result.");
+       }
+       if (abs(VectorTools::sum(realMapDetailed[i][j]) - realMap[i][j]) > 0.000001) {
+-        cerr << "Error, detailed substitution register provides wrong result." << endl;
+-        return 1;
++        throw Exception("Error, detailed substitution register provides wrong result.");
+       }
+     }
+     unique_ptr<Site> site(result->getSite(*model));
+@@ -130,9 +118,10 @@ int main() {
+   drhtl.initialize();
+   cout << drhtl.getValue() << endl;
+ 
++  //Laplace transforms:
+   SubstitutionCount* sCountAna = new LaplaceSubstitutionCount(model, 10);
+   Matrix<double>* m = sCountAna->getAllNumbersOfSubstitutions(0.001, 1);
+-  cout << "Analytical total count:" << endl;
++  cout << "Analytical (Laplace) total count:" << endl;
+   MatrixTools::print(*m);
+   delete m;
+   ProbabilisticSubstitutionMapping* probMapAna = 
+@@ -237,7 +226,7 @@ int main() {
+   //Check per branch:
+   
+   //1. Total:
+-  for (unsigned int j = 0; j < ids.size(); ++j) {
++  for (size_t j = 0; j < ids.size(); ++j) {
+     double totalReal = 0;
+     double totalObs1 = 0;
+     double totalObs2 = 0;
+@@ -246,7 +235,7 @@ int main() {
+     double totalObs5 = 0;
+     double totalObs6 = 0;
+     double totalObs7 = 0;
+-    for (unsigned int i = 0; i < n; ++i) {
++    for (size_t i = 0; i < n; ++i) {
+       totalReal += realMap[i][j];
+       totalObs1 += probMapAna->getNumberOfSubstitutions(ids[j], i, 0);
+       totalObs2 += probMapTot->getNumberOfSubstitutions(ids[j], i, 0);
+@@ -258,16 +247,16 @@ int main() {
+     }
+     if (tree->isLeaf(ids[j])) cout << tree->getNodeName(ids[j]) << "\t";
+     cout << tree->getDistanceToFather(ids[j]) << "\t" << totalReal << "\t" << totalObs1 << "\t" << totalObs2 << "\t" << totalObs3 << "\t" << totalObs4 << "\t" << totalObs5 << "\t" << totalObs6 << "\t" << totalObs7 << endl;
+-    if (abs(totalReal - totalObs1) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs2) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs3) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs4) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs5) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs6) / totalReal > 0.1) return 1;
+-    if (abs(totalReal - totalObs7) / totalReal > 0.1) return 1;
++    if (abs(totalReal - totalObs1) / totalReal > 0.1) throw Exception("Laplace substitution mapping failed, observed: " + TextTools::toString(totalObs1) + ", expected " + TextTools::toString(totalReal));
++    //if (abs(totalReal - totalObs2) / totalReal > 0.1) return 1; //We do not expect the naive mapping to actually give an accurate result!
++    //if (abs(totalReal - totalObs3) / totalReal > 0.1) return 1;
++    if (abs(totalReal - totalObs4) / totalReal > 0.1) throw Exception("Uniformization (total) substitution mapping failed, observed: " + TextTools::toString(totalObs4) + ", expected " + TextTools::toString(totalReal));
++    if (abs(totalReal - totalObs5) / totalReal > 0.1) throw Exception("Uniformization (detailed) substitution mapping failed, observed: " + TextTools::toString(totalObs5) + ", expected " + TextTools::toString(totalReal));
++    if (abs(totalReal - totalObs6) / totalReal > 0.1) throw Exception("Decomposition (total) substitution mapping failed, observed: " + TextTools::toString(totalObs6) + ", expected " + TextTools::toString(totalReal));
++    if (abs(totalReal - totalObs7) / totalReal > 0.1) throw Exception("Decomposition (detailed) substitution mapping failed, observed: " + TextTools::toString(totalObs7) + ", expected " + TextTools::toString(totalReal));
+   }
+   //2. Detail:
+-  for (unsigned int j = 0; j < ids.size(); ++j) {
++  for (size_t j = 0; j < ids.size(); ++j) {
+     vector<double> real(4, 0);
+     vector<double> obs1(4, 0);
+     vector<double> obs2(4, 0);
+@@ -283,7 +272,7 @@ int main() {
+     }
+     if (tree->isLeaf(ids[j])) cout << tree->getNodeName(ids[j]) << "\t";
+     cout << tree->getDistanceToFather(ids[j]) << "\t";
+-    for (unsigned int t = 0; t < 4; ++t) {
++    for (size_t t = 0; t < 4; ++t) {
+       cout << obs1[t] << "/" << real[t] << "\t";
+       cout << obs2[t] << "/" << real[t] << "\t";
+       cout << obs3[t] << "/" << real[t] << "\t";
+@@ -306,5 +295,10 @@ int main() {
+   delete probMapUniTot;
+   delete probMapUniDet;
+   //return (abs(obs - 0.001) < 0.001 ? 0 : 1);
++  } catch (exception& e) {
++    cout << "Test failed. Reason:" << endl;
++    cout << e.what() << endl;
++    return 1;
++  }
+   return 0;
+ }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/libbpp-phyl.git



More information about the debian-med-commit mailing list