Class ParameterEstimator

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    HMMExponentialEstimator, HMMGaussianEstimator, HMMMultinomialEstimator, HSMMParameterEstimator

    public abstract class ParameterEstimator
    extends TypedAtomicActor

    This actor implements the Expectation-Maximization(EM) algorithm for parameter estimation in graphical stochastic models. Two types of fundamental types of Bayesian Network models: Mixture Model(MM) and Hidden Markov Model(HMM) are supported. The input is an array of observations of arbitrary length and the outputs are the parameter estimates for the chosen model.

    The output ports reflect the parameter estimates of Gaussian MM or HMM. The Mixture Model is parameterized by M states, each distributed according to a distribution specified by the emissionDistribution parameter. Currently, the actor supports Gaussian emissions. The mean is a double array output containing the mean estimates and sigma is a double array output containing standard deviation estimates of each mixture component. If the modelType is HMM, then an additional output, transitionMatrix is provided, which is an estimate of the transition matrix governing the Markovian process representing the hidden state evolution. If the modelType is MM, this port outputs a double array with the prior probability estimates of the mixture components.

    iterations is the maximum number of EM iterations until the log-likelihood P(observations | model parameters) remain within likelihoodThreshold neighborhood of the previous likelihood estimate. The default likelihood threshold is set to 1E-4 and for precise applications, may be set to a lower positive value. The actor iterates over the parameter estimates using the EM algorithm. If, at any point, the estimates become NaN, the user is notified that the algorithm did not converge and is given the option to randomize initial guesses to reiterate.

    References

    [1] Jordan, Michael I., et al. An introduction to variational methods for graphical models, Springer Netherlands, 1998.

    [2] Bilmes, Jeff A. A gentle tutorial of the EM algorithm and its application to parameter estimation for Gaussian mixture and hidden Markov models. International Computer Science Institute 4.510 (1998): 126.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Ilge Akkaya
    See Also:
    ObservationClassifier, HMMGaussianEstimator
    Pt.AcceptedRating:
    Red (ilgea)
    Pt.ProposedRating:
    Red (ilgea)
    • Field Detail

      • A0

        public Parameter A0
        The user-provided initial guess of the transition probability matrix.
      • likelihoodThreshold

        public Parameter likelihoodThreshold
        The user-provided threshold on the minimum desired improvement on likelihood per iteration.
      • maxIterations

        public Parameter maxIterations
        The user-provided maximum number of allowed iterations of the Alpha-Beta Recursion.
      • nStates

        public Parameter nStates
        Number of states of the HMM.
      • randomizeGuessVectors

        public Parameter randomizeGuessVectors
        Boolean that determines whether or not to randomize input guess vectors.
      • priorDistribution

        public Parameter priorDistribution
        The user-provided initial guess on the prior probability distribution.
      • input

        public TypedIOPort input
        The input port that provides the sample observations.
      • likelihoodOut

        public TypedIOPort likelihoodOut
        An output port of type Double that contains the likelyhood.
      • priorEstimates

        public TypedIOPort priorEstimates
        The vector estimate for the prior distribution on the set of states.
      • transitionMatrix

        public TypedIOPort transitionMatrix
        The transition matrix estimate obtained by iterating over the observation set.
      • _A0

        protected double[][] _A0
        User-defined initial guess array for the state transition matrix.
      • _likelihood

        protected double _likelihood
        The likelihood value of the observations given the current estimates L(x1,....xT | \theta_p).
      • _likelihoodThreshold

        protected double _likelihoodThreshold
        The likelihood threshold.
      • _nIterations

        protected int _nIterations
        User-defined number of iterations of the alpha-beta recursion.
      • _obsDimension

        protected int _obsDimension
        observation dimension.
      • _nStates

        protected int _nStates
        Number of hidden states in the model.
      • _observations

        protected double[][] _observations
        Observation array.
      • _priors

        protected double[] _priors
        Prior distribution on hidden states.
      • _priorIn

        protected double[] _priorIn
        The prior estimates used in the EM iterations.
      • _randomize

        protected boolean _randomize
        randomize the initial guess vectors or not.
      • _transitionMatrix

        protected double[][] _transitionMatrix
        Initial guess array for the state transition matrix for the Alpha-Beta Recursion.
      • newEstimates

        protected java.util.HashMap newEstimates
        Updated parameter sets, used during Expectation-Maximization.
      • likelihood

        protected double likelihood
        Fitted model likelihood.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        Description copied from class: NamedObj
        React to a change in an attribute. This method is called by a contained attribute when its value changes. In this base class, the method does nothing. In derived classes, this method may throw an exception, indicating that the new attribute value is invalid. It is up to the caller to restore the attribute to a valid value if an exception is thrown.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).
      • _EMParameterEstimation

        protected boolean _EMParameterEstimation()
                                          throws IllegalActionException
        Expectation-Maximization, which internally executes a gradient-descent algorithm for parameter estimation.
        Returns:
        whether parameter estimation has succeded
        Throws:
        IllegalActionException
      • emissionProbability

        protected abstract double emissionProbability​(double[] y,
                                                      int hiddenState)
                                               throws IllegalActionException
        Computes the emission probability. Implemented by the child class.
        Parameters:
        y - input observation
        hiddenState - index of hidden state
        Returns:
        P(Y=y | X=hiddenState)
        Throws:
        IllegalActionException
      • _initializeEMParameters

        protected abstract void _initializeEMParameters()
        Initialize parameters used in ExpectationMaximization here.
      • _checkForConvergence

        protected abstract boolean _checkForConvergence​(int i)
                                                 throws IllegalActionException
        Check whether the gradient-descent algorithm has converged.
        Parameters:
        i - Current iteration index
        Returns:
        boolean indicating whether algorithm has converged
        Throws:
        IllegalActionException - If there is a problem
      • _updateEstimates

        protected abstract void _updateEstimates()
        Update parameter estimates.
      • HMMAlphaBetaRecursion

        protected java.util.HashMap HMMAlphaBetaRecursion​(double[][] y,
                                                          double[][] A,
                                                          double[] prior,
                                                          int nCategories)
                                                   throws IllegalActionException
        Java implementation of the Baum-Welch algorithm (The exact algorithm used here is known as the Alpha-Gamma Recursion, which is a slightly more convenient version of the well-known Alpha-Beta recursion) for parameter estimation and cluster assignment. This method uses normalized alpha values for computing the conditional probabilities of input sequences, to ensure numerical stability. Set nCategories to zero for continuous distribution types
        Parameters:
        y - input observation stream
        A - transition probability matrix guess
        prior - prior state distribution guess
        nCategories - number of categories in the multinomial distribution, where applies
        Returns:
        a HashMap containing the updated estimates of all model parameters
        Throws:
        IllegalActionException