ptolemy.actor.lib
Class NonStrictTest

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Sink
                              extended byptolemy.actor.lib.NonStrictTest
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor
Direct Known Subclasses:
Test

public class NonStrictTest
extends Sink

This actor compares the inputs against the value specified by the correctValues parameter. That parameter is an ArrayToken, where each element of the array is of the same type as the input. On each firing where the input is present, the value of the input is compared against the next token in the correctValues parameter. If it matches, the firing succeeds. If it doesn't match, then an exception is thrown. After matching each of the value in the correctValues parameter, subsequent iterations always succeed, so the actor can be used as a "power-up" test for a model, checking the first few iterations against some known results.

Unlike the Test actor, NonStrictTest does not support a multiport input, only single port inputs are supported. This also differs from Test in that it ignores absent inputs, and it checks the inputs in the postfire() method rather than the fire() method.

If the input is a DoubleToken or ComplexToken, then the comparison passes if the value is close to what it should be, within the specified tolerance (which defaults to 10-9. The input data type is undeclared, so it can resolve to anything.

If the parameter trainingMode is true, then instead of performing the test, this actor collects the inputs into the correctValues parameter. Thus, to use this actor, you can place it in a model, set trainingMode to true to collect the reference data, then set trainingMode to false. Any subsequent run of the actor will throw an exception if the input data does not match the training data. The value of the reference token is set in the wrapup() method.

Since:
Ptolemy II 2.0
Version:
$Id: NonStrictTest.java,v 1.40.2.1 2004/08/02 15:45:24 cxh Exp $
Author:
Paul Whitaker, Christopher Hylands, Edward A. Lee
See Also:
Test, Serialized Form
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Yellow (cxh)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
protected  int _iteration
          Count of iterations.
protected  int _numberOfInputTokensSeen
          Number of input tokens seen by this actor in the fire method.
protected  double _tolerance
          A double that is read from the tolerance parameter specifying how close the input has to be to the value given by correctValues.
protected  java.util.List _trainingTokens
          List to store tokens for training mode.
 ptolemy.data.expr.Parameter correctValues
          A matrix specifying what the input should be.
 ptolemy.data.expr.Parameter tolerance
          A double specifying how close the input has to be to the value given by correctValues.
static java.lang.String TRAINING_MODE_ERROR_MESSAGE
          Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.
 ptolemy.data.expr.Parameter trainingMode
          If true, then do not check inputs, but rather collect them into the correctValues array.
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
NonStrictTest(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with an input multiport.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.Attribute attribute)
          If the attribute being changed is tolerance, then check that it is increasing and nonnegative.
 void initialize()
          Override the base class to set the iteration counter to zero.
static boolean isRunningNightlyBuild()
          If the trainingMode parameter is true and the model is being run as part of the test suite, then throw an exception.
 boolean postfire()
          Read one token from each input channel and compare against the value specified in correctValues.
 void wrapup()
          If trainingMode is true, then take the collected training tokens and store them as an array in correctValues.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, fire, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, iterate, prefire, preinitialize, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

correctValues

public ptolemy.data.expr.Parameter correctValues
A matrix specifying what the input should be. This defaults to a one-by-one array containing a boolean true.


tolerance

public ptolemy.data.expr.Parameter tolerance
A double specifying how close the input has to be to the value given by correctValues. This is a DoubleToken, with default value 10-9.


trainingMode

public ptolemy.data.expr.Parameter trainingMode
If true, then do not check inputs, but rather collect them into the correctValues array. This parameter is a boolean, and it defaults to false.


TRAINING_MODE_ERROR_MESSAGE

public static java.lang.String TRAINING_MODE_ERROR_MESSAGE
Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.


_numberOfInputTokensSeen

protected int _numberOfInputTokensSeen
Number of input tokens seen by this actor in the fire method.


_tolerance

protected double _tolerance
A double that is read from the tolerance parameter specifying how close the input has to be to the value given by correctValues. This is a double, with default value 10-9.


_iteration

protected int _iteration
Count of iterations.


_trainingTokens

protected java.util.List _trainingTokens
List to store tokens for training mode.

Constructor Detail

NonStrictTest

public NonStrictTest(ptolemy.kernel.CompositeEntity container,
                     java.lang.String name)
              throws ptolemy.kernel.util.NameDuplicationException,
                     ptolemy.kernel.util.IllegalActionException
Construct an actor with an input multiport.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the entity cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.IllegalActionException
If the attribute being changed is tolerance, then check that it is increasing and nonnegative.

Throws:
ptolemy.kernel.util.IllegalActionException - If the indexes vector is not increasing and nonnegative, or the indexes is not a row vector.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
Override the base class to set the iteration counter to zero.

Throws:
ptolemy.kernel.util.IllegalActionException - If the base class throws it or if we are running under the test suite and the trainingMode parameter is set to true.
See Also:
isRunningNightlyBuild()

isRunningNightlyBuild

public static boolean isRunningNightlyBuild()
If the trainingMode parameter is true and the model is being run as part of the test suite, then throw an exception. This method merely checks to see if "ptolemy.ptII.isRunningNightlyBuild" property exists and is not empty. To run the test suite in the Nightly Build mode, use
  make nightly
  


postfire

public boolean postfire()
                 throws ptolemy.kernel.util.IllegalActionException
Read one token from each input channel and compare against the value specified in correctValues. If the token count is larger than the length of correctValues, then return immediately, indicating that the inputs correctly matched the values in correctValues and that the test succeeded.

Throws:
ptolemy.kernel.util.IllegalActionException - If an input does not match the required value or if the width of the input is not 1.

wrapup

public void wrapup()
            throws ptolemy.kernel.util.IllegalActionException
If trainingMode is true, then take the collected training tokens and store them as an array in correctValues.

Throws:
ptolemy.kernel.util.IllegalActionException