[mlpack] 14/30: Don't use equal initial probabilities.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Dec 26 10:15:26 UTC 2016


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

bap pushed a commit to branch master
in repository mlpack.

commit 8e62052569b5be711d425dcd9f2a675911f5681d
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Dec 12 14:44:20 2016 -0500

    Don't use equal initial probabilities.
    
    That can cause training to fail sometimes.  Instead, optimization seems to
    perform better when using random intiialization.
---
 src/mlpack/methods/hmm/hmm_impl.hpp | 11 ++++++++---
 src/mlpack/tests/hmm_test.cpp       |  5 +++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp
index 8e854d2..8b98a0c 100644
--- a/src/mlpack/methods/hmm/hmm_impl.hpp
+++ b/src/mlpack/methods/hmm/hmm_impl.hpp
@@ -29,11 +29,16 @@ HMM<Distribution>::HMM(const size_t states,
                        const Distribution emissions,
                        const double tolerance) :
     emission(states, /* default distribution */ emissions),
-    transition(arma::ones<arma::mat>(states, states) / (double) states),
-    initial(arma::ones<arma::vec>(states) / (double) states),
+    transition(arma::randu<arma::mat>(states, states)),
+    initial(arma::randu<arma::vec>(states) / (double) states),
     dimensionality(emissions.Dimensionality()),
     tolerance(tolerance)
-{ /* nothing to do */ }
+{
+  // Normalize the transition probabilities and initial state probabilities.
+  initial /= arma::accu(initial);
+  for (size_t i = 0; i < transition.n_cols; ++i)
+    transition.col(i) /= arma::accu(transition.col(i));
+}
 
 /**
  * Create the Hidden Markov Model with the given transition matrix and the given
diff --git a/src/mlpack/tests/hmm_test.cpp b/src/mlpack/tests/hmm_test.cpp
index ab41e90..c9016c5 100644
--- a/src/mlpack/tests/hmm_test.cpp
+++ b/src/mlpack/tests/hmm_test.cpp
@@ -412,9 +412,10 @@ BOOST_AUTO_TEST_CASE(DiscreteHMMLabeledTrainTest)
 BOOST_AUTO_TEST_CASE(DiscreteHMMSimpleGenerateTest)
 {
   // Very simple HMM.  4 emissions with equal probability and 2 states with
-  // equal probability.  The default transition and emission matrices satisfy
-  // this property.
+  // equal probability.
   HMM<DiscreteDistribution> hmm(2, DiscreteDistribution(4));
+  hmm.Initial() = arma::ones<arma::vec>(2) / 2.0;
+  hmm.Transition() = arma::ones<arma::mat>(2, 2) / 2.0;
 
   // Now generate a really, really long sequence.
   arma::mat dataSeq;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list