- 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 interfaceRandomVariableis thread safe (and does not mutate the class). This implementation uses floats for the realizations on a OpenCL device. There is a CPU implementation inRandomVariableFromFloatArraywhich 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:
equalsin interfaceRandomVariable
-
getFiltrationTime
public double getFiltrationTime()
- Specified by:
getFiltrationTimein interfaceRandomVariable
-
getTypePriority
public int getTypePriority()
- Specified by:
getTypePriorityin interfaceRandomVariable
-
get
public double get(int pathOrState)
- Specified by:
getin interfaceRandomVariable
-
size
public int size()
- Specified by:
sizein interfaceRandomVariable
-
getMin
public double getMin()
- Specified by:
getMinin interfaceRandomVariable
-
getMax
public double getMax()
- Specified by:
getMaxin interfaceRandomVariable
-
getAverage
public double getAverage()
- Specified by:
getAveragein interfaceRandomVariable
-
getAverage
public double getAverage(RandomVariable probabilities)
- Specified by:
getAveragein interfaceRandomVariable
-
getVariance
public double getVariance()
- Specified by:
getVariancein interfaceRandomVariable
-
getVariance
public double getVariance(RandomVariable probabilities)
- Specified by:
getVariancein interfaceRandomVariable
-
getSampleVariance
public double getSampleVariance()
- Specified by:
getSampleVariancein interfaceRandomVariable
-
getStandardDeviation
public double getStandardDeviation()
- Specified by:
getStandardDeviationin interfaceRandomVariable
-
getStandardDeviation
public double getStandardDeviation(RandomVariable probabilities)
- Specified by:
getStandardDeviationin interfaceRandomVariable
-
getStandardError
public double getStandardError()
- Specified by:
getStandardErrorin interfaceRandomVariable
-
getStandardError
public double getStandardError(RandomVariable probabilities)
- Specified by:
getStandardErrorin interfaceRandomVariable
-
getQuantile
public double getQuantile(double quantile)
- Specified by:
getQuantilein interfaceRandomVariable
-
getQuantile
public double getQuantile(double quantile, RandomVariable probabilities)- Specified by:
getQuantilein interfaceRandomVariable
-
getQuantileExpectation
public double getQuantileExpectation(double quantileStart, double quantileEnd)- Specified by:
getQuantileExpectationin interfaceRandomVariable
-
getHistogram
public double[] getHistogram(double[] intervalPoints)
- Specified by:
getHistogramin interfaceRandomVariable
-
getHistogram
public double[][] getHistogram(int numberOfPoints, double standardDeviations)- Specified by:
getHistogramin interfaceRandomVariable
-
isDeterministic
public boolean isDeterministic()
- Specified by:
isDeterministicin interfaceRandomVariable
-
cache
public RandomVariable cache()
- Specified by:
cachein interfaceRandomVariable
-
getRealizations
public double[] getRealizations()
- Specified by:
getRealizationsin interfaceRandomVariable
-
doubleValue
public Double doubleValue()
- Specified by:
doubleValuein interfaceRandomVariable
-
getOperator
public IntToDoubleFunction getOperator()
- Specified by:
getOperatorin interfaceRandomVariable
-
getRealizationsStream
public DoubleStream getRealizationsStream()
- Specified by:
getRealizationsStreamin interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleUnaryOperator function)
- Specified by:
applyin interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleBinaryOperator operator, RandomVariable argument)
- Specified by:
applyin interfaceRandomVariable
-
apply
public RandomVariable apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2)
- Specified by:
applyin interfaceRandomVariable
-
cap
public RandomVariable cap(double cap)
- Specified by:
capin interfaceRandomVariable
-
floor
public RandomVariable floor(double floor)
- Specified by:
floorin interfaceRandomVariable
-
add
public RandomVariable add(double value)
- Specified by:
addin interfaceRandomVariable
-
sub
public RandomVariable sub(double value)
- Specified by:
subin interfaceRandomVariable
-
bus
public RandomVariable bus(double value)
- Specified by:
busin interfaceRandomVariable
-
mult
public RandomVariable mult(double value)
- Specified by:
multin interfaceRandomVariable
-
div
public RandomVariable div(double value)
- Specified by:
divin interfaceRandomVariable
-
vid
public RandomVariable vid(double value)
- Specified by:
vidin interfaceRandomVariable
-
pow
public RandomVariable pow(double exponent)
- Specified by:
powin interfaceRandomVariable
-
average
public RandomVariable average()
- Specified by:
averagein interfaceRandomVariable
-
squared
public RandomVariable squared()
- Specified by:
squaredin interfaceRandomVariable
-
sqrt
public RandomVariable sqrt()
- Specified by:
sqrtin interfaceRandomVariable
-
invert
public RandomVariable invert()
- Specified by:
invertin interfaceRandomVariable
-
abs
public RandomVariable abs()
- Specified by:
absin interfaceRandomVariable
-
exp
public RandomVariable exp()
- Specified by:
expin interfaceRandomVariable
-
log
public RandomVariable log()
- Specified by:
login interfaceRandomVariable
-
sin
public RandomVariable sin()
- Specified by:
sinin interfaceRandomVariable
-
cos
public RandomVariable cos()
- Specified by:
cosin interfaceRandomVariable
-
add
public RandomVariable add(RandomVariable randomVariable)
- Specified by:
addin interfaceRandomVariable
-
sub
public RandomVariable sub(RandomVariable randomVariable)
- Specified by:
subin interfaceRandomVariable
-
bus
public RandomVariable bus(RandomVariable randomVariable)
- Specified by:
busin interfaceRandomVariable
-
mult
public RandomVariable mult(RandomVariable randomVariable)
- Specified by:
multin interfaceRandomVariable
-
div
public RandomVariable div(RandomVariable randomVariable)
- Specified by:
divin interfaceRandomVariable
-
vid
public RandomVariable vid(RandomVariable randomVariable)
- Specified by:
vidin interfaceRandomVariable
-
cap
public RandomVariable cap(RandomVariable randomVariable)
- Specified by:
capin interfaceRandomVariable
-
floor
public RandomVariable floor(RandomVariable randomVariable)
- Specified by:
floorin interfaceRandomVariable
-
accrue
public RandomVariable accrue(RandomVariable rate, double periodLength)
- Specified by:
accruein interfaceRandomVariable
-
discount
public RandomVariable discount(RandomVariable rate, double periodLength)
- Specified by:
discountin interfaceRandomVariable
-
choose
public RandomVariable choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative)
- Specified by:
choosein interfaceRandomVariable
-
addProduct
public RandomVariable addProduct(RandomVariable factor1, double factor2)
- Specified by:
addProductin interfaceRandomVariable
-
addProduct
public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2)
- Specified by:
addProductin interfaceRandomVariable
-
addRatio
public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator)
- Specified by:
addRatioin interfaceRandomVariable
-
subRatio
public RandomVariable subRatio(RandomVariable numerator, RandomVariable denominator)
- Specified by:
subRatioin interfaceRandomVariable
-
isNaN
public RandomVariable isNaN()
- Specified by:
isNaNin interfaceRandomVariable
-
-