net.finmath.stochastic.RandomVariableArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of finmath-lib Show documentation
Show all versions of finmath-lib Show documentation
finmath lib is a Mathematical Finance Library in Java.
It provides algorithms and methodologies related to mathematical finance.
/*
* (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
*
* Created on 09.02.2009
*/
package net.finmath.stochastic;
import java.util.function.Function;
/**
* An array of RandomVariable
objects, implementing the RandomVariable
interface.
*
* The array features a method getLevel()
which indicates if the object is an array where elements are themselves arrays. See {@link #getLevel()}.
*
* All methods inherited from RandomVariable
act element wise on the vector elements getElement(int) and return
* corresponding RandomVariableArray having the same level.
*
* In addition methods are provided that reduce the level by one, like the scalar product, see {@link #sumProduct(RandomVariableArray)}.
*
* @author Christian Fries
*/
public interface RandomVariableArray extends RandomVariable {
int getNumberOfElements();
RandomVariable getElement(int index);
/**
* Returns the level of the array
*
* The level of the array is given by 1 if the elements are of type RandomVariable
but not of type RandomVariableArray
.
* If the elements are of type RandomVariableArray
the level of this array is 1 plus the level of its elements.
* Note: the elements are required to be of the the same level.
*
* @return The level of the array.
*/
default int getLevel() {
RandomVariable element = getElement(0);
if(element instanceof RandomVariableArray) {
return ((RandomVariableArray)element).getLevel() + 1;
}
else {
return 1;
}
}
default Object toDoubleArray() {
if(getLevel() == 1) {
double[] doubleArray = new double[getNumberOfElements()];
for(int i=0; i operator);
/**
* Components wise product followed by sum of all elements.
* Reduction of getLevel by 1.
* Note: The return value is for sure instanceof RandomVariable
but may be instanceof RandomVariableArray
.
*
* @param array Given RandomVariableArray
of the same size()
* @return The scalar product of this array and the given array.
*/
RandomVariable sumProduct(RandomVariableArray array);
@Override
default RandomVariableArray getConditionalExpectation(ConditionalExpectationEstimator conditionalExpectationOperator)
{
return map(x -> conditionalExpectationOperator.getConditionalExpectation(x));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy