[mlpack-svn] r10286 - in mlpack/trunk/src/mlpack/methods/hmm: . distributions
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Nov 15 17:05:53 EST 2011
Author: rcurtin
Date: 2011-11-15 17:05:53 -0500 (Tue, 15 Nov 2011)
New Revision: 10286
Added:
mlpack/trunk/src/mlpack/methods/hmm/distributions/
mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.cpp
mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.hpp
Log:
Begin construction of Distribution classes so that we can generalize the HMM
class.
Added: mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.cpp (rev 0)
+++ mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.cpp 2011-11-15 22:05:53 UTC (rev 10286)
@@ -0,0 +1,30 @@
+/**
+ * @file discrete_distribution_impl.hpp
+ * @author Ryan Curtin
+ *
+ * Implementation of the discrete distribution.
+ */
+#ifndef __MLPACK_METHODS_HMM_DISTRIBUTIONS_DISCRETE_DISTRIBUTION_IMPL_HPP
+#define __MLPACK_METHODS_HMM_DISTRIBUTIONS_DISCRETE_DISTRIBUTION_IMPL_HPP
+
+// Just in case.
+#include "discrete_distribution.hpp"
+
+namespace mlpack {
+namespace distribution {
+
+// These functions are inlined because they are so simple.
+DiscreteDistribution::DiscreteDistribution(size_t numObservations)
+ : probability(numObservations)
+{ /* nothing to do */ }
+
+inline double DiscreteDistribution::Probability(size_t observation)
+{
+ // No bounds checking for speed reasons.
+ return probability(observation);
+}
+
+}; // namespace distribution
+}; // namespace mlpack
+
+#endif
Added: mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.hpp (rev 0)
+++ mlpack/trunk/src/mlpack/methods/hmm/distributions/discrete_distribution.hpp 2011-11-15 22:05:53 UTC (rev 10286)
@@ -0,0 +1,58 @@
+/**
+ * @file discrete_distribution.hpp
+ * @author Ryan Curtin
+ *
+ * Implementation of the discrete distribution, where each discrete observation
+ * has a given probability.
+ */
+#ifndef __MLPACK_METHODS_HMM_DISTRIBUTIONS_DISCRETE_DISTRIBUTION_HPP
+#define __MLPACK_METHODS_HMM_DISTRIBUTIONS_DISCRETE_DISTRIBUTION_HPP
+
+#include <mlpack/core.h>
+
+namespace mlpack {
+namespace distribution {
+
+/**
+ * A discrete distribution where the only observations are of type size_t. This
+ * is useful (for example) with discrete Hidden Markov Models, where
+ * observations are non-negative integers representing specific emissions.
+ *
+ * No bounds checking is performed for observations, so if an invalid
+ * observation is passed (i.e. observation > numObservations), a crash will
+ * probably occur.
+ */
+class DiscreteDistribution
+{
+ public:
+ /**
+ * Define the discrete distribution as having numObservations possible
+ * observations. The probability in each state will be set to (1 /
+ * numObservations).
+ *
+ * @param numObservations Number of possible observations this distribution
+ * can have.
+ */
+ DiscreteDistribution(size_t numObservations);
+
+ /**
+ * Return the probability of the given observation. If the observation is
+ * greater than the number of possible observations, then a crash will
+ * probably occur -- bounds checking is not performed.
+ *
+ * @param observation Observation to return the probability of.
+ * @return Probability of the given observation.
+ */
+ double Probability(size_t observation);
+
+ private:
+ arma::vec probability;
+};
+
+// Include inline implementation.
+#include "discrete_distribution_impl.hpp"
+
+}; // namespace distribution
+}; // namespace mlpack
+
+#endif
More information about the mlpack-svn
mailing list