List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:StatFunctions.java
public static double qnorm(double p, boolean upper) { /*//w ww . ja v a 2 s . com * Reference: J. D. Beasley and S. G. Springer Algorithm AS 111: * "The Percentage Points of the Normal Distribution" Applied Statistics */ if (p < 0 || p > 1) throw new IllegalArgumentException("Illegal argument " + p + " for qnorm(p)."); double split = 0.42, a0 = 2.50662823884, a1 = -18.61500062529, a2 = 41.39119773534, a3 = -25.44106049637, b1 = -8.47351093090, b2 = 23.08336743743, b3 = -21.06224101826, b4 = 3.13082909833, c0 = -2.78718931138, c1 = -2.29796479134, c2 = 4.85014127135, c3 = 2.32121276858, d1 = 3.54388924762, d2 = 1.63706781897, q = p - 0.5; double r, ppnd; if (Math.abs(q) <= split) { r = q * q; ppnd = q * (((a3 * r + a2) * r + a1) * r + a0) / ((((b4 * r + b3) * r + b2) * r + b1) * r + 1); } else { r = p; if (q > 0) r = 1 - p; if (r > 0) { r = Math.sqrt(-Math.log(r)); ppnd = (((c3 * r + c2) * r + c1) * r + c0) / ((d2 * r + d1) * r + 1); if (q < 0) ppnd = -ppnd; } else { ppnd = 0; } } if (upper) ppnd = 1 - ppnd; return (ppnd); }
From source file:dr.math.distributions.PoissonDistribution.java
public static double logPdf(double x, double mean) { PoissonDistributionImpl dist = new PoissonDistributionImpl(mean); double pdf = dist.probability(x); if (pdf == 0 || Double.isNaN(pdf)) { // bad estimate return x * Math.log(mean) - Poisson.gammln(x + 1) - mean; }//from w ww . ja v a 2s . c o m return Math.log(pdf); }
From source file:com.joptimizer.functions.SOCPLogarithmicBarrier.java
public double value(double[] X) { RealVector x = new ArrayRealVector(X); double ret = 0; for (int i = 0; i < socpConstraintParametersList.size(); i++) { SOCPConstraintParameters param = socpConstraintParametersList.get(i); double t = this.buildT(param, x); if (t < 0) { return Double.NaN; }//from w w w. jav a 2 s . c o m RealVector u = this.buildU(param, x); double t2uu = t * t - u.dotProduct(u); if (t2uu <= 0) { return Double.NaN; } double ret_i = -Math.log(t2uu); ret += ret_i; } return ret; }
From source file:com.davidbracewell.math.distribution.NormalDistribution.java
@Override public double logProbability(double x) { return Math.log(probability(x)); }
From source file:hivemall.utils.math.MathUtils.java
public static double logit(final double p, final double hi, final double lo) { return Math.log((p - lo) / (hi - p)); }
From source file:com.analog.lyric.dimple.factorfunctions.Gamma.java
public Gamma(double alpha, double beta) { this();//from ww w .j a v a 2 s . c o m _alpha = alpha; _beta = beta; _alphaMinusOne = _alpha - 1; _logBeta = Math.log(_beta); _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha) - _alpha * _logBeta; _parametersConstant = true; _firstDirectedToIndex = 0; if (_alpha <= 0) throw new DimpleException("Non-positive alpha parameter. This must be a positive value."); if (_beta <= 0) throw new DimpleException("Non-positive beta parameter. This must be a positive value."); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.ExtremeSpreadOptionModel.java
@Override public Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double> getPricingFunction( final ExtremeSpreadOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionWithSpotTimeSeriesDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override/*w ww . j a v a2 s . co m*/ public Double evaluate(final StandardOptionWithSpotTimeSeriesDataBundle data) { Validate.notNull(data, "data"); final double s = data.getSpot(); final double b = data.getCostOfCarry(); final ZonedDateTime date = data.getDate(); final double t1 = -definition.getTimeFromPeriodEnd(date); final double t2 = definition.getTimeToExpiry(date); final double r = data.getInterestRate(t2); final DoubleTimeSeries<?> ts = data.getSpotTimeSeries(); final int eta = definition.isCall() ? 1 : -1; final int phi = definition.isReverse() ? -1 : 1; final double x = eta * phi == 1 ? ts.maxValue() : ts.minValue(); final double sigma = data.getVolatility(t2, x); //REVIEW emcleod 21-7-10 works for flat vol surfaces final double m = Math.log(x / s); final double mu1 = b - sigma * sigma / 2; final double mu2 = b + sigma * sigma / 2; final double df1 = Math.exp(t2 * (b - r)); final double df2 = Math.exp(b * (t1 - t2)); final double df3 = Math.exp(-r * t2); final double sigmaT2 = sigma * Math.sqrt(t2); final double sigmaT1 = sigma * Math.sqrt(t1); final double sigmaSq = sigma * sigma; final double y = sigmaSq / 2 / b; if (definition.isReverse()) { final double dt = t2 - t1; final double sigmaDT = sigma * Math.sqrt(dt); final double z1 = s * df1 * (1 + y) * NORMAL.getCDF(eta * (m - mu2 * t2) / sigmaT2); final double z2 = df3 * x * NORMAL.getCDF(eta * (mu1 * t2 - m) / sigmaT2); final double z3 = -df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(eta * (m + mu1 * t2) / sigmaT2); final double z4 = -s * df1 * (1 + y) * NORMAL.getCDF(-eta * mu2 * dt / sigmaDT); final double z5 = -df2 * df1 * s * (1 - y) * NORMAL.getCDF(eta * mu1 * dt / sigmaDT); return -eta * (z1 + z2 + z3 + z4 + z5); } final double z1 = s * df1 * (1 + y) * NORMAL.getCDF(eta * (mu2 * t2 - m) / sigmaT2); final double z2 = -df2 * df1 * s * (1 + y) * NORMAL.getCDF(eta * (mu2 * t1 - m) / sigmaT1); final double z3 = df3 * x * NORMAL.getCDF(eta * (m - mu1 * t2) / sigmaT2); final double z4 = -df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(-eta * (m + mu1 * t2) / sigmaT2); final double z5 = -df3 * x * NORMAL.getCDF(eta * (m - mu1 * t1) / sigmaT1); final double z6 = df3 * x * y * Math.exp(2 * mu1 * m / sigmaSq) * NORMAL.getCDF(-eta * (m + mu1 * t1) / sigmaT1); return eta * (z1 + z2 + z3 + z4 + z5 + z6); } }; }
From source file:com.analog.lyric.dimple.factorfunctions.NegativeExpGamma.java
public NegativeExpGamma(double alpha, double beta) { this();//from w w w . ja v a 2 s . c o m _alpha = alpha; _beta = beta; _alphaMinusOne = _alpha - 1; _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha) - _alpha * Math.log(_beta); _parametersConstant = true; _firstDirectedToIndex = 0; if (_alpha <= 0) throw new DimpleException("Non-positive alpha parameter. This must be a positive value."); if (_beta <= 0) throw new DimpleException("Non-positive beta parameter. This must be a positive value."); }
From source file:com.opengamma.analytics.math.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * @param degrees The number of degrees of freedom, not negative or zero * @param nonCentrality The non-centrality parameter, not negative *//*from w ww . ja v a2 s .c o m*/ public NonCentralChiSquaredDistribution(final double degrees, final double nonCentrality) { Validate.isTrue(degrees > 0, "degrees of freedom must be > 0, have " + degrees); Validate.isTrue(nonCentrality >= 0, "non-centrality must be >= 0, have " + nonCentrality); _dofOverTwo = degrees / 2.0; _lambdaOverTwo = nonCentrality / 2.0; _k = (int) Math.round(_lambdaOverTwo); if (_lambdaOverTwo == 0) { _pStart = 0.0; } else { final double logP = -_lambdaOverTwo + _k * Math.log(_lambdaOverTwo) - Gamma.logGamma(_k + 1); _pStart = Math.exp(logP); } }
From source file:de.unijena.bioinf.IsotopePatternAnalysis.scoring.MissingPeakScorer.java
@Override public double score(Spectrum<Peak> measuredSpectrum, Spectrum<Peak> theoreticalSpectrum, Normalization norm, Ms2Experiment experiment, MeasurementProfile profile) { final Spectrum<? extends Peak> measured, theoretical; if (normalization.getMode() != null && !norm.equals(normalization)) { measured = normalization.call(measuredSpectrum); theoretical = normalization.call(theoreticalSpectrum); } else {/*from w w w .j av a 2 s .c o m*/ measured = measuredSpectrum; theoretical = theoreticalSpectrum; } double score = 0; final double standardDeviation = 0.03; for (int i = measured.size(); i < theoretical.size(); ++i) { final double diff = theoretical.getIntensityAt(i); score += Math.log(Erf.erfc(diff / (sqrt2 * standardDeviation))); //score -= lambda*theoretical.getIntensityAt(i); } return score; }