<commit_before>/**
 * 
 */
package net.finmath.montecarlo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.math3.analysis.UnivariateFunction;

import net.finmath.stochastic.RandomVariableInterface;

/**
 * {@link RandomVariableInterface} having the feature to calculate the backward algorithmic differentiation.
 * 
 * For this class has a static {@link ArrayList} saving all instances of the class that are produced over time.
 * Hence the class does not have a {@link public} constructor! 
 * 
 * In order to initialize a instance of this class, please use the {@link static} method {@link RandomVariableAAD.constructNewAADRandomVariable}!
 * 
 * @author <NAME>
 * @version 1.0
 */
public class RandomVariableAAD implements RandomVariableInterface {

	private static final long serialVersionUID = 2459373647785530657L;

	/* static elements of the class are shared between all members */
	private static ArrayList<RandomVariableAAD> arrayListOfAllAADRandomVariables = new ArrayList<>();
	private static int indexOfNextRandomVariable = 0;
	private static enum OperatorType {
		ADD, MULT, DIV, SUB, SQUARED, SQRT, LOG, SIN, COS, EXP, INVERT, CAP, FLOOR, ABS, 
		ADDPRODUCT, ADDRATIO, SUBRATIO, BARRIER, DISCOUNT, ACCURUE, POW, AVERAGE, VARIANCE, 
		STDEV, MIN, MAX, STDERROR, SVARIANCE
	}

	/* index of corresponding random variable in the static array list*/
	private final RandomVariableInterface ownRandomVariable;
	private final int ownIndexInList;

	/* this could maybe be outsourced to own class ParentElement */
	private final int[] parentIndices;
	private final OperatorType parentOperator;
	private ArrayList<Integer> childrenIndices;
	private boolean isConstant;

	/**
	 * @param indexOfRandomVariable
	 * @param parentRandomVariables
	 * @param parentOperator
	 * @param isConstant
	 */
	private RandomVariableAAD(int ownIndexInList, RandomVariableInterface ownRandomVariable, 
			int[] parentIndices, OperatorType parentOperator, ArrayList<Integer> childrenIndices ,boolean isConstant) {
		super();
		this.ownIndexInList = ownIndexInList;
		this.ownRandomVariable = ownRandomVariable;
		this.parentIndices = parentIndices;
		this.parentOperator = parentOperator;
		this.childrenIndices = childrenIndices;
		this.isConstant = isConstant;
	}

	

	/**
	 * @param randomVariable
	 * @param parentIndices
	 * @param parentOperator
	 * @param isConstant
	 * @return
	 */
	public static RandomVariableAAD constructNewAADRandomVariable(RandomVariableInterface randomVariable, int[] parentIndices,
			OperatorType parentOperator, ArrayList<Integer> childrenIndices, boolean isConstant){

		/* TODO: how to handle cases with different realization lengths? */
		if(!arrayListOfAllAADRandomVariables.isEmpty()){
			if(arrayListOfAllAADRandomVariables.get(0).size() != randomVariable.size() && !randomVariable.isDeterministic()){
				throw new IllegalArgumentException("RandomVariables with different sizes are not supported at the moment!");
			}
		}

		/* get index of this random variable */
		int indexOfThisAADRandomVariable = indexOfNextRandomVariable++;

		RandomVariableAAD newAADRandomVariable = new RandomVariableAAD(indexOfThisAADRandomVariable, randomVariable, 
				parentIndices, parentOperator, childrenIndices, isConstant);

		/* add random variable to static list for book keeping */
		arrayListOfAllAADRandomVariables.add(indexOfThisAADRandomVariable, newAADRandomVariable);

		/* return a new random variable */
		return newAADRandomVariable;
	}
<commit_msg>Fixed JavaDoc.<commit_after>/**
 * 
 */
package net.finmath.montecarlo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.math3.analysis.UnivariateFunction;

import net.finmath.stochastic.RandomVariableInterface;

/**
 * Implementation of <code>RandomVariableInterface</code> having the additional feature to calculate the backward algorithmic differentiation.
 * 
 * For construction use the factory method <code>constructNewAADRandomVariable</code>.
 *
 * @author <NAME>
 * @version 1.0
 */
public class RandomVariableAAD implements RandomVariableInterface {

	private static final long serialVersionUID = 2459373647785530657L;

	/* static elements of the class are shared between all members */
	private static ArrayList<RandomVariableAAD> arrayListOfAllAADRandomVariables = new ArrayList<>();
	private static int indexOfNextRandomVariable = 0;
	private static enum OperatorType {
		ADD, MULT, DIV, SUB, SQUARED, SQRT, LOG, SIN, COS, EXP, INVERT, CAP, FLOOR, ABS, 
		ADDPRODUCT, ADDRATIO, SUBRATIO, BARRIER, DISCOUNT, ACCURUE, POW, AVERAGE, VARIANCE, 
		STDEV, MIN, MAX, STDERROR, SVARIANCE
	}

	/* index of corresponding random variable in the static array list*/
	private final RandomVariableInterface ownRandomVariable;
	private final int ownIndexInList;

	/* this could maybe be outsourced to own class ParentElement */
	private final int[] parentIndices;
	private final OperatorType parentOperator;
	private ArrayList<Integer> childrenIndices;
	private boolean isConstant;

	/**
	 * @param indexOfRandomVariable
	 * @param parentRandomVariables
	 * @param parentOperator
	 * @param isConstant
	 */
	private RandomVariableAAD(int ownIndexInList, RandomVariableInterface ownRandomVariable, 
			int[] parentIndices, OperatorType parentOperator, ArrayList<Integer> childrenIndices ,boolean isConstant) {
		super();
		this.ownIndexInList = ownIndexInList;
		this.ownRandomVariable = ownRandomVariable;
		this.parentIndices = parentIndices;
		this.parentOperator = parentOperator;
		this.childrenIndices = childrenIndices;
		this.isConstant = isConstant;
	}

	

	/**
	 * @param randomVariable
	 * @param parentIndices
	 * @param parentOperator
	 * @param isConstant
	 * @return A new RandomVariableAAD.
	 */
	public static RandomVariableAAD constructNewAADRandomVariable(RandomVariableInterface randomVariable, int[] parentIndices,
			OperatorType parentOperator, ArrayList<Integer> childrenIndices, boolean isConstant){

		/* TODO: how to handle cases with different realization lengths? */
		if(!arrayListOfAllAADRandomVariables.isEmpty()){
			if(arrayListOfAllAADRandomVariables.get(0).size() != randomVariable.size() && !randomVariable.isDeterministic()){
				throw new IllegalArgumentException("RandomVariables with different sizes are not supported at the moment!");
			}
		}

		/* get index of this random variable */
		int indexOfThisAADRandomVariable = indexOfNextRandomVariable++;

		RandomVariableAAD newAADRandomVariable = new RandomVariableAAD(indexOfThisAADRandomVariable, randomVariable, 
				parentIndices, parentOperator, childrenIndices, isConstant);

		/* add random variable to static list for book keeping */
		arrayListOfAllAADRandomVariables.add(indexOfThisAADRandomVariable, newAADRandomVariable);

		/* return a new random variable */
		return newAADRandomVariable;
	}

{'fraction_non_alphanumeric': 0.08051948051948052, 'fraction_numerical': 0.006926406926406926, 'mean_word_length': 5.465485074626866, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270070', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1857, 'n_words': 563}