Module net.finmath.lib
Interface RandomVariableDifferentiable
- All Superinterfaces:
RandomVariable
,Serializable
- All Known Implementing Classes:
RandomVariableDifferentiableAAD
,RandomVariableDifferentiableAD
Interface providing additional methods for
random variable implementing
RandomVariable
allowing automatic differentiation.
The interface will introduce three additional methods:
Long getID()
and
Map<Long, RandomVariable> getGradient()
and
Map<Long, RandomVariable> getTangents()
.
The method getGradient
will return a map providing the first order
differentiation of the given random variable (this) with respect to
all its input RandomVariableDifferentiable
s.
The method getTangents
will return a map providing the first order
differentiation of all dependent random variables with respect to the
given random variable (this).
To get the differentiation dY/dX of Y with respect to a specific object X using backward mode (getGradient) use
Map gradient = Y.getGradient();
RandomVariable derivative = Y.get(X.getID());
To get the differentiation dY/dX of Y with respect to a specific object X using forward mode (getTanget) use
Map tangent = X.getTangent();
RandomVariable derivative = X.get(Y.getID());
Note: Some implementations may allow limit the result of the gradient to leave nodes or the result of the tangent to terminal nodes.- Version:
- 1.0
- Author:
- Christian Fries
-
Method Summary
Modifier and TypeMethodDescriptiondefault RandomVariableDifferentiable
Returns a clone of this differentiable random variable with a new ID.default Map<Long,RandomVariable>
Returns the gradient of this random variable with respect to all its leaf nodes.getGradient(Set<Long> independentIDs)
Returns the gradient of this random variable with respect to the given IDs.getID()
A unique id for this random variable.default Map<Long,RandomVariable>
Returns the tangents of this random variable with respect to all its dependent nodes.getTangents(Set<Long> dependentIDs)
Returns the tangents of this random variable with respect to the given dependent node IDs (if dependent).Methods inherited from interface net.finmath.stochastic.RandomVariable
abs, accrue, add, add, addProduct, addProduct, addRatio, addSumProduct, addSumProduct, apply, apply, apply, appy, average, bus, bus, cache, cap, cap, choose, cos, covariance, discount, div, div, doubleValue, equals, exp, expectation, expm1, floor, floor, get, getAverage, getAverage, getConditionalExpectation, getFiltrationTime, getHistogram, getHistogram, getMax, getMin, getOperator, getQuantile, getQuantile, getQuantileExpectation, getRealizations, getRealizationsStream, getSampleVariance, getStandardDeviation, getStandardDeviation, getStandardError, getStandardError, getTypePriority, getValues, getVariance, getVariance, invert, isDeterministic, isNaN, log, mult, mult, pow, sin, size, sqrt, squared, sub, sub, subRatio, variance, vid, vid
-
Method Details
-
getID
Long getID()A unique id for this random variable. Will be used ingetGradient
.- Returns:
- The id for this random variable.
-
getGradient
Returns the gradient of this random variable with respect to all its leaf nodes. The method calculates the map \( v \mapsto \frac{d u}{d v} \) where \( u \) denotesthis
.- Returns:
- The gradient map.
-
getGradient
Returns the gradient of this random variable with respect to the given IDs. The method calculates the map \( v \mapsto \frac{d u}{d v} \) where \( u \) denotesthis
.- Parameters:
independentIDs
-Set
of IDs of random variables \( v \) with respect to which the gradients \( \frac{d u}{d v} \) will be calculated. If null, derivatives w.r.t. all known independents are returned.- Returns:
- The gradient map.
-
getTangents
Returns the tangents of this random variable with respect to all its dependent nodes. The method calculated the map \( u \mapsto \frac{d u}{d v} \) where \( v \) denotesthis
.- Returns:
- The map of all tangents .
-
getTangents
Returns the tangents of this random variable with respect to the given dependent node IDs (if dependent). The method calculated the map \( u \mapsto \frac{d u}{d v} \) where \( v \) denotesthis
.- Parameters:
dependentIDs
-Set
of IDs of random variables \( u \) with respect to which the differentials \( \frac{d u}{d v} \) will be calculated. If null, derivatives w.r.t. all known dependents are returned.- Returns:
- The map of differentials.
-
getCloneIndependent
Returns a clone of this differentiable random variable with a new ID. This implies that the random variable is a leaf node and independent from all previous calculations.- Returns:
- A clone of this differentiable random variable with a new ID.
-