List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:dfs.OLSTrendLine.java
@Override public double predict(double x) { double yhat = coef.preMultiply(xVector(x))[0]; // apply coefs to xVector if (logY())//from w w w. j a v a 2 s .c om yhat = (Math.exp(yhat)); // if we predicted ln y, we still need to get y return yhat; }
From source file:com.davidbracewell.math.distribution.NormalDistribution.java
@Override public double probability(double x) { return 1d / Math.sqrt(TWO_PI * var) * Math.exp(-Math.pow(x - mean, 2) / (2 * var)); }
From source file:com.opengamma.analytics.financial.model.volatility.surface.BlackVolatilitySurfaceLogMoneyness.java
@Override public double getAbsoluteStrike(final double t, final LogMoneyness s) { return _fc.getForward(t) * Math.exp(s.value()); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.FadeInOptionModel.java
@Override public Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double> getPricingFunction( final FadeInOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override//from w w w . j ava2 s .c o m public Double evaluate(final StandardOptionWithSpotTimeSeriesDataBundle data) { Validate.notNull(data, "data"); final double s = data.getSpot(); final double k = definition.getStrike(); final double b = data.getCostOfCarry(); final ZonedDateTime date = data.getDate(); final double t = definition.getTimeToExpiry(date); final double r = data.getInterestRate(t); final double sigma = data.getVolatility(t, k); final double l = definition.getLowerBound(); final double u = definition.getUpperBound(); final double n = data.getSpotTimeSeries().size(); final double df1 = Math.exp(t * (b - r)); final double df2 = Math.exp(-r * t); final int sign = definition.isCall() ? 1 : -1; double rho, tI, d1, d2, d3, d4, d5, d6; double price = 0; for (int i = 0; i < n; i++) { tI = i * t / n; rho = -sign * Math.sqrt(tI / t); d1 = getD1(s, k, t, sigma, b); d2 = getD2(d1, sigma, t); d3 = getD1(s, l, tI, sigma, b); d4 = getD2(d3, sigma, tI); d5 = getD1(s, u, tI, sigma, b); d6 = getD2(d5, sigma, tI); price += sign * (s * df1 * (BIVARIATE_NORMAL.getCDF(new double[] { -d5, sign * d1, rho }) - BIVARIATE_NORMAL.getCDF(new double[] { -d3, sign * d1, rho })) - k * df2 * (BIVARIATE_NORMAL.getCDF(new double[] { -d6, sign * d2, rho }) - BIVARIATE_NORMAL.getCDF(new double[] { -d4, sign * d2, rho }))); } return price / n; } }; }
From source file:com.davidbracewell.ml.classification.bayes.NaiveBayes.java
@Override protected ClassificationResult classifyImpl(Instance instance) { int numClasses = getTargetFeature().alphabetSize(); double[] probabilities = new double[numClasses]; double sum = 0d; for (int i = 0; i < numClasses; i++) { //prior// w w w. j a v a 2s . c o m probabilities[i] = FastMath.log10(priors[i]); //posterior for (DoubleEntry entry : CollectionUtils.asIterable(instance.nonZeroIterator())) { probabilities[i] += FastMath.log10(conditionals[entry.index][i]); } probabilities[i] = Math.exp(probabilities[i]); sum += probabilities[i]; } //normalize to make probabilities add to one for (int i = 0; i < numClasses; i++) { probabilities[i] = probabilities[i] / sum; } return new ClassificationResult(getTargetFeature(), probabilities); }
From source file:beast.math.distributions.NormalDistribution.java
/** * probability density function/*from w ww .j a va2 s .com*/ * * @param x argument * @param m mean * @param sd standard deviation * @return pdf at x */ public static double pdf(double x, double m, double sd) { double a = 1.0 / (Math.sqrt(2.0 * Math.PI) * sd); double b = -(x - m) * (x - m) / (2.0 * sd * sd); return a * Math.exp(b); }
From source file:geogebra.util.MyMath.java
final public static double gamma(double x, Kernel kernel) { // Michael Borcherds 2008-05-04 if (x <= 0 && Kernel.isEqual(x, Math.round(x))) return Double.NaN; // negative integers // Michael Borcherds 2007-10-15 BEGIN added case for x<0 otherwise no // results in 3rd quadrant if (x >= 0) return Math.exp(Gamma.logGamma(x)); else//from w w w.ja v a 2s .c o m return -Math.PI / (x * gamma(-x, kernel) * Math.sin(Math.PI * x)); // Michael Borcherds 2007-10-15 END }
From source file:com.github.tteofili.looseen.yay.SoftmaxActivationFunction.java
private double expDen(RealMatrix matrix) { return matrix.walkInOptimizedOrder(new RealMatrixPreservingVisitor() { private double d1 = 0d; @Override/* ww w. jav a 2 s . c o m*/ public void start(int rows, int columns, int startRow, int endRow, int startColumn, int endColumn) { } @Override public void visit(int row, int column, double value) { d1 += Math.exp(value); } @Override public double end() { return d1; } }); }
From source file:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java
/** * * @param x a matrix of dimension 1 x k, where k is the number of variables * @return/*from w ww . ja v a2s . co m*/ */ public double density(RealMatrix x) throws SingularMatrixException { double prob = 0.0; RealMatrix xTran = x.transpose(); int d = xTran.getRowDimension(); double det = new LUDecomposition(sigma).getDeterminant(); double nconst = 1.0 / Math.sqrt(det * Math.pow(2.0 * Math.PI, d)); RealMatrix Sinv = new LUDecomposition(sigma).getSolver().getInverse(); RealMatrix delta = xTran.subtract(mu); RealMatrix dist = (delta.transpose().multiply(Sinv).multiply(delta)); prob = nconst * Math.exp(-0.5 * dist.getEntry(0, 0)); return prob; }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.FixedStrikeLookbackOptionModel.java
@Override public Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double> getPricingFunction( final FixedStrikeLookbackOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override/*from ww w .ja va 2 s.c o m*/ public Double evaluate(final StandardOptionWithSpotTimeSeriesDataBundle data) { Validate.notNull(data, "data"); final DoubleTimeSeries<?> ts = data.getSpotTimeSeries(); final double s = data.getSpot(); final ZonedDateTime date = data.getDate(); final double t = definition.getTimeToExpiry(date); final boolean isCall = definition.isCall(); final double k = definition.getStrike(); final double sCritical = isCall ? ts.maxValue() : ts.minValue(); final double sigma = data.getVolatility(t, k); final double r = data.getInterestRate(t); final double b = data.getCostOfCarry(); final double df1 = Math.exp(t * (b - r)); final double df2 = Math.exp(-r * t); double x = k; if ((isCall && x <= sCritical) || (!isCall && x >= sCritical)) { x = sCritical; } final int sign = isCall ? 1 : -1; final double d1 = getD1(s, x, t, sigma, b); final double d2 = getD2(d1, sigma, t); final double cdf1 = NORMAL.getCDF(sign * d1); return sign * (df2 * (x - k) + s * df1 * cdf1 - x * df2 * NORMAL.getCDF(sign * d2) - s * df2 * sigma * sigma * (Math.pow(s / x, -2 * b / sigma / sigma) * NORMAL.getCDF(sign * (d1 - 2 * b * Math.sqrt(t) / sigma)) - Math.exp(b * t) * cdf1) / 2 / b); } }; }