net.finmath.stochastic.RandomVariableArray Maven / Gradle / Ivy
/* * (c) Copyright Christian P. Fries, Germany. Contact: [email protected]. * * Created on 09.02.2009 */ package net.finmath.stochastic; /** * An array of
but may be instanceofRandomVariable
objects, implementing theRandomVariable
interface. * * The array features a methodgetLevel()
which indicates if the object is an array where elements are themselves arrays. See {@link #getLevel()}. * * All methods inherited fromRandomVariable
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 typeRandomVariable
but not of typeRandomVariableArray
. * If the elements are of typeRandomVariableArray
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() { final RandomVariable element = getElement(0); if(element instanceof RandomVariableArray) { return ((RandomVariableArray)element).getLevel() + 1; } else { return 1; } } default Object toDoubleArray() { if(getLevel() == 1) { final double[] doubleArray = new double[getNumberOfElements()]; for(int i=0; iRandomVariable RandomVariableArray
. * * @param array GivenRandomVariableArray
of the same size() * @return The scalar product of this array and the given array. */ RandomVariable sumProduct(RandomVariableArray array); @Override default RandomVariableArray getConditionalExpectation(final ConditionalExpectationEstimator conditionalExpectationOperator) { return map(new RandomOperator() { @Override public RandomVariable apply(final RandomVariable x) { return conditionalExpectationOperator.getConditionalExpectation(x); } }); } }