public class RandomVariableFromDoubleArray extends Object implements RandomVariable
RandomVariable
is thread safe (and does not mutate the class).
The implementation requires Java 8 or better.Constructor and Description |
---|
RandomVariableFromDoubleArray(double value)
Create a non stochastic random variable, i.e. a constant.
|
RandomVariableFromDoubleArray(double time,
double value)
Create a non stochastic random variable, i.e. a constant.
|
RandomVariableFromDoubleArray(double time,
double[] realisations)
Create a stochastic random variable.
|
RandomVariableFromDoubleArray(double time,
double[] realisations,
int typePriority)
Create a stochastic random variable.
|
RandomVariableFromDoubleArray(double time,
double value,
int typePriority)
Create a non stochastic random variable, i.e. a constant.
|
RandomVariableFromDoubleArray(double time,
int numberOfPath,
double value)
Deprecated.
|
RandomVariableFromDoubleArray(double time,
IntToDoubleFunction realizations,
int size)
Create a stochastic random variable.
|
RandomVariableFromDoubleArray(double time,
IntToDoubleFunction realizations,
int size,
int typePriority)
Create a stochastic random variable.
|
RandomVariableFromDoubleArray(RandomVariable value)
Create a random variable from a given other implementation of
RandomVariable . |
RandomVariableFromDoubleArray(RandomVariable value,
DoubleUnaryOperator function)
Create a random variable by applying a function to a given other implementation of
RandomVariable . |
Modifier and Type | Method and Description |
---|---|
RandomVariable |
abs()
Applies x → Math.abs(x), i.e. x → |x| to this random variable.
|
RandomVariable |
accrue(RandomVariable rate,
double periodLength)
Applies x → x * (1.0 + rate * periodLength) to this random variable.
|
RandomVariable |
add(double value)
Applies x → x + value to this random variable.
|
RandomVariable |
add(RandomVariable randomVariable)
Applies x → x+randomVariable to this random variable.
|
RandomVariable |
addProduct(RandomVariable factor1,
double factor2)
Applies x → x + factor1 * factor2
|
RandomVariable |
addProduct(RandomVariable factor1,
RandomVariable factor2)
Applies x → x + factor1 * factor2
|
RandomVariable |
addRatio(RandomVariable numerator,
RandomVariable denominator)
Applies x → x + numerator / denominator
|
RandomVariable |
addSumProduct(List<RandomVariable> factor1,
List<RandomVariable> factor2)
Applies \( x \mapsto x + \sum_{i=0}^{n-1} factor1_{i} * factor2_{i}
|
RandomVariable |
apply(DoubleBinaryOperator operatorOuter,
DoubleBinaryOperator operatorInner,
RandomVariable argument1,
RandomVariable argument2) |
RandomVariable |
apply(DoubleBinaryOperator operator,
RandomVariable argument)
Applies x → operator(x,y) to this random variable, where x is this random variable and y is a given random variable.
|
RandomVariable |
apply(DoubleTernaryOperator operator,
RandomVariable argument1,
RandomVariable argument2)
Applies x → operator(x,y,z) to this random variable, where x is this random variable and y and z are given random variable.
|
RandomVariable |
apply(DoubleUnaryOperator operator)
Applies x → operator(x) to this random variable.
|
RandomVariable |
average()
Returns a random variable which is deterministic and corresponds
the expectation of this random variable.
|
RandomVariable |
bus(double value) |
RandomVariable |
bus(RandomVariable randomVariable)
Applies x → randomVariable-x to this random variable.
|
RandomVariable |
cache()
Return a cacheable version of this object (often a self-reference).
|
RandomVariable |
cap(double cap)
Applies x → min(x,cap) to this random variable.
|
RandomVariable |
cap(RandomVariable randomVariable)
Applies x → min(x,cap) to this random variable.
|
RandomVariable |
choose(RandomVariable valueIfTriggerNonNegative,
RandomVariable valueIfTriggerNegative)
Applies x → (x ≥ 0 ?
|
RandomVariable |
cos()
Applies x → cos(x) to this random variable.
|
RandomVariable |
discount(RandomVariable rate,
double periodLength)
Applies x → x / (1.0 + rate * periodLength) to this random variable.
|
RandomVariable |
div(double value)
Applies x → x / value to this random variable.
|
RandomVariable |
div(RandomVariable randomVariable)
Applies x → x/randomVariable to this random variable.
|
Double |
doubleValue()
Returns the double value if isDeterministic() is true. otherwise throws an
UnsupportedOperationException . |
boolean |
equals(RandomVariable randomVariable)
Compare this random variable with a given one
|
RandomVariableFromDoubleArray |
exp()
Applies x → exp(x) to this random variable.
|
RandomVariableFromDoubleArray |
expm1()
Applies x → expm1(x) (that is x → exp(x)-1.0) to this random variable.
|
RandomVariable |
floor(double floor)
Applies x → max(x,floor) to this random variable.
|
RandomVariable |
floor(RandomVariable randomVariable)
Applies x → max(x,floor) to this random variable.
|
double |
get(int pathOrState)
Evaluate at a given path or state.
|
double |
getAverage()
Returns the expectation of this random variable.
|
double |
getAverage(RandomVariable probabilities)
Returns the expectation of this random variable for a given probability measure (weight).
|
RandomVariable |
getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)
Returns the conditional expectation using a given conditional expectation estimator.
|
double |
getFiltrationTime()
Returns the filtration time.
|
double[] |
getHistogram(double[] intervalPoints)
Generates a Histogram based on the realizations stored in this random variable.
|
double[][] |
getHistogram(int numberOfPoints,
double standardDeviations)
Generates a histogram based on the realizations stored in this random variable
using interval points calculated from the arguments, see also
RandomVariable.getHistogram(double[]) . |
double |
getMax()
Returns the maximum value attained by this random variable.
|
double |
getMin()
Returns the minimum value attained by this random variable.
|
IntToDoubleFunction |
getOperator()
Returns the operator path → this.get(path) corresponding to this random variable.
|
double |
getQuantile(double quantile)
Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile,
where P denotes the probability measure.
|
double |
getQuantile(double quantile,
RandomVariable probabilities)
Returns the quantile value for this given random variable, i.e., the value x such that P(this < x) = quantile,
where P denotes the probability measure.
|
double |
getQuantileExpectation(double quantileStart,
double quantileEnd)
Returns the expectation over a quantile for this given random variable.
|
double[] |
getRealizations()
Returns a vector representing the realization of this random variable.
|
DoubleStream |
getRealizationsStream()
Returns a stream of doubles corresponding to the realizations of this random variable.
|
double |
getSampleVariance()
Returns the sample variance of this random variable, i.e.,
V * size()/(size()-1) where V = getVariance().
|
double |
getStandardDeviation()
Returns the standard deviation of this random variable, i.e.,
sqrt(V) where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().
|
double |
getStandardDeviation(RandomVariable probabilities)
Returns the standard deviation of this random variable, i.e.,
sqrt(V) where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).
|
double |
getStandardError()
Returns the standard error (discretization error) of this random variable.
|
double |
getStandardError(RandomVariable probabilities)
Returns the standard error (discretization error) of this random variable.
|
int |
getTypePriority()
Returns the type priority.
|
double |
getVariance()
Returns the variance of this random variable, i.e.,
V where V = ((X-m)^2).getAverage() and X = this and m = X.getAverage().
|
double |
getVariance(RandomVariable probabilities)
Returns the variance of this random variable, i.e.,
V where V = ((X-m)^2).getAverage(probabilities) and X = this and m = X.getAverage(probabilities).
|
RandomVariable |
invert()
Applies x → 1/x to this random variable.
|
boolean |
isDeterministic()
Check if this random variable is deterministic in the sense that it is represented by a single double value.
|
RandomVariable |
isNaN()
Applies x → (Double.isNaN(x) ?
|
RandomVariableFromDoubleArray |
log()
Applies x → log(x) to this random variable.
|
RandomVariable |
mult(double value)
Applies x → x * value to this random variable.
|
RandomVariable |
mult(RandomVariable randomVariable)
Applies x → x*randomVariable to this random variable.
|
RandomVariable |
pow(double exponent)
Applies x → pow(x,exponent) to this random variable.
|
RandomVariable |
sin()
Applies x → sin(x) to this random variable.
|
int |
size()
Returns the number of paths or states.
|
RandomVariable |
sqrt()
Applies x → sqrt(x) to this random variable.
|
RandomVariable |
squared()
Applies x → x * x to this random variable.
|
RandomVariable |
sub(double value)
Applies x → x - value to this random variable.
|
RandomVariable |
sub(RandomVariable randomVariable)
Applies x → x-randomVariable to this random variable.
|
RandomVariable |
subRatio(RandomVariable numerator,
RandomVariable denominator)
Applies x → x - numerator / denominator
|
String |
toString() |
RandomVariable |
vid(double value) |
RandomVariable |
vid(RandomVariable randomVariable)
Applies x → randomVariable/x to this random variable.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addSumProduct, getValues
public RandomVariableFromDoubleArray(RandomVariable value)
RandomVariable
.value
- Object implementing RandomVariable
.public RandomVariableFromDoubleArray(double value)
value
- the value, a constant.public RandomVariableFromDoubleArray(RandomVariable value, DoubleUnaryOperator function)
RandomVariable
.value
- Object implementing RandomVariable
.function
- A function mapping double to double.public RandomVariableFromDoubleArray(double time, double value, int typePriority)
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.public RandomVariableFromDoubleArray(double time, double value)
time
- the filtration time, set to 0.0 if not used.value
- the value, a constant.@Deprecated public RandomVariableFromDoubleArray(double time, int numberOfPath, double value)
time
- the filtration time, set to 0.0 if not used.numberOfPath
- The number of paths.value
- the value, a constant.public RandomVariableFromDoubleArray(double time, double[] realisations, int typePriority)
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.public RandomVariableFromDoubleArray(double time, double[] realisations)
time
- the filtration time, set to 0.0 if not used.realisations
- the vector of realizations.public RandomVariableFromDoubleArray(double time, IntToDoubleFunction realizations, int size, int typePriority)
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.public RandomVariableFromDoubleArray(double time, IntToDoubleFunction realizations, int size)
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.public boolean equals(RandomVariable randomVariable)
RandomVariable
equals
in interface RandomVariable
randomVariable
- Random variable to compare with.public double getFiltrationTime()
RandomVariable
getFiltrationTime
in interface RandomVariable
public int getTypePriority()
RandomVariable
getTypePriority
in interface RandomVariable
public double get(int pathOrState)
RandomVariable
get
in interface RandomVariable
pathOrState
- Index of the path or state.public int size()
RandomVariable
size
in interface RandomVariable
public double getMin()
RandomVariable
getMin
in interface RandomVariable
public double getMax()
RandomVariable
getMax
in interface RandomVariable
public double getAverage()
RandomVariable
average().doubleValue()
.getAverage
in interface RandomVariable
public double getAverage(RandomVariable probabilities)
RandomVariable
this.mult(probabilities).getAverage() / probabilities.getAverage()
getAverage
in interface RandomVariable
probabilities
- The probability weights.public double getVariance()
RandomVariable
getVariance
in interface RandomVariable
public double getVariance(RandomVariable probabilities)
RandomVariable
getVariance
in interface RandomVariable
probabilities
- The probability weights.public double getSampleVariance()
RandomVariable
getSampleVariance
in interface RandomVariable
public double getStandardDeviation()
RandomVariable
getStandardDeviation
in interface RandomVariable
public double getStandardDeviation(RandomVariable probabilities)
RandomVariable
getStandardDeviation
in interface RandomVariable
probabilities
- The probability weights.public double getStandardError()
RandomVariable
RandomVariable.getStandardDeviation()
.getStandardError
in interface RandomVariable
public double getStandardError(RandomVariable probabilities)
RandomVariable
RandomVariable.getStandardDeviation(RandomVariable)
.getStandardError
in interface RandomVariable
probabilities
- The probability weights.public double getQuantile(double quantile)
RandomVariable
getQuantile
in interface RandomVariable
quantile
- The quantile level.public double getQuantile(double quantile, RandomVariable probabilities)
RandomVariable
getQuantile
in interface RandomVariable
quantile
- The quantile level.probabilities
- The probability weights.public double getQuantileExpectation(double quantileStart, double quantileEnd)
RandomVariable
getQuantileExpectation
in interface RandomVariable
quantileStart
- Lower bound of the integral.quantileEnd
- Upper bound of the integral.public double[] getHistogram(double[] intervalPoints)
RandomVariable
result
array's length is intervalPoints.length+1
.
possibleValues
, then result = getHistogram(possibleValues)
returns an
array where result[i]
is the relative frequency of occurrence of possibleValues[i]
.
The sum of result[i] over all i is equal to 1, except for uninitialized random
variables where all values are 0.getHistogram
in interface RandomVariable
intervalPoints
- Array of ascending values defining the interval boundaries.public double[][] getHistogram(int numberOfPoints, double standardDeviations)
RandomVariable
RandomVariable.getHistogram(double[])
.
The interval points are
set with equal distance over an the interval of the specified standard deviation.
The interval points used are
x[i] = mean + alpha[i] * standardDeviations * sigma
RandomVariable.getAverage()
,RandomVariable.getStandardDeviation()
.result
is an array of two vectors, where result[0] are the
intervals center points ('anchor points') and result[1] contains the relative frequency for the interval.
The 'anchor point' for the interval (-infinity, x[0]) is x[0] - 1/2 (x[1]-x[0])
and the 'anchor point' for the interval (x[n], infinity) is x[n] + 1/2 (x[n]-x[n-1]).
Here n = numberOfPoints is the number of interval points.getHistogram
in interface RandomVariable
numberOfPoints
- The number of interval points.standardDeviations
- The number of standard deviations defining the discretization radius.RandomVariable.getHistogram(double[])
for the given the interval points. The length of result[0] and result[1] is numberOfPoints+1.public boolean isDeterministic()
RandomVariable
isDeterministic
in interface RandomVariable
public RandomVariable cache()
RandomVariable
cache
in interface RandomVariable
public DoubleStream getRealizationsStream()
RandomVariable
getRealizationsStream
in interface RandomVariable
public double[] getRealizations()
RandomVariable
getRealizations
in interface RandomVariable
public Double doubleValue()
RandomVariable
UnsupportedOperationException
.doubleValue
in interface RandomVariable
UnsupportedOperationException
.public IntToDoubleFunction getOperator()
RandomVariable
getOperator
in interface RandomVariable
public RandomVariable apply(DoubleUnaryOperator operator)
RandomVariable
apply
in interface RandomVariable
operator
- An unary operator/function, mapping double to double.public RandomVariable apply(DoubleBinaryOperator operator, RandomVariable argument)
RandomVariable
apply
in interface RandomVariable
operator
- A binary operator/function, mapping (double,double) to double.argument
- A random variable.public RandomVariable apply(DoubleTernaryOperator operator, RandomVariable argument1, RandomVariable argument2)
RandomVariable
apply
in interface RandomVariable
operator
- A ternary operator/function, mapping (double,double,double) to double.argument1
- A random variable representing y.argument2
- A random variable representing z.public RandomVariable apply(DoubleBinaryOperator operatorOuter, DoubleBinaryOperator operatorInner, RandomVariable argument1, RandomVariable argument2)
public RandomVariable cap(double cap)
RandomVariable
cap
in interface RandomVariable
cap
- The cap.public RandomVariable floor(double floor)
RandomVariable
floor
in interface RandomVariable
floor
- The floor.public RandomVariable add(double value)
RandomVariable
add
in interface RandomVariable
value
- The value to add.public RandomVariable sub(double value)
RandomVariable
sub
in interface RandomVariable
value
- The value to subtract.public RandomVariable bus(double value)
public RandomVariable mult(double value)
RandomVariable
mult
in interface RandomVariable
value
- The value to multiply.public RandomVariable div(double value)
RandomVariable
div
in interface RandomVariable
value
- The value to divide.public RandomVariable vid(double value)
public RandomVariable pow(double exponent)
RandomVariable
pow
in interface RandomVariable
exponent
- The exponent.public RandomVariable average()
RandomVariable
average
in interface RandomVariable
public RandomVariable getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)
RandomVariable
getConditionalExpectation
in interface RandomVariable
conditionalExpectationOperator
- A given conditional expectation estimator.public RandomVariable squared()
RandomVariable
squared
in interface RandomVariable
public RandomVariable sqrt()
RandomVariable
sqrt
in interface RandomVariable
public RandomVariable invert()
RandomVariable
invert
in interface RandomVariable
public RandomVariable abs()
RandomVariable
abs
in interface RandomVariable
public RandomVariableFromDoubleArray exp()
RandomVariable
exp
in interface RandomVariable
public RandomVariableFromDoubleArray expm1()
RandomVariable
expm1
in interface RandomVariable
public RandomVariableFromDoubleArray log()
RandomVariable
log
in interface RandomVariable
public RandomVariable sin()
RandomVariable
sin
in interface RandomVariable
public RandomVariable cos()
RandomVariable
cos
in interface RandomVariable
public RandomVariable add(RandomVariable randomVariable)
RandomVariable
add
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable sub(RandomVariable randomVariable)
RandomVariable
sub
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable bus(RandomVariable randomVariable)
RandomVariable
bus
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable mult(RandomVariable randomVariable)
RandomVariable
mult
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable div(RandomVariable randomVariable)
RandomVariable
div
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable vid(RandomVariable randomVariable)
RandomVariable
vid
in interface RandomVariable
randomVariable
- A random variable (compatible with this random variable).public RandomVariable cap(RandomVariable randomVariable)
RandomVariable
cap
in interface RandomVariable
randomVariable
- The cap. A random variable (compatible with this random variable).public RandomVariable floor(RandomVariable randomVariable)
RandomVariable
floor
in interface RandomVariable
randomVariable
- The floor. A random variable (compatible with this random variable).public RandomVariable accrue(RandomVariable rate, double periodLength)
RandomVariable
accrue
in interface RandomVariable
rate
- The accruing rate. A random variable (compatible with this random variable).periodLength
- The period lengthpublic RandomVariable discount(RandomVariable rate, double periodLength)
RandomVariable
discount
in interface RandomVariable
rate
- The discounting rate. A random variable (compatible with this random variable).periodLength
- The period lengthpublic RandomVariable choose(RandomVariable valueIfTriggerNonNegative, RandomVariable valueIfTriggerNegative)
RandomVariable
choose
in interface RandomVariable
valueIfTriggerNonNegative
- The value used if this is greater or equal 0valueIfTriggerNegative
- The value used if the this is less than 0public RandomVariable addProduct(RandomVariable factor1, double factor2)
RandomVariable
addProduct
in interface RandomVariable
factor1
- The factor 1. A random variable (compatible with this random variable).factor2
- The factor 2.public RandomVariable addProduct(RandomVariable factor1, RandomVariable factor2)
RandomVariable
addProduct
in interface RandomVariable
factor1
- The factor 1. A random variable (compatible with this random variable).factor2
- The factor 2. A random variable (compatible with this random variable).public RandomVariable addSumProduct(List<RandomVariable> factor1, List<RandomVariable> factor2)
RandomVariable
addSumProduct
in interface RandomVariable
factor1
- The factor 1. A list of random variables (compatible with this random variable).factor2
- The factor 2. A list of random variables (compatible with this random variable).public RandomVariable addRatio(RandomVariable numerator, RandomVariable denominator)
RandomVariable
addRatio
in interface RandomVariable
numerator
- The numerator of the ratio to add. A random variable (compatible with this random variable).denominator
- The denominator of the ratio to add. A random variable (compatible with this random variable).public RandomVariable subRatio(RandomVariable numerator, RandomVariable denominator)
RandomVariable
subRatio
in interface RandomVariable
numerator
- The numerator of the ratio to sub. A random variable (compatible with this random variable).denominator
- The denominator of the ratio to sub. A random variable (compatible with this random variable).public RandomVariable isNaN()
RandomVariable
isNaN
in interface RandomVariable
Copyright © 2020. All rights reserved.