Class ParameterEstimator
- java.lang.Object
- 
- ptolemy.kernel.util.NamedObj
- 
- ptolemy.kernel.InstantiableNamedObj
- 
- ptolemy.kernel.Entity<T>
- 
- ptolemy.kernel.ComponentEntity<T>
- 
- ptolemy.actor.AtomicActor<TypedIOPort>
- 
- ptolemy.actor.TypedAtomicActor
- 
- org.ptolemy.machineLearning.hmm.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)
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class ptolemy.kernel.EntityEntity.ContainedObjectsIterator
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected double[][]_A0User-defined initial guess array for the state transition matrix.protected double_likelihoodThe likelihood value of the observations given the current estimates L(x1,....xT | \theta_p).protected double_likelihoodThresholdThe likelihood threshold.protected int_nIterationsUser-defined number of iterations of the alpha-beta recursion.protected int_nStatesNumber of hidden states in the model.protected int_obsDimensionobservation dimension.protected double[][]_observationsObservation array.protected double[]_priorInThe prior estimates used in the EM iterations.protected double[]_priorsPrior distribution on hidden states.protected boolean_randomizerandomize the initial guess vectors or not.protected double[][]_transitionMatrixInitial guess array for the state transition matrix for the Alpha-Beta Recursion.ParameterA0The user-provided initial guess of the transition probability matrix.TypedIOPortinputThe input port that provides the sample observations.protected doublelikelihoodFitted model likelihood.TypedIOPortlikelihoodOutAn output port of type Double that contains the likelyhood.ParameterlikelihoodThresholdThe user-provided threshold on the minimum desired improvement on likelihood per iteration.ParametermaxIterationsThe user-provided maximum number of allowed iterations of the Alpha-Beta Recursion.protected java.util.HashMapnewEstimatesUpdated parameter sets, used during Expectation-Maximization.ParameternStatesNumber of states of the HMM.ParameterpriorDistributionThe user-provided initial guess on the prior probability distribution.TypedIOPortpriorEstimatesThe vector estimate for the prior distribution on the set of states.ParameterrandomizeGuessVectorsBoolean that determines whether or not to randomize input guess vectors.TypedIOPorttransitionMatrixThe transition matrix estimate obtained by iterating over the observation set.- 
Fields inherited from class ptolemy.actor.TypedAtomicActor_typesValid
 - 
Fields inherited from class ptolemy.actor.AtomicActor_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 - 
Fields inherited from class ptolemy.kernel.util.NamedObj_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 - 
Fields inherited from interface ptolemy.actor.ExecutableCOMPLETED, NOT_READY, STOP_ITERATING
 
- 
 - 
Constructor SummaryConstructors Constructor Description ParameterEstimator(CompositeEntity container, java.lang.String name)Construct an actor with the given container and name.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean_checkForConvergence(int i)Check whether the gradient-descent algorithm has converged.protected boolean_EMParameterEstimation()Expectation-Maximization, which internally executes a gradient-descent algorithm for parameter estimation.protected void_initializeArrays()Initialize arrays to be used in parameter estimation.protected abstract void_initializeEMParameters()Initialize parameters used in ExpectationMaximization here.protected abstract void_iterateEM()One step EM iteration.protected abstract void_updateEstimates()Update parameter estimates.voidattributeChanged(Attribute attribute)React to a change in an attribute.java.lang.Objectclone(Workspace workspace)Clone the actor into the specified workspace.protected abstract doubleemissionProbability(double[] y, int hiddenState)Computes the emission probability.voidfire()Do nothing.protected java.util.HashMapHMMAlphaBetaRecursion(double[][] y, double[][] A, double[] prior, int nCategories)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.- 
Methods inherited from class ptolemy.actor.TypedAtomicActor_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
 - 
Methods inherited from class ptolemy.actor.AtomicActor_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 - 
Methods inherited from class ptolemy.kernel.ComponentEntity_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 - 
Methods inherited from class ptolemy.kernel.Entity_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 - 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 - 
Methods inherited from class ptolemy.kernel.util.NamedObj_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 - 
Methods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface ptolemy.actor.ActorcreateReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 - 
Methods inherited from interface ptolemy.kernel.util.DerivablegetDerivedLevel, getDerivedList, propagateValue
 - 
Methods inherited from interface ptolemy.actor.ExecutableisFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 - 
Methods inherited from interface ptolemy.actor.InitializableaddInitializable, initialize, preinitialize, removeInitializable, wrapup
 - 
Methods inherited from interface ptolemy.kernel.util.Nameabledescription, getContainer, getDisplayName, getFullName, getName, getName, setName
 
- 
 
- 
- 
- 
Field Detail- 
A0public Parameter A0 The user-provided initial guess of the transition probability matrix.
 - 
likelihoodThresholdpublic Parameter likelihoodThreshold The user-provided threshold on the minimum desired improvement on likelihood per iteration.
 - 
