- java.lang.Object
-
- net.finmath.opencl.montecarlo.RandomVariableOpenCL
-
- All Implemented Interfaces:
Serializable
,RandomVariable
public class RandomVariableOpenCL extends Object implements RandomVariable
This class 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 on a OpenCL device. There is a CPU implementation inRandomVariableFromFloatArray
which give exactly the same results for all methods (checked by unit test). Configuration The class can be configured with system property to use a chosen OpenCL device. The properties are:- "net.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceType"
- with possible values "GPU", "CPU", "ALL"
- "net.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceIndex"
- being an integer. For a positive values, the device with the corresponding index is used. For a negative value the device with the index numberOfDevices - deviceIndex is used. That is, a value of -1 selects the last device in the list of devices. To select the dedicated GPU in a MacBook Pro you may use "GPU" with index "-1".
- Version:
- 2.1
- Author:
- Christian Fries
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RandomVariableOpenCL(double value)
Create a non stochastic random variable, i.e. a constant.RandomVariableOpenCL(double time, double value)
Create a non stochastic random variable, i.e. a constant.RandomVariableOpenCL(double time, double[] realisations)
Create a stochastic random variable.RandomVariableOpenCL(double time, double value, int typePriority)
Create a non stochastic random variable, i.e. a constant.RandomVariableOpenCL(double time, float[] realisations)
Create a stochastic random variable.RandomVariableOpenCL(double time, float[] realisations, int typePriority)
Create a stochastic random variable.RandomVariableOpenCL(float[] realisations)
Create a stochastic random variable.
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.finmath.stochastic.RandomVariable
addSumProduct, addSumProduct, appy, covariance, expectation, expm1, getConditionalExpectation, getValues, variance
-
-
-
-
Constructor Detail
-
RandomVariableOpenCL
public RandomVariableOpenCL(double value)
Create a non stochastic random variable, i.e. a constant.- Parameters:
value
- the value, a constant.
-
RandomVariableOpenCL
public RandomVariableOpenCL(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.
-
RandomVariableOpenCL
public RandomVariableOpenCL(double time, float[] realisations, int typePriority)
Create a stochastic random variable.- 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.
-
RandomVariableOpenCL
public RandomVariableOpenCL(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.
-
RandomVariableOpenCL
public RandomVariableOpenCL(double time, float[] realisations)
Create a stochastic random variable.- Parameters:
time
- the filtration time, set to 0.0 if not used.realisations
- the vector of realizations.
-
RandomVariableOpenCL
public RandomVariableOpenCL(double time, double[] realisations)
Create a stochastic random variable.- Parameters:
time
- the filtration time, set to 0.0 if not used.realisations
- the vector of realizations.
-
RandomVariableOpenCL
public RandomVariableOpenCL(float[] realisations)
Create a stochastic random variable.- Parameters:
realisations
- the vector of realizations.
-
-
Method Detail
-
of
public static RandomVariableOpenCL of(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.- Returns:
- A new instance of RandomVariableOpenCL with a constant value.
-
getDevicePointer
public static net.finmath.opencl.montecarlo.RandomVariableOpenCL.DevicePointerReference getDevicePointer(long size)
-
clean
public static void clean()
-
purge
public static void purge()
-
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
-
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
-
getRealizationsStream
public DoubleStream getRealizationsStream()
- Specified by:
getRealizationsStream
in interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleUnaryOperator function)
- 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
-
bus
public RandomVariable bus(double value)
- Specified by:
bus
in interfaceRandomVariable
-
mult
public RandomVariable mult(double value)
- Specified by:
mult
in interfaceRandomVariable
-
div
public RandomVariable div(double value)
- Specified by:
div
in interfaceRandomVariable
-
vid
public RandomVariable vid(double value)
- Specified by:
vid
in interfaceRandomVariable
-
pow
public RandomVariable pow(double exponent)
- Specified by:
pow
in interfaceRandomVariable
-
average
public RandomVariable average()
- Specified by:
average
in interfaceRandomVariable
-
squared
public RandomVariable squared()
- Specified by:
squared
in interfaceRandomVariable
-
sqrt
public RandomVariable sqrt()
- Specified by:
sqrt
in interfaceRandomVariable
-
invert
public RandomVariable invert()
- Specified by:
invert
in interfaceRandomVariable
-
abs
public RandomVariable abs()
- Specified by:
abs
in interfaceRandomVariable
-
exp
public RandomVariable exp()
- Specified by:
exp
in interfaceRandomVariable
-
log
public RandomVariable 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
-
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
-
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
-
-