Package org.ptolemy.machineLearning.hsmm
Class HSMMParameterEstimator
- 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
-
- org.ptolemy.machineLearning.hsmm.HSMMParameterEstimator
-
- All Implemented Interfaces:
java.lang.Cloneable,Actor,Executable,FiringsRecordable,Initializable,TypedActor,Changeable,Debuggable,DebugListener,Derivable,Instantiable,ModelErrorHandler,MoMLExportable,Moveable,Nameable
- Direct Known Subclasses:
HSMMGaussianEstimator,HSMMMultinomialEstimator
public abstract class HSMMParameterEstimator extends ParameterEstimator
This actor implements the Expectation-Maximization(EM) algorithm for parameter estimation in a family of graphical stochastic models, known as the Hidden Semi-Markov Model family.
In addition to estimating the parameters of a hidden markov model,
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:
ParameterEstimator- Pt.AcceptedRating:
- Pt.ProposedRating:
- Red (ilgea)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected double[][]_Dcurrent duration distribution.protected double[][]_D0initial duration distribution.protected double[]_dPriors0The user defined duration priors.protected double[]_durationPriorsDuration priors - an nStates-by-nDurations matrix.protected int_etaDimensionTotal number of categories among all observation dimensions.protected java.util.List<java.lang.Double>_likelihoodHistoryLikelihood history over iterations.protected int_maxDurationmaximum duration ( in time steps).TypedIOPortclusterAssignmentsHidden-State Assignments.protected double[][]D_newnew duration distribution.TypedIOPortdurationEstimatesDurationEstimates.TypedIOPortdurationPriorEstimatesDuration Prior estimates.ParameterdurationProbabilitiesThe user-provided initial guess on the prior probability distribution.ParametermaxStateDurationMaximum Duration.ParameterpriorDurationDistributionThe user-provided initial guess on the prior probability distribution.-
Fields inherited from class org.ptolemy.machineLearning.hmm.ParameterEstimator
_A0, _likelihood, _likelihoodThreshold, _nIterations, _nStates, _obsDimension, _observations, _priorIn, _priors, _randomize, _transitionMatrix, A0, input, likelihood, likelihoodOut, likelihoodThreshold, maxIterations, newEstimates, nStates, priorDistribution, priorEstimates, randomizeGuessVectors, transitionMatrix
-
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.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description HSMMParameterEstimator(CompositeEntity container, java.lang.String name)Construct an actor with the given container and name.
-
Method Summary
All 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 doubledurationProbability(int y, int hiddenState)Return the duration probability of duration y at hidden state.protected abstract doubleemissionProbability(double[] y, int hiddenState)Computes the emission probability.voidfire()Do nothing.protected java.util.HashMapHSMMAlphaBetaRecursion(double[][] y, double[][] A, double[] prior, int[] nCategories)Java implementation of the Baum-Welch algorithm (Alpha-Beta Recursion) for parameter estimation and cluster assignment.voidpreinitialize()Create receivers and declare delay dependencies.-
Methods inherited from class org.ptolemy.machineLearning.hmm.ParameterEstimator
HMMAlphaBetaRecursion
-
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, 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.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
priorDurationDistribution
public Parameter priorDurationDistribution
The user-provided initial guess on the prior probability distribution.
-
durationProbabilities
public Parameter durationProbabilities
The user-provided initial guess on the prior probability distribution.
-
durationEstimates
public TypedIOPort durationEstimates
DurationEstimates.
-
durationPriorEstimates
public TypedIOPort durationPriorEstimates
Duration Prior estimates.
-
clusterAssignments
public TypedIOPort clusterAssignments
Hidden-State Assignments.
-
maxStateDuration
public Parameter maxStateDuration
Maximum Duration.
-
_durationPriors
protected double[] _durationPriors
Duration priors - an nStates-by-nDurations matrix.
-
D_new
protected double[][] D_new
new duration distribution.
-
_D0
protected double[][] _D0
initial duration distribution.
-
_D
protected double[][] _D
current duration distribution.
-
_dPriors0
protected double[] _dPriors0
The user defined duration priors. Note that while _durationPriors gets updated on Baum-Welch Iterations, this array stays set at the initial user setting such that if the algorithm fails to converge, the value of _durationPriors is rolled back to _dPriors0.
-
_maxDuration
protected int _maxDuration
maximum duration ( in time steps).
-
_etaDimension
protected int _etaDimension
Total number of categories among all observation dimensions.
-
_likelihoodHistory
protected java.util.List<java.lang.Double> _likelihoodHistory
Likelihood history over iterations. Used for debugging at the moment.
-
-
Constructor Detail
-
HSMMParameterEstimator
public HSMMParameterEstimator(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
-
attributeChanged
public 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 classParameterEstimator- Parameters:
attribute- The attribute that changed.- Throws:
IllegalActionException- If the change is not acceptable to this container (not thrown in this base class).
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Description copied from class:TypedAtomicActorClone the actor into the specified workspace.- Overrides:
clonein classParameterEstimator- 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)
-
preinitialize
public void preinitialize() throws IllegalActionExceptionDescription copied from class:AtomicActorCreate receivers and declare delay dependencies. Derived classes can override this method to perform additional initialization functions, but they should call this base class methods or create the receivers themselves. This method gets executed exactly once prior to any other action methods. It cannot produce output data since type resolution is typically not yet done. It also gets invoked prior to any static scheduling that might occur in the domain, so it can change scheduling information.- Specified by:
preinitializein interfaceInitializable- Overrides:
preinitializein classAtomicActor<TypedIOPort>- Throws:
IllegalActionException- Not thrown in this base class.
-
fire
public void fire() throws IllegalActionExceptionDescription copied from class:AtomicActorDo nothing. Derived classes override this method to define their primary run-time action.- Specified by:
firein interfaceExecutable- Overrides:
firein classParameterEstimator- Throws:
IllegalActionException- Not thrown in this base class.
-
_EMParameterEstimation
protected boolean _EMParameterEstimation()
Description copied from class:ParameterEstimatorExpectation-Maximization, which internally executes a gradient-descent algorithm for parameter estimation.- Overrides:
_EMParameterEstimationin classParameterEstimator- Returns:
- whether parameter estimation has succeded
-
emissionProbability
protected abstract double emissionProbability(double[] y, int hiddenState)Description copied from class:ParameterEstimatorComputes the emission probability. Implemented by the child class.- Specified by:
emissionProbabilityin classParameterEstimator- Parameters:
y- input observationhiddenState- index of hidden state- Returns:
- P(Y=y | X=hiddenState)
-
durationProbability
protected abstract double durationProbability(int y, int hiddenState)Return the duration probability of duration y at hidden state.- Parameters:
y- The duration indexhiddenState- The hidden state index- Returns:
- p(y|hiddenState)
-
_initializeArrays
protected void _initializeArrays() throws IllegalActionExceptionDescription copied from class:ParameterEstimatorInitialize arrays to be used in parameter estimation.- Overrides:
_initializeArraysin classParameterEstimator- Throws:
IllegalActionException- Not thrown in this base class.
-
_initializeEMParameters
protected abstract void _initializeEMParameters()
Description copied from class:ParameterEstimatorInitialize parameters used in ExpectationMaximization here.- Specified by:
_initializeEMParametersin classParameterEstimator
-
_iterateEM
protected abstract void _iterateEM()
Description copied from class:ParameterEstimatorOne step EM iteration.- Specified by:
_iterateEMin classParameterEstimator
-
_checkForConvergence
protected abstract boolean _checkForConvergence(int i)
Description copied from class:ParameterEstimatorCheck whether the gradient-descent algorithm has converged.- Specified by:
_checkForConvergencein classParameterEstimator- Parameters:
i- Current iteration index- Returns:
- boolean indicating whether algorithm has converged
-
_updateEstimates
protected abstract void _updateEstimates()
Description copied from class:ParameterEstimatorUpdate parameter estimates.- Specified by:
_updateEstimatesin classParameterEstimator
-
HSMMAlphaBetaRecursion
protected java.util.HashMap HSMMAlphaBetaRecursion(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- Observation arrayA- transition probability matrixprior- State priorsnCategories- Number of categories in multinomial distribution- Returns:
- a Map of parameter estimates
-
-