List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:com.opengamma.analytics.financial.model.finitedifference.MarkovChainApprox.java
private double getI1(final double t) { final double lt = _lambda * t; if (lt < 1e-7) { return _probState1; }/*w w w .j a v a2s .c om*/ return _theta + (_probState1 - _theta) * (1 - Math.exp(-_lambda * t)) / lt; }
From source file:io.s4.model.GaussianMixtureModel.java
/** * @param obs/* w ww .j av a 2s . c o m*/ * the observed data vector. * @return the probability. */ public double prob(D1Matrix64F obs) { return Math.exp(logProb(obs)); }
From source file:org.jfree.data.statistics.Regression.java
/** * Returns the parameters 'a' and 'b' for an equation y = ax^b, fitted to * the data using a power regression equation. The result is returned as * an array, where double[0] --> a, and double[1] --> b. * * @param data the data./*ww w. java 2 s. c om*/ * @param series the series to fit the regression line against. * * @return The parameters. */ public static double[] getPowerRegression(XYDataset data, int series) { int n = data.getItemCount(series); if (n < 2) { throw new IllegalArgumentException("Not enough data."); } double sumX = 0; double sumY = 0; double sumXX = 0; double sumXY = 0; for (int i = 0; i < n; i++) { double x = Math.log(data.getXValue(series, i)); double y = Math.log(data.getYValue(series, i)); sumX += x; sumY += y; double xx = x * x; sumXX += xx; double xy = x * y; sumXY += xy; } double sxx = sumXX - (sumX * sumX) / n; double sxy = sumXY - (sumX * sumY) / n; double xbar = sumX / n; double ybar = sumY / n; double[] result = new double[2]; result[1] = sxy / sxx; result[0] = Math.pow(Math.exp(1.0), ybar - result[1] * xbar); return result; }
From source file:com.datumbox.framework.core.statistics.distributions.ContinuousDistributions.java
/** * Calculates the probability from 0 to X under Beta Distribution * /*from w w w . j a va 2s . c o m*/ * @param x * @param a * @param b * @return */ public static double betaCdf(double x, double a, double b) { if (x < 0 || a <= 0 || b <= 0) { throw new IllegalArgumentException("All the parameters must be positive."); } double Bcdf = 0.0; if (x == 0) { return Bcdf; } else if (x >= 1) { Bcdf = 1.0; return Bcdf; } double S = a + b; double BT = Math.exp(logGamma(S) - logGamma(b) - logGamma(a) + a * Math.log(x) + b * Math.log(1 - x)); if (x < (a + 1.0) / (S + 2.0)) { Bcdf = BT * betinc(x, a, b); } else { Bcdf = 1.0 - BT * betinc(1.0 - x, b, a); } return Bcdf; }
From source file:com.datumbox.framework.statistics.distributions.ContinuousDistributions.java
/** * Calculates the probability from 0 to X under Beta Distribution * //from w ww . j ava 2 s . c om * @param x * @param a * @param b * @return */ public static double BetaCdf(double x, double a, double b) throws IllegalArgumentException { if (x < 0 || a <= 0 || b <= 0) { throw new IllegalArgumentException(); } double Bcdf = 0.0; if (x == 0) { return Bcdf; } else if (x >= 1) { Bcdf = 1.0; return Bcdf; } double S = a + b; double BT = Math.exp(LogGamma(S) - LogGamma(b) - LogGamma(a) + a * Math.log(x) + b * Math.log(1 - x)); if (x < (a + 1.0) / (S + 2.0)) { Bcdf = BT * Betinc(x, a, b); } else { Bcdf = 1.0 - BT * Betinc(1.0 - x, b, a); } return Bcdf; }
From source file:com.bmwcarit.barefoot.matcher.MatcherTest.java
private void assertTransition(Tuple<MatcherTransition, Double> transition, Tuple<MatcherCandidate, MatcherSample> source, Tuple<MatcherCandidate, MatcherSample> target, double lambda) { List<Road> edges = router.route(source.one().point(), target.one().point(), cost); if (edges == null) { // fail(); }//w w w .j a v a 2s. c o m Route route = new Route(source.one().point(), target.one().point(), edges); assertEquals(route.length(), transition.one().route().length(), 10E-6); assertEquals(route.source().edge().id(), transition.one().route().source().edge().id()); assertEquals(route.target().edge().id(), transition.one().route().target().edge().id()); double beta = lambda == 0 ? (2.0 * (target.two().time() - source.two().time()) / 1000) : 1 / lambda; double base = 1.0 * spatial.distance(source.two().point(), target.two().point()) / 60; double p = (1 / beta) * Math.exp((-1.0) * Math.max(0, route.cost(new TimePriority()) - base) / beta); assertEquals(transition.two(), p, 10E-6); }
From source file:stratego.neural.net.SimulatedAnnealing.java
public double calculateProbability(double[] weights, double e) { double prob = Math.exp(-((e - energy) / ((double) temperature / (double) start_temperature))); // dividing the temperature by the start temperature to normalize prob = Math.log(prob);/*from ww w . j a v a2s . co m*/ System.out.println("Acceptance probability: " + prob); return prob; }
From source file:Randoms.java
/** Return a random double drawn from a Gamma distribution with mean alpha*beta+lamba and variance alpha*beta^2. */ public synchronized double nextGamma(double alpha, double beta, double lambda) { double gamma = 0; if (alpha <= 0 || beta <= 0) { throw new IllegalArgumentException("alpha and beta must be strictly positive."); }/*from www. j a v a 2 s . c o m*/ if (alpha < 1) { double b, p; boolean flag = false; b = 1 + alpha * Math.exp(-1); while (!flag) { p = b * nextUniform(); if (p > 1) { gamma = -Math.log((b - p) / alpha); if (nextUniform() <= Math.pow(gamma, alpha - 1)) flag = true; } else { gamma = Math.pow(p, 1 / alpha); if (nextUniform() <= Math.exp(-gamma)) flag = true; } } } else if (alpha == 1) { gamma = -Math.log(nextUniform()); } else { double y = -Math.log(nextUniform()); while (nextUniform() > Math.pow(y * Math.exp(1 - y), alpha - 1)) y = -Math.log(nextUniform()); gamma = alpha * y; } return beta * gamma + lambda; }
From source file:com.opengamma.analytics.financial.model.volatility.BlackFormula.java
public final Double computeStrikeImpliedByDeltaViaRootFinding(final double fwdDelta, final boolean forCall) { try {/*from www. j av a 2s.co m*/ Validate.isTrue(fwdDelta >= 0.0 && fwdDelta <= 1.0, "Delta must be between 0.0 and 1.0"); final BlackFormula black = new BlackFormula(_forward, _strike, _expiry, _lognormalVol, _fwdMtm, forCall); final Function1D<Double, Double> difference = new Function1D<Double, Double>() { @Override public Double evaluate(final Double strike) { black.setStrike(strike); final double delta = black.computeForwardDelta(); return delta - fwdDelta * (forCall ? 1.0 : -1.0); // TODO Case : confirm this is sufficient for calls and puts } }; final NewtonRaphsonSingleRootFinder rootFinder = new NewtonRaphsonSingleRootFinder(); if ((forCall && fwdDelta >= 0.5) || (!forCall && fwdDelta <= 0.5)) { // Strike is bounded below by 0 and above by the atmDelta final double atmDelta = _forward * Math.exp(0.5 * _lognormalVol * _lognormalVol * _expiry); return rootFinder.getRoot(difference, 0.0, atmDelta); } // Give it a guess, and estimate finite-difference derivative return rootFinder.getRoot(difference, _strike); } catch (final com.opengamma.analytics.math.MathException e) { System.err.println(e); System.err.println("Failed to compute ImpliedVolatility"); return null; } }
From source file:com.opengamma.analytics.financial.credit.isdayieldcurve.ISDADateCurve.java
/** * A ISDA model zero default curve //from w w w .jav a 2s . c o m * @param name The curve name * @param baseDate base date to convert other (future) dates into year fractions using the day-count convention * @param curveDates The dates of points on the curve * @param rates The zero default rates at points on the curve. <b>Note:</b>These as annually compounded rates * @param offset TODO find out what this does * @param dayCount The day-count convention */ public ISDADateCurve(final String name, final ZonedDateTime baseDate, final ZonedDateTime[] curveDates, final double[] rates, final double offset, final DayCount dayCount) { super(name); ArgumentChecker.notNull(name, "name"); ArgumentChecker.notNull(baseDate, "base date"); ArgumentChecker.noNulls(curveDates, "curve dates"); ArgumentChecker.notEmpty(rates, "rates"); ArgumentChecker.notNull(dayCount, "day count"); _n = curveDates.length; ArgumentChecker.isTrue(_n != 0, "Data arrays were empty"); // TODO why is this test commented out? // ArgumentChecker.isTrue(_n == rates.length, "Have {} rates for {} dates", rates.length, _n); _baseDates = baseDate; _name = name; _offset = offset; _curveDates = new ZonedDateTime[_n]; System.arraycopy(curveDates, 0, _curveDates, 0, _n); final double[] times = new double[_n]; final double[] continuousRates = new double[_n]; _shiftedTimePoints = new double[_n]; for (int i = 0; i < _n; i++) { // Convert the ZonedDateTimes to doubles final double dayCountFraction = dayCount.getDayCountFraction(baseDate, curveDates[i]); times[i] = dayCountFraction; // Convert the discrete rates to continuous ones continuousRates[i] = new PeriodicInterestRate(rates[i], 1).toContinuous().getRate(); _shiftedTimePoints[i] = dayCountFraction + _offset; } // Choose interpolation/extrapolation to match the behavior of curves in the ISDA CDS reference code if (_n > 1) { _curve = InterpolatedDoublesCurve.fromSorted(times, continuousRates, INTERPOLATOR); } else { _curve = ConstantDoublesCurve.from(continuousRates[0]); // Unless the curve is flat, in which case use a constant curve } _zeroDiscountFactor = Math.exp(_offset * getInterestRate(0.0)); }