- java.lang.Object
-
- net.finmath.cuda.cpu.montecarlo.RandomVariableFromFloatArray
-
- All Implemented Interfaces:
Serializable
,RandomVariable
public class RandomVariableFromFloatArray extends Object implements RandomVariable
The class RandomVariableFromFloatArray represents a random variable being the evaluation of a stochastic process at a certain time within a Monte-Carlo simulation. It is thus essentially a vector of floating point numbers - the realizations - together with a double - the time. The index of the vector represents path. The class may also be used for non-stochastic quantities which may potentially be stochastic (e.g. volatility). If only non-stochastic random variables are involved in an operation the class uses optimized code. Accesses performed exclusively through the interfaceRandomVariable
is thread safe (and does not mutate the class). This implementation uses floats for the realizations (consuming less memory compared to using doubles). However, the calculation of the average is performed using double precision.- Version:
- 1.8
- Author:
- Christian Fries
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RandomVariableFromFloatArray(double value)
Create a non stochastic random variable, i.e. a constant.RandomVariableFromFloatArray(double time, double value)
Create a non stochastic random variable, i.e. a constant.RandomVariableFromFloatArray(double time, double[] realisations)
Create a stochastic random variable.RandomVariableFromFloatArray(double time, double value, int typePriority)
Create a non stochastic random variable, i.e. a constant.RandomVariableFromFloatArray(double time, float[] newRealizations)
Create a non stochastic random variable, i.e. a constant.RandomVariableFromFloatArray(double time, float[] realisations, int typePriority)
Create a stochastic random variable.RandomVariableFromFloatArray(double time, int numberOfPath, double value)
Deprecated.RandomVariableFromFloatArray(double time, IntToDoubleFunction realizations, int size)
Create a stochastic random variable.RandomVariableFromFloatArray(double time, IntToDoubleFunction realizations, int size, int typePriority)
Create a stochastic random variable.RandomVariableFromFloatArray(RandomVariable value)
Create a random variable from a given other implementation ofRandomVariable
.RandomVariableFromFloatArray(RandomVariable value, DoubleUnaryOperator function)
Create a random variable by applying a function to a given other implementation ofRandomVariable
.
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.finmath.stochastic.RandomVariable
addSumProduct, appy, bus, covariance, expectation, expm1, getValues, variance, vid
-
-
-
-
Constructor Detail
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(RandomVariable value)
Create a random variable from a given other implementation ofRandomVariable
.- Parameters:
value
- Object implementingRandomVariable
.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double value)
Create a non stochastic random variable, i.e. a constant.- Parameters:
value
- the value, a constant.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(RandomVariable value, DoubleUnaryOperator function)
Create a random variable by applying a function to a given other implementation ofRandomVariable
.- Parameters:
value
- Object implementingRandomVariable
.function
- A function mapping double to double.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, double value, int typePriority)
Create a non stochastic random variable, i.e. a constant.- Parameters:
time
- the filtration time, set to 0.0 if not used.value
- the value, a constant.typePriority
- The priority of this type in construction of result types. See "operator type priority" for details.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, double value)
Create a non stochastic random variable, i.e. a constant.- Parameters:
time
- the filtration time, set to 0.0 if not used.value
- the value, a constant.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, float[] newRealizations)
Create a non stochastic random variable, i.e. a constant.- Parameters:
time
- the filtration time, set to 0.0 if not used.newRealizations
- the value, a constant.
-
RandomVariableFromFloatArray
@Deprecated public RandomVariableFromFloatArray(double time, int numberOfPath, double value)
Deprecated.Create a non stochastic random variable, i.e. a constant.- Parameters:
time
- the filtration time, set to 0.0 if not used.numberOfPath
- The number of paths.value
- the value, a constant.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, float[] realisations, int typePriority)
Create a stochastic random variable. Important: The realizations array is not cloned (no defensive copy is made).- Parameters:
time
- the filtration time, set to 0.0 if not used.realisations
- the vector of realizations.typePriority
- The priority of this type in construction of result types. See "operator type priority" for details.- To dos:
- A future version should perform a defensive copy.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, double[] realisations)
Create a stochastic random variable. Important: The realizations array is not cloned (not defensive copy is made).- Parameters:
time
- the filtration time, set to 0.0 if not used.realisations
- the vector of realizations.- To dos:
- A future version should perform a defensive copy.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, IntToDoubleFunction realizations, int size, int typePriority)
Create a stochastic random variable.- Parameters:
time
- the filtration time, set to 0.0 if not used.realizations
- A map mapping integer (path or state) to double, representing this random variable.size
- The size, i.e., number of paths.typePriority
- The priority of this type in construction of result types. See "operator type priority" for details.
-
RandomVariableFromFloatArray
public RandomVariableFromFloatArray(double time, IntToDoubleFunction realizations, int size)
Create a stochastic random variable.- Parameters:
time
- the filtration time, set to 0.0 if not used.realizations
- A map mapping integer (path or state) to double, representing this random variable.size
- The size, i.e., number of paths.
-
-
Method Detail
-
equals
public boolean equals(RandomVariable randomVariable)
- Specified by:
equals
in interfaceRandomVariable
-
getFiltrationTime
public double getFiltrationTime()
- Specified by:
getFiltrationTime
in interfaceRandomVariable
-
getTypePriority
public int getTypePriority()
- Specified by:
getTypePriority
in interfaceRandomVariable
-
get
public double get(int pathOrState)
- Specified by:
get
in interfaceRandomVariable
-
size
public int size()
- Specified by:
size
in interfaceRandomVariable
-
getMin
public double getMin()
- Specified by:
getMin
in interfaceRandomVariable
-
getMax
public double getMax()
- Specified by:
getMax
in interfaceRandomVariable
-
getAverage
public double getAverage()
- Specified by:
getAverage
in interfaceRandomVariable
-
getAverage
public double getAverage(RandomVariable probabilities)
- Specified by:
getAverage
in interfaceRandomVariable
-
getVariance
public double getVariance()
- Specified by:
getVariance
in interfaceRandomVariable
-
getVariance
public double getVariance(RandomVariable probabilities)
- Specified by:
getVariance
in interfaceRandomVariable
-
getSampleVariance
public double getSampleVariance()
- Specified by:
getSampleVariance
in interfaceRandomVariable
-
getStandardDeviation
public double getStandardDeviation()
- Specified by:
getStandardDeviation
in interfaceRandomVariable
-
getStandardDeviation
public double getStandardDeviation(RandomVariable probabilities)
- Specified by:
getStandardDeviation
in interfaceRandomVariable
-
getStandardError
public double getStandardError()
- Specified by:
getStandardError
in interfaceRandomVariable
-
getStandardError
public double getStandardError(RandomVariable probabilities)
- Specified by:
getStandardError
in interfaceRandomVariable
-
getQuantile
public double getQuantile(double quantile)
- Specified by:
getQuantile
in interfaceRandomVariable
-
getQuantile
public double getQuantile(double quantile, RandomVariable probabilities)
- Specified by:
getQuantile
in interfaceRandomVariable
-
getQuantileExpectation
public double getQuantileExpectation(double quantileStart, double quantileEnd)
- Specified by:
getQuantileExpectation
in interfaceRandomVariable
-
getHistogram
public double[] getHistogram(double[] intervalPoints)
- Specified by:
getHistogram
in interfaceRandomVariable
-
getHistogram
public double[][] getHistogram(int numberOfPoints, double standardDeviations)
- Specified by:
getHistogram
in interfaceRandomVariable
-
isDeterministic
public boolean isDeterministic()
- Specified by:
isDeterministic
in interfaceRandomVariable
-
cache
public RandomVariable cache()
- Specified by:
cache
in interfaceRandomVariable
-
getRealizationsStream
public DoubleStream getRealizationsStream()
- Specified by:
getRealizationsStream
in interfaceRandomVariable
-
getRealizations
public double[] getRealizations()
- Specified by:
getRealizations
in interfaceRandomVariable
-
doubleValue
public Double doubleValue()
- Specified by:
doubleValue
in interfaceRandomVariable
-
getOperator
public IntToDoubleFunction getOperator()
- Specified by:
getOperator
in interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleUnaryOperator operator)
- Specified by:
apply
in interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleBinaryOperator operator, RandomVariable argument)
- Specified by:
apply
in interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2)
- Specified by:
apply
in interfaceRandomVariable
-
cap
public RandomVariable cap(double cap)
- Specified by:
cap
in interfaceRandomVariable
-
floor
public RandomVariable floor(double floor)
- Specified by:
floor
in interfaceRandomVariable
-
add
public RandomVariable add(double value)
- Specified by:
add
in interfaceRandomVariable
-
sub
public RandomVariable sub(double value)
- Specified by:
sub
in interfaceRandomVariable
-
mult
public RandomVariable mult(double value)
- Specified by:
mult
in interfaceRandomVariable
-
div
public RandomVariable div(double value)
- Specified by:
div
in interfaceRandomVariable
-
pow
public RandomVariable pow(double exponent)
- Specified by:
pow
in interfaceRandomVariable
-
average
public RandomVariable average()
- Specified by:
average
in interfaceRandomVariable
-
getConditionalExpectation
public RandomVariable getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)
- Specified by:
getConditionalExpectation
in interfaceRandomVariable
-
squared
public RandomVariable squared()
- Specified by:
squared
in interfaceRandomVariable
-
sqrt
public RandomVariable sqrt()
- Specified by:
sqrt
in interfaceRandomVariable
-
exp
public RandomVariableFromFloatArray exp()
- Specified by:
exp
in interfaceRandomVariable
-
log
public RandomVariableFromFloatArray log()
- Specified by:
log
in interfaceRandomVariable
-
sin
public RandomVariable sin()
- Specified by:
sin
in interfaceRandomVariable
-
cos
public RandomVariable cos()
- Specified by:
cos
in interfaceRandomVariable
-
add
public RandomVariable add(RandomVariable randomVariable)
- Specified by:
add
in interfaceRandomVariable
-
sub
public RandomVariable sub(RandomVariable randomVariable)
- Specified by:
sub
in interfaceRandomVariable
-
bus
public RandomVariable bus(RandomVariable randomVariable)
- Specified by:
bus
in interfaceRandomVariable
-
mult
public RandomVariable mult(RandomVariable randomVariable)
- Specified by:
mult
in interfaceRandomVariable
-
div
public RandomVariable div(RandomVariable randomVariable)
- Specified by:
div
in interfaceRandomVariable
-
vid
public RandomVariable vid(RandomVariable randomVariable)
- Specified by:
vid
in interfaceRandomVariable
-
cap
public RandomVariable cap(RandomVariable randomVariable)
- Specified by:
cap
in interfaceRandomVariable
-
floor
public RandomVariable floor(RandomVariable randomVariable)
- Specified by:
floor
in interfaceRandomVariable
-
accrue
public RandomVariable accrue(RandomVariable rate, double periodLength)
- Specified by:
accrue
in interfaceRandomVariable
-
discount
public RandomVariable discount(RandomVariable rate, double periodLength)
- Specified by:
discount
in interfaceRandomVariable
-
choose
public RandomVariable choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative)
- Specified by:
choose
in interfaceRandomVariable
-
invert
public RandomVariable invert()
- Specified by:
invert
in interfaceRandomVariable
-
abs
public RandomVariable abs()
- Specified by:
abs
in interfaceRandomVariable
-
addProduct
public RandomVariable addProduct(RandomVariable factor1, double factor2)
- Specified by:
addProduct
in interfaceRandomVariable
-
addProduct
public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2)
- Specified by:
addProduct
in interfaceRandomVariable
-
addSumProduct
public RandomVariable addSumProduct(List<RandomVariable> factor1, List<RandomVariable> factor2)
- Specified by:
addSumProduct
in interfaceRandomVariable
-
addRatio
public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator)
- Specified by:
addRatio
in interfaceRandomVariable
-
subRatio
public RandomVariable subRatio(RandomVariable numerator, RandomVariable denominator)
- Specified by:
subRatio
in interfaceRandomVariable
-
isNaN
public RandomVariable isNaN()
- Specified by:
isNaN
in interfaceRandomVariable
-
-