[mlpack-git] mlpack-2.0.x: Fix test: the fourth Gaussian should not be part of the mixture. (102fc20)

gitdub at mlpack.org gitdub at mlpack.org
Wed Jul 20 13:30:14 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : mlpack-2.0.x
Link       : https://github.com/mlpack/mlpack/compare/e434bc4ac042534529a2a440a44d86935b4d7164...fc4195d27bb9e642356a384d1fa6fe10cbdf89a6

>---------------------------------------------------------------

commit 102fc20662aa2dd37629d27d507b5056cbcd458b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Fri Jul 1 12:05:29 2016 -0400

    Fix test: the fourth Gaussian should not be part of the mixture.


>---------------------------------------------------------------

102fc20662aa2dd37629d27d507b5056cbcd458b
 src/mlpack/tests/gmm_test.cpp | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/mlpack/tests/gmm_test.cpp b/src/mlpack/tests/gmm_test.cpp
index 7139722..356f5c9 100644
--- a/src/mlpack/tests/gmm_test.cpp
+++ b/src/mlpack/tests/gmm_test.cpp
@@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability)
   }
 
   // Now train the model.
-  GMM g(4, 3); // 3 dimensions, 4 components.
+  GMM g(3, 3); // 3 dimensions, 3 components (the fourth component is fake).
 
   g.Train(points, probabilities, 8);
 
@@ -323,53 +323,43 @@ BOOST_AUTO_TEST_CASE(GMMTrainEMMultipleGaussiansWithProbability)
 
   // The tolerances in our checks are quite large, but it is good to remember
   // that we introduced a fair amount of random noise into this whole process.
+  // We don't need to look for the fourth Gaussian since that is not supposed to
+  // be a part of this mixture.
 
-  // First Gaussian (d4).
-  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.1, 0.1);
+  // First Gaussian (d1).
+  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[0]] - 0.2, 0.1);
 
   for (size_t i = 0; i < 3; i++)
     BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Mean()[i]
-        - d4.Mean()[i]), 0.4);
-
-  for (size_t row = 0; row < 3; row++)
-    for (size_t col = 0; col < 3; col++)
-      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Covariance()(row, col)
-          - d4.Covariance()(row, col)), 0.7); // Big tolerance!  Lots of noise.
-
-  // Second Gaussian (d1).
-  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.2, 0.1);
-
-  for (size_t i = 0; i < 3; i++)
-    BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i]
         - d1.Mean()[i]), 0.4);
 
   for (size_t row = 0; row < 3; row++)
     for (size_t col = 0; col < 3; col++)
-      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Covariance()(row, col)
+      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[0]).Covariance()(row, col)
           - d1.Covariance()(row, col)), 0.7); // Big tolerance!  Lots of noise.
 
-  // Third Gaussian (d2).
-  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[2]] - 0.3, 0.1);
+  // Second Gaussian (d2).
+  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[1]] - 0.3, 0.1);
 
   for (size_t i = 0; i < 3; i++)
-    BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Mean()[i]
+    BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Mean()[i]
         - d2.Mean()[i]), 0.4);
 
   for (size_t row = 0; row < 3; row++)
     for (size_t col = 0; col < 3; col++)
-      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Covariance()(row, col)
+      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[1]).Covariance()(row, col)
           - d2.Covariance()(row, col)), 0.7); // Big tolerance!  Lots of noise.
 
-  // Fourth gaussian (d3).
-  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[3]] - 0.4, 0.1);
+  // Third Gaussian (d3).
+  BOOST_REQUIRE_SMALL(g.Weights()[sortedIndices[2]] - 0.4, 0.1);
 
   for (size_t i = 0; i < 3; ++i)
-    BOOST_REQUIRE_SMALL((g.Component(sortedIndices[3]).Mean()[i]
+    BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Mean()[i]
         - d3.Mean()[i]), 0.4);
 
   for (size_t row = 0; row < 3; ++row)
     for (size_t col = 0; col < 3; ++col)
-      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[3]).Covariance()(row, col)
+      BOOST_REQUIRE_SMALL((g.Component(sortedIndices[2]).Covariance()(row, col)
           - d3.Covariance()(row, col)), 0.7);
 }
 




More information about the mlpack-git mailing list