ptolemy.domains.continuous.kernel
Class Noise
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Source
ptolemy.actor.lib.RandomSource
ptolemy.actor.lib.Gaussian
ptolemy.domains.continuous.kernel.Noise
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
- Direct Known Subclasses:
- Noise
public class Noise
- extends Gaussian
This actor generates continuous-time noise with a Gaussian distribution.
It provides two approximations to a white noise process, depending
on the value of the linearlyInterpolate parameter. Specifically,
if this parameter is true (the default), then the output signal is
a continuous signal that linearly interpolates between
Gaussian random numbers generated at each sample time chosen by
the solver. If the solver step size is constant or increasing, then these Gaussian
random numbers will be independent. However, if the solver finds itself having
to reduce the step size after performing a speculative execution into the
future, then the random number produced at the end of the reduced
integration step will be correlated with that produced at the beginning
of the integration step. (FIXME: Need a figure to illustrate this.)
If linearlyInterpolate is set to false, then this actor will
hold the value of its output constant for the duration of an integration
step. Thus, the output signal is piecewise constant. At each time step
chosen by the solver, the value is given by a new independent Gaussian
random number. This method has the advantage that samples at all
times chosen by the solver are uncorrelated.
In both cases, whether linearlyInterpolate is true or false, if the
solver holds its step size constant, then the resulting signal is
statistically equivalent to filtered white noise. If linearlyInterpolate
is true, then the power spectrum has the shape of a sinc squared.
If it is false, then it has the shape of the absolute value of a sinc
function. In the latter case, the power is infinite, so the approximation
is not physically realizable. In the former case, the power is finite.
In both cases, sampling the process at the rate of one over the step
size yields a discrete-time white noise process.
It is worth explaining why we must approximate white noise.
In general, it is not possible in any discretized approximation of a continuous
random process to exactly simulate a white noise process. By definition, a
white noise process is one where any two values at distinct times are
uncorrelated. A naive attempt to simulate this might simply generate
a new random number at each sample time at which the solver chooses
to fire the actor. However, this cannot work in general.
Specifically, the semantics of the continuous domain assumes
that signals are piecewise continuous. The signal resulting from
the above strategy will not be piecewise continuous. If the solver
refines a step size and chooses a point close to a previously calculated
point, the new value produced by such an actor would not be close to the
previously value previously produced. This can result in the solver
assuming that its step size is too large and reducing it until it can
reduce it no more.
To demonstrate this effect, try connecting a GaussianActor to a
LevelCrossingDetector actor under a ContinuousDirector. An execution
of the model will immediately trigger an exception with a message
like "The refined step size is less than the time resolution, at time..."
Conceptually, with a true white noise process, the level crossing
occurs at all times, and therefore the exception is,
in fact, the correct response.
If you modify the above example by sending the output of the
Gaussian actor directly to an Integrator, and then the output
of the Integrator to the LevelCrossingDetector, then the exception
disappears. The Integrator ensures that the signal is piecewise
continuous. This might seem like a reasonable approximation to a
Weiner process, but in fact it is problematic. In particular,
at the times that the LevelCrossingDetector triggers, the
Gaussian actor will actually produce two distinct random numbers
at the same time (at different microsteps). This changes the
statistics of the output in a very subtle way.
- Since:
- Ptolemy II 8.0
- Version:
- $Id: Noise.java 57046 2010-01-27 23:35:53Z cxh $
- Author:
- Edward A. Lee
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
Field Summary |
private Time |
_timeOfValueAtEnd
Time assigned to a new random number. |
private double |
_valueAtEnd
The random number at the end of the current integration period. |
private double |
_valueAtStart
The random number at the start of the current integration period. |
Parameter |
linearlyInterpolate
If true, linearly between random number for multistep solvers,
and otherwise, perform zero-order hold. |
Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Constructor Summary |
Noise(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary |
protected void |
_generateRandomNumber()
Generate a new random number. |
void |
fire()
Produce a number that is linearly interpolated within the
current integration step, if linearlyInterpolate is true, or
the random number for the beginning of the integration
step otherwise. |
void |
initialize()
Initialize the random number generator with the seed, if it
has been given. |
boolean |
postfire()
Set a flag to cause a new random number to be generated the next
time fire() is called. |
Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, 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 |
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName |
Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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 |
linearlyInterpolate
public Parameter linearlyInterpolate
- If true, linearly between random number for multistep solvers,
and otherwise, perform zero-order hold. This is a boolean that
defaults to true.
_timeOfValueAtEnd
private Time _timeOfValueAtEnd
- Time assigned to a new random number. This will be the integration end
time for the first firing with a non-zero step size after the random
number is generated.
_valueAtStart
private double _valueAtStart
- The random number at the start of the current integration period.
_valueAtEnd
private double _valueAtEnd
- The random number at the end of the current integration period.
Noise
public Noise(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.
fire
public void fire()
throws IllegalActionException
- Produce a number that is linearly interpolated within the
current integration step, if linearlyInterpolate is true, or
the random number for the beginning of the integration
step otherwise.
- Specified by:
fire
in interface Executable
- Overrides:
fire
in class Gaussian
- Throws:
IllegalActionException
- If the superclass throws it.
initialize
public void initialize()
throws IllegalActionException
- Initialize the random number generator with the seed, if it
has been given. A seed of zero is interpreted to mean that no
seed is specified. In such cases, a seed based on the current
time and this instance of a RandomSource is used to be fairly
sure that two identical sequences will not be returned.
- Specified by:
initialize
in interface Initializable
- Overrides:
initialize
in class RandomSource
- Throws:
IllegalActionException
- If the parent class throws it.
postfire
public boolean postfire()
throws IllegalActionException
- Set a flag to cause a new random number to be generated the next
time fire() is called.
- Specified by:
postfire
in interface Executable
- Overrides:
postfire
in class RandomSource
- Returns:
- True if it is OK to continue.
- Throws:
IllegalActionException
- If the base class throws it.
_generateRandomNumber
protected void _generateRandomNumber()
throws IllegalActionException
- Generate a new random number. This gets called in initialize()
and in the first fire() method of an iteration. It produces a number
that is to be the random number at the end of the current
iteration.
- Overrides:
_generateRandomNumber
in class Gaussian
- Throws:
IllegalActionException
- If parameter values are incorrect.