maxIterationspublic Parameter maxIterations The user-provided maximum number of allowed iterations of the Alpha-Beta Recursion.
 - 
nStatespublic Parameter nStates Number of states of the HMM.
 - 
randomizeGuessVectorspublic Parameter randomizeGuessVectors Boolean that determines whether or not to randomize input guess vectors.
 - 
priorDistributionpublic Parameter priorDistribution The user-provided initial guess on the prior probability distribution.
 - 
inputpublic TypedIOPort input The input port that provides the sample observations.
 - 
likelihoodOutpublic TypedIOPort likelihoodOut An output port of type Double that contains the likelyhood.
 - 
priorEstimatespublic TypedIOPort priorEstimates The vector estimate for the prior distribution on the set of states.
 - 
transitionMatrixpublic TypedIOPort transitionMatrix The transition matrix estimate obtained by iterating over the observation set.
 - 
_A0protected double[][] _A0 User-defined initial guess array for the state transition matrix.
 - 
_likelihoodprotected double _likelihood The likelihood value of the observations given the current estimates L(x1,....xT | \theta_p).
 - 
_likelihoodThresholdprotected double _likelihoodThreshold The likelihood threshold.
 - 
_nIterationsprotected int _nIterations User-defined number of iterations of the alpha-beta recursion.
 - 
_obsDimensionprotected int _obsDimension observation dimension.
 - 
_nStatesprotected int _nStates Number of hidden states in the model.
 - 
_observationsprotected double[][] _observations Observation array.
 - 
_priorsprotected double[] _priors Prior distribution on hidden states.
 - 
_priorInprotected double[] _priorIn The prior estimates used in the EM iterations.
 - 
_randomizeprotected boolean _randomize randomize the initial guess vectors or not.
 - 
_transitionMatrixprotected double[][] _transitionMatrix Initial guess array for the state transition matrix for the Alpha-Beta Recursion.
 - 
newEstimatesprotected java.util.HashMap newEstimates Updated parameter sets, used during Expectation-Maximization.
 - 
likelihoodprotected double likelihood Fitted model likelihood.
 
- 
 - 
Constructor Detail- 
ParameterEstimatorpublic ParameterEstimator(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException Construct an actor with the given container and name.- Parameters:
- container- The container.
- name- The name of this actor
- Throws:
- IllegalActionException- If the actor cannot be contained by the proposed container.
- NameDuplicationException- If the container already has an actor with this name.
 
 
- 
 - 
Method Detail- 
attributeChangedpublic void attributeChanged(Attribute attribute) throws IllegalActionException Description copied from class:NamedObjReact 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:
- attributeChangedin 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).
 
 - 
clonepublic java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException Description copied from class:TypedAtomicActorClone the actor into the specified workspace.- Overrides:
- clonein class- TypedAtomicActor
- Parameters:
- workspace- The workspace for the new object.
- Returns:
- A new actor.
- Throws:
- java.lang.CloneNotSupportedException- If a derived class contains an attribute that cannot be cloned.
- See Also:
- NamedObj.exportMoML(Writer, int, String),- NamedObj.setDeferringChangeRequests(boolean)
 
 - 
firepublic void fire() throws IllegalActionExceptionDescription copied from class:AtomicActorDo nothing. Derived classes override this method to define their primary run-time action.- Specified by:
- firein interface- Executable
- Overrides:
- firein class- AtomicActor<TypedIOPort>
- Throws:
- IllegalActionException- Not thrown in this base class.
 
 - 
_EMParameterEstimationprotected boolean _EMParameterEstimation() throws IllegalActionExceptionExpectation-Maximization, which internally executes a gradient-descent algorithm for parameter estimation.- Returns:
- whether parameter estimation has succeded
- Throws:
- IllegalActionException
 
 - 
emissionProbabilityprotected abstract double emissionProbability(double[] y, int hiddenState) throws IllegalActionExceptionComputes 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
 
 - 
_initializeArraysprotected void _initializeArrays() throws IllegalActionExceptionInitialize arrays to be used in parameter estimation.- Throws:
- IllegalActionException- Not thrown in this base class.
 
 - 
_initializeEMParametersprotected abstract void _initializeEMParameters() Initialize parameters used in ExpectationMaximization here.
 - 
_iterateEMprotected abstract void _iterateEM() throws IllegalActionExceptionOne step EM iteration.- Throws:
- IllegalActionException- If there is a problem.
 
 - 
_checkForConvergenceprotected abstract boolean _checkForConvergence(int i) throws IllegalActionExceptionCheck 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
 
 - 
_updateEstimatesprotected abstract void _updateEstimates() Update parameter estimates.
 - 
HMMAlphaBetaRecursionprotected java.util.HashMap HMMAlphaBetaRecursion(double[][] y, double[][] A, double[] prior, int nCategories) throws IllegalActionExceptionJava 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
 
 
- 
 
-