public class SmoothToken extends DoubleToken
This token will be treated exactly
like a DoubleToken
by any actor or operation that does not
specifically support it, and it will be represented in the type systems
as a "double." But it can (potentially) carry additional information giving
one or more derivatives of the function from which it is a sample and
giving the time at which it represents a sample of the signal.
This token, therefore, gives a way for actors that either generate or
use this derivative information to make that information available to other
actors that can use it. Such actors should declare their input ports to
be of type double, but when they receive an input token, they should
check (using instanceof) whether the token is a SmoothToken, and if so,
access these derivatives using the derivativeValues()
method,
or extrapolate the value to a specified time using the extrapolate(Time)
method.
Note that if two SmoothTokens are added or subtracted, then the derivatives also add or subtract. If the times of the two tokens that are added or subtracted are not the same, then the one with the lesser time is extrapolated to the larger time, and the result will be the sum at the later time. If a SmoothToken is added to a DoubleToken, the derivatives of the DoubleToken are assumed to be zero, and similarly for subtraction.
If a SmoothToken is multiplied by a SmoothToken, then the product rule of calculus is used to determine the derivatives of the product. The product rule stipulates that
(xy)' = x'y + xy'Again, if the times of the two tokens are not equal, then the one with the lesser time will be extrapolated to the larger time before being multiplied, and the time of the result will be the larger time. If a SmoothToken is multiplied by a DoubleToken, then the derivatives of the DoubleToken are assumed to be zero.
Division works similarly:
(x/y)' = x'/y + x(1/y)' = x'/y - xy'/y^2
where the last equality follows from the reciprocal rule of calculus. The second derivative of a multiplication or division is obtained by applying the above rules to x' and y' rather than to x and y. Higher-order derivatives are similarly obtained.
You can construct an instance of this token in the Ptolemy expression
language using the smoothToken(double, double, {double})
function.
The first argument specifies the value, and the second argument specifies
the time, and the third specifies the derivatives. Also provided in the
expression language are one and two argument versions of this function that
assume the time is zero. These should be used only during initialization, and
only if the start time of the model is actually zero.
By default, instances of SmoothToken have no more than three derivatives.
This can be changed using the setOrderLimit(int)
method.
FIXME: Division is not implemented yet.
Modifier and Type | Field and Description |
---|---|
(package private) static int |
_maxOrder |
static SmoothToken |
NIL
A token that represents a missing value.
|
_value, ONE, ZERO
_unitCategoryExponents
Constructor and Description |
---|
SmoothToken()
Construct a SmoothToken with value 0.0 at time zero and no derivatives.
|
SmoothToken(double value)
Construct a SmoothToken with the specified value at time zero and no derivatives.
|
SmoothToken(double[] x,
Time time)
Construct a SmoothToken with the specified value and derivatives, given
as a single array, at the specified time.
|
SmoothToken(double value,
double[] derivatives)
Construct a SmoothToken with the specified value at time zero
and the specified derivatives.
|
SmoothToken(double value,
Time time,
double[] derivatives)
Construct a SmoothToken with the specified value at the specified
time, and with the specified derivatives.
|
SmoothToken(java.lang.String init)
Construct a SmoothToken from the specified string, which specifies only
a value.
|
Modifier and Type | Method and Description |
---|---|
protected ScalarToken |
_add(ScalarToken rightArgument)
Return a new token whose value is the value of the
argument Token added to the value of this Token.
|
protected ScalarToken |
_divide(ScalarToken divisor)
Return a new token whose value is the value of this token
divided by the value of the argument token.
|
protected boolean |
_isClose(double arg1,
double arg2,
double epsilon)
Return true if the two arguments are within epsilon of one another.
|
protected BooleanToken |
_isCloseTo(ScalarToken rightArgument,
double epsilon)
Test that the value of this token is close to the first
argument, where "close" means that the distance between their
values is less than or equal to the second argument.
|
protected BooleanToken |
_isLessThan(ScalarToken rightArgument)
Test for ordering of the values of this Token and the argument
Token.
|
protected ScalarToken |
_multiply(ScalarToken rightArgument)
Return a new token whose value is the value of this token
multiplied by the value of the argument token.
|
protected static double[] |
_multiplyPolynomials(double[] p1,
double[] p2)
Multiply two polynomials.
|
protected ScalarToken |
_subtract(ScalarToken rightArgument)
Return a new token whose value is the value of the argument token
subtracted from the value of this token.
|
(package private) SmoothToken[] |
align(SmoothToken arg1,
SmoothToken arg2)
Given two SmoothTokens, align them by finding the maximum time
of the tokens, extrapolating the other token to that time, and returning
an array of tokens with the extrapolated values and derivatives.
|
static Token[] |
align(Token[] args)
Given an array of Tokens, align them by finding the maximum time
of all the tokens, extrapolating all tokens that are instances of
SmoothToken to that time, and returning
an array of tokens with the extrapolated values and derivatives.
|
static Token[] |
align(Token[] args,
Time time)
Given an array of Tokens and a time, align them by
extrapolating all tokens that are instances of
SmoothToken to that time, and returning
an array of tokens with the extrapolated values and derivatives.
|
static double |
derivativeValue(DoubleToken token,
int n)
Return the n-th derivative of the specified token.
|
double[] |
derivativeValues()
Return the derivatives of the token as a double[], or null if there are
no derivatives.
|
boolean |
equals(java.lang.Object object)
Return true if the argument's class is SmoothToken and it has the
same value and derivatives as this token.
|
SmoothToken |
extrapolate(Time time)
Return a SmoothToken at the specified time whose value and derivatives
are the result of extrapolating this token to the specified time.
|
static int |
getOrderLimit()
Get the maximum order of any token (the number of derivatives).
|
Time |
getTime()
Return the time for which the values of this smooth token are valid.
|
int |
hashCode()
Return the hash code for the SmoothToken object.
|
boolean |
isNil()
Return true if the token is nil, (aka null or missing).
|
static int |
maxOrder(DoubleToken arg1,
DoubleToken arg2)
Return the maximum number of specified derivatives for the two tokens.
|
SmoothToken |
negate()
Return a new token that is the negative of this one.
|
static int |
order(DoubleToken token)
Return the number of specified derivatives for the token.
|
static void |
setOrderLimit(int maxOrder)
Set the maximum order of any token (the number of derivatives).
|
static SmoothToken |
smoothToken(double value)
Return a SmoothToken with the specified value at time zero and no derivatives.
|
static SmoothToken |
smoothToken(double value,
double[] derivatives)
Return a SmoothToken with the specified value at time zero and derivatives.
|
java.lang.String |
toString()
Return the value of this token as a string that can be parsed
by the expression language to recover a token with the same value and derivatives.
|
_absolute, _bitwiseAnd, _bitwiseNot, _bitwiseOr, _bitwiseXor, _modulo, complexValue, convert, doubleValue, getType, one, zero
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isEqualTo, _isUnitless, _subtractCategoryExponents, absolute, add, addReverse, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseXor, byteValue, divide, divideReverse, fixValue, floatValue, intValue, inUnitsOf, isCloseTo, isEqualTo, isGreaterThan, isLessThan, isLessThan, leftShift, logicalRightShift, longValue, modulo, moduloReverse, multiply, multiplyReverse, rightShift, setUnitCategory, shortValue, subtract, subtractReverse, unitsString
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
public static final SmoothToken NIL
static int _maxOrder
public SmoothToken()
public SmoothToken(double value)
value
- The specified value.public SmoothToken(double value, double[] derivatives)
value
- The specified value.derivatives
- The specified derivatives.public SmoothToken(double value, Time time, double[] derivatives)
value
- The specified value.time
- The specified time.derivatives
- The specified derivatives.public SmoothToken(double[] x, Time time)
x
- An array where the first element is the value, and optionally any
other elements can be present to specify the first, second, etc. derivatives.time
- The time at which this token is a sample.public SmoothToken(java.lang.String init) throws IllegalActionException
init
- The initialization string, which is in a format
suitable for java.lang.Double.parseDouble(String).IllegalActionException
- If the Token could not
be created with the given String.public static Token[] align(Token[] args, Time time)
args
- The tokens to be aligned.time
- The Time to which the tokens will be aligned.public static Token[] align(Token[] args)
args
- The tokens to be aligned.SmoothToken[] align(SmoothToken arg1, SmoothToken arg2)
arg1
- The first SmoothToken to be aligned.arg2
- The second SmoothToken to be aligned.public static final double derivativeValue(DoubleToken token, int n)
token
- The token.n
- The order of the desired derivative.public double[] derivativeValues()
public boolean equals(java.lang.Object object)
equals
in class DoubleToken
object
- An object to compare for equality.public SmoothToken extrapolate(Time time)
time
- The time to which to extrapolate this token.public static int getOrderLimit()
setOrderLimit(int)
public Time getTime()
public int hashCode()
hashCode
in class DoubleToken
public boolean isNil()
isNil
in class DoubleToken
NIL
token.public static final int maxOrder(DoubleToken arg1, DoubleToken arg2)
arg1
- The first token.arg2
- The second token.public SmoothToken negate()
public static final int order(DoubleToken token)
token
- The token.public static void setOrderLimit(int maxOrder)
maxOrder
- The maximum order of the token.getOrderLimit()
public static SmoothToken smoothToken(double value)
value
- The value.public static SmoothToken smoothToken(double value, double[] derivatives)
value
- The value.derivatives
- An array containing the first derivative,
the second derivative, etc.public java.lang.String toString()
DoubleToken.doubleValue()
, and
derivatives is an array of doubles.toString
in class DoubleToken
ScalarToken.unitsString()
protected ScalarToken _add(ScalarToken rightArgument)
align(SmoothToken, SmoothToken)
,
and then added. The returned SmoothToken
will have the maximum of the number of derivatives of this token and
the derivatives of the argument, and for derivatives given by both
tokens, the derivative will be the sum of the two derivatives.
The time of the returned token will be the maximum of the time of this
token and the argument._add
in class DoubleToken
rightArgument
- The token to add to this token.protected ScalarToken _divide(ScalarToken divisor)
_divide
in class DoubleToken
divisor
- The token to divide this token by.protected final boolean _isClose(double arg1, double arg2, double epsilon)
arg1
- First argument.arg2
- Second argument.epsilon
- The maximum difference.protected BooleanToken _isCloseTo(ScalarToken rightArgument, double epsilon)
_isCloseTo
in class DoubleToken
rightArgument
- The token to compare to this token.epsilon
- The distance.protected BooleanToken _isLessThan(ScalarToken rightArgument) throws IllegalActionException
_isLessThan
in class DoubleToken
rightArgument
- The token to compare to this token.IllegalActionException
- If this method is not
supported by the derived class.protected ScalarToken _multiply(ScalarToken rightArgument)
_multiply
in class DoubleToken
rightArgument
- The token to multiply this token by.protected static double[] _multiplyPolynomials(double[] p1, double[] p2)
p1
- First polynomial.p2
- Second polynomialprotected ScalarToken _subtract(ScalarToken rightArgument)
_subtract
in class DoubleToken
rightArgument
- The token to subtract from this token.