/* (non-Javadoc)
@see net.finmath.stochastic.RandomVariable#getQuantileExpectation(double, double)
510577
@Override
	public double getQuantileExpectation(double quantileStart, double quantileEnd) {
		return ((RandomVariableAAD) getRandomVariableInterface()).getRandomVariableInterface().getQuantileExpectation(quantileStart, quantileEnd);
	}
1077219
@Override
    public double getStandardDeviation() {
        double stdDev = Double.NaN;
        if (getN() > 0) {
            if (getN() > 1) {
                stdDev = FastMath.sqrt(getVariance());
            } else {
                stdDev = 0.0;
            }
        }
        return stdDev;
    }
224314
@Override
	public RandomVariable sub(RandomVariable randomVariable) {
		return new RandomVariableDifferentiableAADStochasticNonOptimized(
				getValues().sub(randomVariable),
				Arrays.asList(this, randomVariable),
				OperatorType.SUB);
	}
665878
@Override
	public double getVariance() {
		if(isDeterministic()) {
			return 0.0;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		double sum			= 0.0;
		double sumOfSquared = 0.0;
		for (double realization : getRealizations()) {
			sum += realization;
			sumOfSquared += realization * realization;
		}
		return sumOfSquared/size() - sum/size() * sum/size();
	}
137080
@Override
	public RandomVariableDifferentiable mult(RandomVariable randomVariable) {
		return new RandomVariableDifferentiableAADPathwise(
				getValues().mult(randomVariable),
				Arrays.asList(this, randomVariable),
				OperatorType.MULT);
	}
1338495
public double getDoubleValueFromMap( RandomIter map ) {
        try {
            if (map == null) {
                return HMConstants.doubleNovalue;
            }
            double value = map.getSampleDouble(col, row, 0);
            return value;
        } catch (Exception e) {
            // ignore and return novalue
            return HMConstants.doubleNovalue;
        }
    }
532554
@Override
	public RandomVariable div(double value) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return x / value;
			}
		});
	}
575390
private RandomVariable getShortRate(int timeIndex) throws CalculationException {
		double time = getProcess().getTime(timeIndex);
		double timePrev = timeIndex > 0 ? getProcess().getTime(timeIndex-1) : time;
		double timeNext = getProcess().getTime(timeIndex+1);

		RandomVariable zeroRate = getZeroRateFromForwardCurve(time); //getDiscountFactorFromForwardCurve(time).div(getDiscountFactorFromForwardCurve(timeNext)).log().div(timeNext-time);

		RandomVariable alpha = getDV(0, time);

		RandomVariable value = getProcess().getProcessValue(timeIndex, 0);
		value = value.add(alpha);
		//		value = value.sub(Math.log(value.exp().getAverage()));

		value = value.add(zeroRate);

		return value;
	}
2500
protected LightweightTypeReference getMapExpectation(LightweightTypeReference expectation) {
		if (expectation != null && expectation.isResolved()) {
			LightweightTypeReference result = expectation.getSuperType(Map.class);
			if (result != null && result.getTypeArguments().size() == 2) {
				return result;
			}
		}
		return null;
	}
197960
public double getDouble(int index)
  {
    Object value = _values[index - 1];

    if (value instanceof Double) {
      return (Double) value;
    }
    else if (value instanceof Float) {
      return (Float) value;
    }
    else if (value instanceof Number) {
      return (Double) ((Number) value);
    }
    else {
      return Double.valueOf(value.toString());
    }
  }
174989
@Pure
	@Inline(value = "StochasticGenerator.generateRandomValue(new UniformStochasticLaw(($1), ($2)))",
			imported = {StochasticGenerator.class, UniformStochasticLaw.class})
	public static double random(double minX, double maxX) throws MathException {
		return StochasticGenerator.generateRandomValue(new UniformStochasticLaw(minX, maxX));
	}
1366417
private double getExpectedProbability(double x)
    {
        double y = 1 / (standardDeviation * Math.sqrt(Math.PI * 2));
        double z = -(Math.pow(x - mean, 2) / (2 * Math.pow(standardDeviation, 2)));
        return y * Math.exp(z);
    }
967600
public double getDouble(int index)
    {
        checkIndexLength(index, SizeOf.SIZE_OF_DOUBLE);
        return unsafe.getDouble(base, address + index);
    }
114419
@Override
	public RandomVariable pow(double exponent) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return FastMath.pow(x, exponent);
			}
		});
	}
492697
@Override
	public RandomVariable pow(double exponent) {
		return apply(OperatorType.POW, new RandomVariable[]{this, constructNewAADRandomVariable(exponent)});
	}
810517
public static final double getDouble(String value)
   {
      return (value == null || value.length() == 0 ? 0 : Double.parseDouble(value));
   }
1159684
public final hqlParser.quantifiedExpression_return quantifiedExpression() throws RecognitionException {
		hqlParser.quantifiedExpression_return retval = new hqlParser.quantifiedExpression_return();
		retval.start = input.LT(1);

		CommonTree root_0 = null;

		Token SOME226=null;
		Token EXISTS227=null;
		Token ALL228=null;
		Token ANY229=null;
		Token OPEN232=null;
		Token CLOSE234=null;
		ParserRuleReturnScope identifier230 =null;
		ParserRuleReturnScope collectionExpr231 =null;
		ParserRuleReturnScope subQuery233 =null;

		CommonTree SOME226_tree=null;
		CommonTree EXISTS227_tree=null;
		CommonTree ALL228_tree=null;
		CommonTree ANY229_tree=null;
		CommonTree OPEN232_tree=null;
		CommonTree CLOSE234_tree=null;

		try {
			// hql.g:577:2: ( ( SOME ^| EXISTS ^| ALL ^| ANY ^) ( identifier | collectionExpr | ( OPEN ! ( subQuery ) CLOSE !) ) )
			// hql.g:577:4: ( SOME ^| EXISTS ^| ALL ^| ANY ^) ( identifier | collectionExpr | ( OPEN ! ( subQuery ) CLOSE !) )
			{
			root_0 = (CommonTree)adaptor.nil();


			// hql.g:577:4: ( SOME ^| EXISTS ^| ALL ^| ANY ^)
			int alt80=4;
			switch ( input.LA(1) ) {
			case SOME:
				{
				alt80=1;
				}
				break;
			case EXISTS:
				{
				alt80=2;
				}
				break;
			case ALL:
				{
				alt80=3;
				}
				break;
			case ANY:
				{
				alt80=4;
				}
				break;
			default:
				NoViableAltException nvae =
					new NoViableAltException("", 80, 0, input);
				throw nvae;
			}
			switch (alt80) {
				case 1 :
					// hql.g:577:6: SOME ^
					{
					SOME226=(Token)match(input,SOME,FOLLOW_SOME_in_quantifiedExpression2713);
					SOME226_tree = (CommonTree)adaptor.create(SOME226);
					root_0 = (CommonTree)adaptor.becomeRoot(SOME226_tree, root_0);

					}
					break;
				case 2 :
					// hql.g:577:14: EXISTS ^
					{
					EXISTS227=(Token)match(input,EXISTS,FOLLOW_EXISTS_in_quantifiedExpression2718);
					EXISTS227_tree = (CommonTree)adaptor.create(EXISTS227);
					root_0 = (CommonTree)adaptor.becomeRoot(EXISTS227_tree, root_0);

					}
					break;
				case 3 :
					// hql.g:577:24: ALL ^
					{
					ALL228=(Token)match(input,ALL,FOLLOW_ALL_in_quantifiedExpression2723);
					ALL228_tree = (CommonTree)adaptor.create(ALL228);
					root_0 = (CommonTree)adaptor.becomeRoot(ALL228_tree, root_0);

					}
					break;
				case 4 :
					// hql.g:577:31: ANY ^
					{
					ANY229=(Token)match(input,ANY,FOLLOW_ANY_in_quantifiedExpression2728);
					ANY229_tree = (CommonTree)adaptor.create(ANY229);
					root_0 = (CommonTree)adaptor.becomeRoot(ANY229_tree, root_0);

					}
					break;

			}

			// hql.g:578:2: ( identifier | collectionExpr | ( OPEN ! ( subQuery ) CLOSE !) )
			int alt81=3;
			switch ( input.LA(1) ) {
			case IDENT:
				{
				alt81=1;
				}
				break;
			case ELEMENTS:
			case INDICES:
				{
				alt81=2;
				}
				break;
			case OPEN:
				{
				alt81=3;
				}
				break;
			default:
				NoViableAltException nvae =
					new NoViableAltException("", 81, 0, input);
				throw nvae;
			}
			switch (alt81) {
				case 1 :
					// hql.g:578:4: identifier
					{
					pushFollow(FOLLOW_identifier_in_quantifiedExpression2737);
					identifier230=identifier();
					state._fsp--;

					adaptor.addChild(root_0, identifier230.getTree());

					}
					break;
				case 2 :
					// hql.g:578:17: collectionExpr
					{
					pushFollow(FOLLOW_collectionExpr_in_quantifiedExpression2741);
					collectionExpr231=collectionExpr();
					state._fsp--;

					adaptor.addChild(root_0, collectionExpr231.getTree());

					}
					break;
				case 3 :
					// hql.g:578:34: ( OPEN ! ( subQuery ) CLOSE !)
					{
					// hql.g:578:34: ( OPEN ! ( subQuery ) CLOSE !)
					// hql.g:578:35: OPEN ! ( subQuery ) CLOSE !
					{
					OPEN232=(Token)match(input,OPEN,FOLLOW_OPEN_in_quantifiedExpression2746);
					// hql.g:578:41: ( subQuery )
					// hql.g:578:43: subQuery
					{
					pushFollow(FOLLOW_subQuery_in_quantifiedExpression2751);
					subQuery233=subQuery();
					state._fsp--;

					adaptor.addChild(root_0, subQuery233.getTree());

					}

					CLOSE234=(Token)match(input,CLOSE,FOLLOW_CLOSE_in_quantifiedExpression2755);
					}

					}
					break;

			}

			}

			retval.stop = input.LT(-1);

			retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}