Class ParameterEstimator

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

    public abstract class ParameterEstimator
    extends AtomicCommunicationAspect
    This actor is a CommunicationAspect that, when its sendToken(Receiver, Receiver, Token) method is called, delays the delivery of the specified token to the specified receiver according to a service rule. Specifically, if the actor is not currently servicing a previous token, then it delivers the token with a delay given by the serviceTimeMultiplicationFactor parameter multiplied by the messageLength parameter specified in the port. If the actor is currently servicing a previous token, then it waits until it has finished servicing that token (and any other pending tokens), and then delays for an additional amount given by serviceTimeMultiplicationFactor * messageLength. In the default case of the messageLength = 1, the behavior is similar to the Server actor. Tokens are processed in FIFO order.

    To use this communication aspect, drag an instance of this Bus into the model, and (optionally) assign it a name. Then, on any input port whose communication is to be mediated by this instance of Bus, open the configuration dialogue, select the tab with the name of the bus in the title and select the enable attribute. The message length is by default set to 1 but can be configured in this tab.

    Several Bus communication aspects can be used in sequence. The order in which Tokens are sent through Buses depends on the order in which these are enabled via the DecoratorAttributes.

    This actor is tested in continuous and DE.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Patricia Derler, Edward A. Lee
    Pt.AcceptedRating:
    Red (derler)
    Pt.ProposedRating:
    Yellow (derler)
    • Field Detail

      • serviceTimeMultiplicationFactor

        public Parameter serviceTimeMultiplicationFactor
        The service time for the default messageLength of 1. This is a double with default 0.1. It is required to be positive.
      • 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.
      • batchSize

        public Parameter batchSize
        The user-provided batch-size to be considered in the estimation.
      • 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.
      • 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.
      • _batchSize

        protected int _batchSize
        User-defined batch size.
      • _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.
      • _nStates

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

        protected double[] _observations
        Observation array.
      • _observedTokens

        protected java.util.HashMap<java.lang.String,​java.util.List<java.lang.Double>> _observedTokens
        The observation tokens.
      • _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
        If true, then randomize the initial guess vectors.
      • _transitionMatrix

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

      • ParameterEstimator

        public ParameterEstimator​(CompositeEntity container,
                                  java.lang.String name)
                           throws IllegalActionException,
                                  NameDuplicationException
        Construct a Bus with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace.
        Parameters:
        container - The container.
        name - The name of this actor.
        Throws:
        IllegalActionException - If the container is incompatible with this actor.
        NameDuplicationException - If the name coincides with an actor already in the container.
    • Method Detail

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone this actor into the specified workspace. The new actor is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new actor with the same ports as the original, but no connections and no container. A container must be set before much can be done with this actor.
        Overrides:
        clone in class AtomicCommunicationAspect
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        A new Bus.
        Throws:
        java.lang.CloneNotSupportedException - If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • sendToken

        public void sendToken​(Receiver source,
                              Receiver receiver,
                              Token token)
                       throws IllegalActionException
        Initiate a send of the specified token to the specified receiver. This method will schedule a refiring of this actor if there is not one already scheduled.
        Parameters:
        source - Sender of the token.
        receiver - The receiver to send to.
        token - The token to send.
        Throws:
        IllegalActionException - If the refiring request fails.
      • reset

        public void reset()
        Nothing to do.
      • _EMParameterEstimation

        protected boolean _EMParameterEstimation()
      • emissionProbability

        protected abstract double emissionProbability​(double y,
                                                      int hiddenState)
      • _initializeEMParameters

        protected abstract void _initializeEMParameters()
      • _iterateEM

        protected abstract void _iterateEM()
      • _checkForConvergence

        protected abstract boolean _checkForConvergence​(int i)
      • _updateEstimates

        protected abstract void _updateEstimates()
      • HMMAlphaBetaRecursion

        protected java.util.HashMap HMMAlphaBetaRecursion​(double[] y,
                                                          double[][] A,
                                                          double[] prior,
                                                          int nCategories)
        Java implementation of the Baum-Welch algorithm (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 - y values
        A - A values
        prior - prior values
        nCategories - The number of categories
        Returns:
        a hashmaps with String keys and double array values.
      • HMMAlphaBetaRecursionNonNormalized

        protected java.util.HashMap HMMAlphaBetaRecursionNonNormalized​(double[] y,
                                                                       double[][] A,
                                                                       double[] prior,
                                                                       int unused)