All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.stochastic.RandomVariableArray Maven / Gradle / Ivy

Go to download

finmath lib is a Mathematical Finance Library in Java. It provides algorithms and methodologies related to mathematical finance.

The newest version!
/*
 * (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
 *
 * Created on 09.02.2009
 */
package net.finmath.stochastic;

/**
 * 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() {

		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 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(final ConditionalExpectationEstimator conditionalExpectationOperator)
	{
		return map(new RandomOperator() {
			@Override
			public RandomVariable apply(final RandomVariable x) {
				return conditionalExpectationOperator.getConditionalExpectation(x);
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy