Class CompositeOptimizerUsingGradient
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity
-
- ptolemy.kernel.CompositeEntity
-
- ptolemy.actor.CompositeActor
-
- ptolemy.actor.TypedCompositeActor
-
- ptolemy.actor.lib.hoc.ReflectComposite
-
- org.ptolemy.optimization.CompositeOptimizerUsingGradient
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
,HandlesInternalLinks
public class CompositeOptimizerUsingGradient extends ReflectComposite
This actor implements a composite optimizer that optimizes a function provided as an SDF model in the inner composite. To use the composite optimizer, construct an SDF model on the inside that operates on the x input to output four values: (i) an intermediate result, that is a function of x and possibly other inputs, (ii) a double array containing the values of the constraints, calculated for the specific x input, (iii) a double matrix that is a gradient of a function of x, and (iv) an array of double matrices that is a gradient of the constraints. If the gradients (iii) and (iv) can't be defined, un-check the parameter "useGradient" in expert mode so that (iii) and (iv) are not used.In the case that the objective function is only a function of x, the trigger input should be used to start a new optimization round.
The variable named "maxEvaluations" can be used to limit the number of evaluations. Specifically, the inside SDF model will be fired at most maxEvaluations times. There may be several reasons it is fired less than this number. The iteration may terminate due to any of the following reasons: (i) convergence criteria met (ii) user requests termination (iii) the roundoff errors become damaging, especially if the function is not smooth, and no optimal value can be found under given constraints (iv) maximum number of evaluations are reached.
This actor is properly viewed as a "higher-order component" in that its contained actor is a parameter that specifies how to operate on input arrays. It is inspired by the higher-order functions of functional languages, but unlike those, the contained actor need not be functional. That is, it can have state.
If the gradients are used (the parameter "useGradient" is checked), Barrier Method is used as the solver. Barrier Method performs optimization efficiently using gradients and estimating the hessian of the objective function and the constraints. If the parameter "useGradient" is un-checked, current implementation uses Cobyla as the solver. Cobyla implements the trust-region-reflective algorithm and performs a type of gradient descent optimization, ideal for objective functions that are non-convex and/or with unknown gradient.
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Shuhei Emoto, Ilge Akkaya, Edward A. Lee
- Pt.AcceptedRating:
- Pt.ProposedRating:
- Red (shuhei)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompositeOptimizerUsingGradient.OptimizerComposite
This is a specialized composite actor for use in CompositeOptimizer.class
CompositeOptimizerUsingGradient.OptimizerDirector
This is a specialized director that fires the input SDF model repeatedly for different values of the optimization variable.-
Nested classes/interfaces inherited from class ptolemy.actor.lib.hoc.ReflectComposite
ReflectComposite.ReflectCompositeContents
-
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description Parameter
dimensionOfOptimizationSpace
The dimension of optimization space.Parameter
maxEvaluations
Maximum number of function evaluations per iteration.Parameter
mode
Optimization mode.Parameter
numberOfConstraints
Number of constraints checked at each evaluation.TypedIOPort
optimalValue
Optimal ValueParameter
reusePreviousResult
The expert parameter that decides whether to reuse previous result as the initial value.Parameter
rhoBeg
The expert parameter that denotes the beginning step-size.Parameter
rhoEnd
The expert parameter that denotes the final step-size.TypedIOPort
trigger
Trigger.Parameter
useGradient
The expert parameter that decides whether to use Interior point method or not.-
Fields inherited from class ptolemy.actor.lib.hoc.ReflectComposite
_inAddPort, _inRemoveEntity, _mirrorParameterPorts
-
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _derivedPiggybacks, _initializables, _notifyingActorFiring, _piggybacks, _publishedPorts, _publisherRelations, _stopRequested, _subscribedPorts
-
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
-
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 CompositeOptimizerUsingGradient(CompositeEntity container, java.lang.String name)
Constructs a CompositeOptimizer object.CompositeOptimizerUsingGradient(Workspace workspace)
Constructs a CompositeOptimizer object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
React to a change in an attribute.java.lang.Object
clone(Workspace workspace)
Clone the object into the specified workspace.void
wrapup()
If this actor is opaque, then invoke the wrapup() method of the local director.-
Methods inherited from class ptolemy.actor.lib.hoc.ReflectComposite
_addEntity, _addPort, _exportMoMLContents, _mirrorPort, _removeEntity, _removePort, newParameterPort, newPort
-
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addRelation, _checkTypesFromTo, _destinationTypeConstraints, attributeTypeChanged, isBackwardTypeInferenceEnabled, newRelation, resolveTypes, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _setDirector, _transferPortParameterInputs, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, getPublishedPort, getPublishedPortChannel, getPublishedPorts, getSubscribedPortChannel, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isOpaque, isPublishedPort, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, postfire, prefire, preinitialize, recordFiring, registerPublisherPort, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort, unregisterPublisherPort
-
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _containedDecorators, _deepOpaqueEntityList, _description, _removeRelation, _validateSettables, allAtomicEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepCompositeEntityList, deepEntityList, deepGetEntities, deepNamedObjList, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyAllCompositeTransparentAndOpaqueEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, clone, 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, 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
fire, isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
rhoBeg
public Parameter rhoBeg
The expert parameter that denotes the beginning step-size.
-
rhoEnd
public Parameter rhoEnd
The expert parameter that denotes the final step-size.
-
reusePreviousResult
public Parameter reusePreviousResult
The expert parameter that decides whether to reuse previous result as the initial value.
-
useGradient
public Parameter useGradient
The expert parameter that decides whether to use Interior point method or not.
-
maxEvaluations
public Parameter maxEvaluations
Maximum number of function evaluations per iteration.
-
mode
public Parameter mode
Optimization mode. ( min or max)
-
dimensionOfOptimizationSpace
public Parameter dimensionOfOptimizationSpace
The dimension of optimization space. Also equal to the length of the optimization variable array, x.
-
numberOfConstraints
public Parameter numberOfConstraints
Number of constraints checked at each evaluation. The expected type of constraints is a double array with length numberOfConstraints.
-
optimalValue
public TypedIOPort optimalValue
Optimal Value
-
trigger
public TypedIOPort trigger
Trigger.
-
-
Constructor Detail
-
CompositeOptimizerUsingGradient
public CompositeOptimizerUsingGradient(Workspace workspace) throws IllegalActionException, NameDuplicationException
Constructs a CompositeOptimizer object.- Parameters:
workspace
- a Workspace object- Throws:
IllegalActionException
- ...NameDuplicationException
- ...
-
CompositeOptimizerUsingGradient
public CompositeOptimizerUsingGradient(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Constructs a CompositeOptimizer object.- Parameters:
container
- a CompositeEntity objectname
- a String ...- Throws:
IllegalActionException
- ...NameDuplicationException
- ...
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Description copied from class:TypedCompositeActor
React to a change in an attribute. If the name of the attribute is "enableBackwardTypeInference" then invalidate resolved types.- Overrides:
attributeChanged
in classTypedCompositeActor
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- Not thrown in this base class. Derived classes can throw this exception if type change is not allowed.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Description copied from class:ReflectComposite
Clone the object into the specified workspace. This overrides the base class to set up the associations in the mirror ports and to set a flag indicating that cloning is complete.- Overrides:
clone
in classReflectComposite
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new NamedObj.
- Throws:
java.lang.CloneNotSupportedException
- If any of the attributes cannot be cloned.- See Also:
CompositeEntity.exportMoML(Writer, int, String)
-
wrapup
public void wrapup() throws IllegalActionException
Description copied from class:CompositeActor
If this actor is opaque, then invoke the wrapup() method of the local director. This method is read-synchronized on the workspace.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classCompositeActor
- Throws:
IllegalActionException
- If there is no director, or if the director's wrapup() method throws it, or if this actor is not opaque.
-
-