List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:org.gumtree.vis.hist2d.ColorPaintScale.java
@Override public Paint getPaint(double value) { double colorValue = (value - ((upper - lower) * lowerBoundPercent + lower)) / width; if (colorValue < 0) { colorValue = 0;//from w ww . j a v a 2 s . co m } if (colorValue > 1) { colorValue = 1; } if (isLogScale) { return scale.getColor((Math.log((colorValue) * LOG_INPUT_WIDTH + LOG_INPUT_START) - LOG_OUTPUT_START) / LOG_OUTPUT_WIDTH); } return scale.getColor(colorValue); }
From source file:de.huberlin.wbi.hiway.scheduler.WienerProcessModel.java
public void addRuntime(double timestamp, double runtime) { Runtime measurement = new Runtime(timestamp, logarithmize ? Math.log(runtime) : runtime); if (!measurements.isEmpty()) { Runtime lastMeasurement = measurements.getLast(); double difference = (measurement.runtime - lastMeasurement.runtime) / Math.sqrt(measurement.timestamp - lastMeasurement.timestamp); sumOfDifferences += difference;//from w w w .j a v a2s.co m differences.add(difference); } measurements.add(measurement); }
From source file:Util.java
public static final double logGamma(double x) { double result, y, xnum, xden; int i;/*from www . jav a 2s .co m*/ final double d1 = -5.772156649015328605195174e-1; final double p1[] = { 4.945235359296727046734888e0, 2.018112620856775083915565e2, 2.290838373831346393026739e3, 1.131967205903380828685045e4, 2.855724635671635335736389e4, 3.848496228443793359990269e4, 2.637748787624195437963534e4, 7.225813979700288197698961e3 }; final double q1[] = { 6.748212550303777196073036e1, 1.113332393857199323513008e3, 7.738757056935398733233834e3, 2.763987074403340708898585e4, 5.499310206226157329794414e4, 6.161122180066002127833352e4, 3.635127591501940507276287e4, 8.785536302431013170870835e3 }; final double d2 = 4.227843350984671393993777e-1; final double p2[] = { 4.974607845568932035012064e0, 5.424138599891070494101986e2, 1.550693864978364947665077e4, 1.847932904445632425417223e5, 1.088204769468828767498470e6, 3.338152967987029735917223e6, 5.106661678927352456275255e6, 3.074109054850539556250927e6 }; final double q2[] = { 1.830328399370592604055942e2, 7.765049321445005871323047e3, 1.331903827966074194402448e5, 1.136705821321969608938755e6, 5.267964117437946917577538e6, 1.346701454311101692290052e7, 1.782736530353274213975932e7, 9.533095591844353613395747e6 }; final double d4 = 1.791759469228055000094023e0; final double p4[] = { 1.474502166059939948905062e4, 2.426813369486704502836312e6, 1.214755574045093227939592e8, 2.663432449630976949898078e9, 2.940378956634553899906876e10, 1.702665737765398868392998e11, 4.926125793377430887588120e11, 5.606251856223951465078242e11 }; final double q4[] = { 2.690530175870899333379843e3, 6.393885654300092398984238e5, 4.135599930241388052042842e7, 1.120872109616147941376570e9, 1.488613728678813811542398e10, 1.016803586272438228077304e11, 3.417476345507377132798597e11, 4.463158187419713286462081e11 }; final double c[] = { -1.910444077728e-03, 8.4171387781295e-04, -5.952379913043012e-04, 7.93650793500350248e-04, -2.777777777777681622553e-03, 8.333333333333333331554247e-02, 5.7083835261e-03 }; final double a = 0.6796875; if ((x <= 0.5) || ((x > a) && (x <= 1.5))) { if (x <= 0.5) { result = -Math.log(x); /* Test whether X < machine epsilon. */ if (x + 1 == 1) { return result; } } else { result = 0; x = (x - 0.5) - 0.5; } xnum = 0; xden = 1; for (i = 0; i < 8; i++) { xnum = xnum * x + p1[i]; xden = xden * x + q1[i]; } result += x * (d1 + x * (xnum / xden)); } else if ((x <= a) || ((x > 1.5) && (x <= 4))) { if (x <= a) { result = -Math.log(x); x = (x - 0.5) - 0.5; } else { result = 0; x -= 2; } xnum = 0; xden = 1; for (i = 0; i < 8; i++) { xnum = xnum * x + p2[i]; xden = xden * x + q2[i]; } result += x * (d2 + x * (xnum / xden)); } else if (x <= 12) { x -= 4; xnum = 0; xden = -1; for (i = 0; i < 8; i++) { xnum = xnum * x + p4[i]; xden = xden * x + q4[i]; } result = d4 + x * (xnum / xden); } /* X > 12 */ else { y = Math.log(x); result = x * (y - 1) - y * 0.5 + .9189385332046727417803297; x = 1 / x; y = x * x; xnum = c[6]; for (i = 0; i < 6; i++) { xnum = xnum * y + c[i]; } xnum *= x; result += xnum; } return result; }
From source file:com.opengamma.strata.math.impl.statistics.distribution.NonCentralChiSquaredDistribution.java
/** * @param degrees The number of degrees of freedom, not negative or zero * @param nonCentrality The non-centrality parameter, not negative *//* ww w . j a v a2 s. c o m*/ public NonCentralChiSquaredDistribution(double degrees, double nonCentrality) { ArgChecker.isTrue(degrees > 0, "degrees of freedom must be > 0, have " + degrees); ArgChecker.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 { double logP = -_lambdaOverTwo + _k * Math.log(_lambdaOverTwo) - Gamma.logGamma(_k + 1); _pStart = Math.exp(logP); } }
From source file:BackEnd.E_Spheres_calculation.java
private double get_Pkk(double K, double Hk, double Rk) { double val = K * Math.log((2 * Hk) / Rk); return val; }
From source file:com.opengamma.analytics.financial.model.volatility.curve.FXVannaVolgaVolatilityCurveModel.java
@Override public VolatilityCurve getCurve(final FXVannaVolgaVolatilityCurveDataBundle marketQuotes, final FXOptionDataBundle data) { Validate.notNull(marketQuotes);/*from ww w. ja va2 s. co m*/ Validate.notNull(data); final double sigmaRR = marketQuotes.getRiskReversal(); final double sigmaATM = marketQuotes.getAtTheMoney(); final double sigmaVWB = marketQuotes.getVegaWeightedButterfly(); final double sigmaDeltaCall = sigmaVWB + sigmaATM + 0.5 * sigmaRR; final double sigmaDeltaPut = sigmaDeltaCall - sigmaRR; final double t = DateUtils.getDifferenceInYears(data.getDate(), marketQuotes.getMaturity()); if (t < 0) { throw new IllegalArgumentException("Cannot have date after time to maturity"); } final double sqrtT = Math.sqrt(t); final double s = data.getSpot(); final double rd = data.getInterestRate(t); final double rf = data.getForeignInterestRate(t); final double alpha = -NORMAL.getInverseCDF(Math.exp(rf * t) * marketQuotes.getDelta()); final double k1 = s * Math.exp(-alpha * sigmaDeltaPut * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaPut * sigmaDeltaPut)); final double k2 = s * Math.exp(t * (rd - rf + 0.5 * sigmaATM * sigmaATM)); final double k3 = s * Math.exp(alpha * sigmaDeltaCall * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaCall * sigmaDeltaCall)); final double lnk21 = Math.log(k2 / k1); final double lnk31 = Math.log(k3 / k1); final double lnk32 = Math.log(k3 / k2); final double sigma = sigmaATM; return new VolatilityCurve(FunctionalDoublesCurve.from(new Function1D<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final Double x) { Validate.notNull(x); final double k = x; final double a1 = Math.log(k2 / k) * Math.log(k3 / k) / lnk21 / lnk31; final double a2 = Math.log(k / k1) * Math.log(k3 / k) / lnk21 / lnk32; final double a3 = Math.log(k / k1) * Math.log(k / k2) / lnk31 / lnk32; final double x1 = a1 * sigmaDeltaPut; final double x2 = a2 * sigmaATM; final double x3 = a3 * sigmaDeltaCall; final double e1 = x1 + x2 + x3 - sigma; final double d1k1 = getD1(s, k1, t, rd, rf, sigma, sqrtT); final double d1k2 = getD1(s, k2, t, rd, rf, sigma, sqrtT); final double d1k3 = getD1(s, k3, t, rd, rf, sigma, sqrtT); final double x4 = a1 * d1k1 * getD2(d1k1, sigma, sqrtT) * (sigmaDeltaPut - sigma) * (sigmaDeltaPut - sigma); final double x5 = a2 * d1k2 * getD2(d1k2, sigma, sqrtT) * (sigmaATM - sigma) * (sigmaATM - sigma); final double x6 = a3 * d1k3 * getD2(d1k3, sigma, sqrtT) * (sigmaDeltaCall - sigma) * (sigmaDeltaCall - sigma); final double e2 = x4 + x5 + x6; final double d1k = getD1(s, k, t, rd, rf, sigma, sqrtT); final double d2k = getD2(d1k, sigma, sqrtT); return sigma + (-sigma + Math.sqrt(sigma * sigma + d1k * d2k * (2 * sigma * e1 + e2))) / d1k / d2k; } })); }
From source file:com.google.cloud.genomics.dataflow.functions.LikelihoodFnTest.java
@Test public void testValue() { final double tolerance = 0.0000001; // slop factor for floating point comparisons final double alpha = 0.25; final int errPhred = 10; // P(err) = 0.1 final double pRef = 0.6; Position position1 = new Position().setReferenceName("1").setPosition(123L); /*//from w w w .ja va2s . c o m * Observe single REF read */ ImmutableMap.Builder<Position, ReadCounts> countsBuilder = ImmutableMap.builder(); ReadCounts rc = new ReadCounts(); rc.setRefFreq(pRef); ReadQualityCount rqc = new ReadQualityCount(); rqc.setBase(Base.REF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); Map<Position, ReadCounts> readCounts = countsBuilder.build(); LikelihoodFn fn = new LikelihoodFn(readCounts); // Likelihood of a single REF with the parameters above final double likRef = 0.3354133333; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likRef), tolerance), 0); /* * Observe single NONREF read */ countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.NONREF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); // Likelihood of a single NONREF with the parameters above final double likNonref = 0.20368; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likNonref), tolerance), 0); /* * Observe single OTHER read */ countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.OTHER); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); // Likelihood of a single OTHER with the parameters above final double likOther = 0.03850666667; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likOther), tolerance), 0); // Likelihood for reads at 2 different positions should be product of // likelihoods for individual reads Position position2 = new Position().setReferenceName("1").setPosition(124L); countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.REF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.NONREF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position2, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likRef * likNonref), tolerance), 0); }
From source file:gr.eap.LSHDB.HammingKey.java
public int getLc() { double p = 1 - (t * 1.0) / (this.size * 1.0); p = Math.pow(p, k);//from w ww .j a va 2 s. co m double exp = (L * p); double std = Math.sqrt(exp * (1 - p)); int C = (int) Math.round(exp - std); double x = (Math.sqrt(Math.log(delta) * Math.log(delta) - 2 * C * Math.log(delta)) - Math.log(delta) + C) / p; int Lc = (int) Math.ceil(x); double b = Lc * p; if (C > b) System.out.println("does not apply C > np."); BinomialDistribution bd1 = new BinomialDistribution(L, p); for (int l = L; l < L * 2; l++) { bd1 = new BinomialDistribution(l, p); double result = bd1.cumulativeProbability(C - 1); if (result < delta) { Lc = l; break; } } System.out.println("Lc reduced to=" + Lc); return Lc; }
From source file:com.google.cloud.genomics.dataflow.functions.verifybamid.LikelihoodFnTest.java
@Test public void testValue() { final double tolerance = 0.0000001; // slop factor for floating point comparisons final double alpha = 0.25; final int errPhred = 10; // P(err) = 0.1 final double pRef = 0.6; Position position1 = Position.newBuilder().setReferenceName("1").setPosition(123L).build(); /*/* ww w. ja v a2s . c o m*/ * Observe single REF read */ ImmutableMap.Builder<Position, ReadCounts> countsBuilder = ImmutableMap.builder(); ReadCounts rc = new ReadCounts(); rc.setRefFreq(pRef); ReadQualityCount rqc = new ReadQualityCount(); rqc.setBase(Base.REF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); Map<Position, ReadCounts> readCounts = countsBuilder.build(); LikelihoodFn fn = new LikelihoodFn(readCounts); // Likelihood of a single REF with the parameters above final double likRef = 0.3354133333; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likRef), tolerance), 0); /* * Observe single NONREF read */ countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.NONREF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); // Likelihood of a single NONREF with the parameters above final double likNonref = 0.20368; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likNonref), tolerance), 0); /* * Observe single OTHER read */ countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.OTHER); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); // Likelihood of a single OTHER with the parameters above final double likOther = 0.03850666667; assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likOther), tolerance), 0); // Likelihood for reads at 2 different positions should be product of // likelihoods for individual reads Position position2 = Position.newBuilder().setReferenceName("1").setPosition(124L).build(); countsBuilder = ImmutableMap.builder(); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.REF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position1, rc); rc = new ReadCounts(); rc.setRefFreq(pRef); rqc = new ReadQualityCount(); rqc.setBase(Base.NONREF); rqc.setQuality(errPhred); rqc.setCount(1); rc.addReadQualityCount(rqc); countsBuilder.put(position2, rc); readCounts = countsBuilder.build(); fn = new LikelihoodFn(readCounts); assertEquals(Precision.compareTo(fn.value(alpha), Math.log(likRef * likNonref), tolerance), 0); }
From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.NCauer.java
public NCauer(double Rp, double Rs, int n) { // Cutoff frequency = 1: double wp = 1; // Stop band edge ws: double ws = __ellip_ws(n, Rp, Rs); double k = wp / ws; double k1 = Math.sqrt(1.0 - Math.pow(k, 2)); double q0 = (1.0 / 2.0) * ((1.0 - Math.sqrt(k1)) / (1 + Math.sqrt(k1))); double q = q0 + 2.0 * Math.pow(q0, 5) + 15.0 * Math.pow(q0, 9) + 150.0 * Math.pow(q0, 13); //%(....) double D = (Math.pow(10, 0.1 * Rs) - 1.0) / (Math.pow(10, (0.1 * Rp)) - 1.0); //Filter order maybe this, but not used now: //n=ceil(log10(16*D)/log10(1/q)) double l = (1.0 / (2.0 * n)) * Math.log((Math.pow(10, 0.05 * Rp) + 1.0) / (Math.pow(10, 0.05 * Rp) - 1.0)); double sig01 = 0; double sig02 = 0; for (int m = 0; m <= 30; m++) { sig01 = sig01 + Math.pow((-1), m) * Math.pow(q, (m * (m + 1))) * Math.sinh((2 * m + 1) * l); }// w w w . j av a 2s.c o m for (int m = 1; m <= 30; m++) { sig02 = sig02 + Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2))) * Math.cosh(2 * m * l); } double sig0 = Math.abs((2.0 * Math.pow(q, (1.0 / 4.0)) * sig01) / (1.0 + 2.0 * sig02)); double w = Math.sqrt((1.0 + k * Math.pow(sig0, 2)) * (1.0 + Math.pow(sig0, 2) / k)); int r; if (n % 2 != 0) { r = (n - 1) / 2; } else { r = n / 2; } double[] wi = new double[r]; for (int ii = 1; ii <= r; ii++) { double mu; if (n % 2 != 0) { mu = ii; } else { mu = (double) ii - 0.5; } double soma1 = 0; for (int m = 0; m <= 30; m++) { soma1 = soma1 + 2.0 * Math.pow(q, (1.0 / 4.0)) * (Math.pow(-1.0, m) * Math.pow(q, (m * (m + 1))) * Math.sin(((2.0 * m + 1.0) * Math.PI * mu) / n)); } double soma2 = 0; for (int m = 1; m <= 30; m++) { soma2 = soma2 + 2.0 * (Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2))) * Math.cos((2.0 * m * Math.PI * mu) / n)); } wi[ii - 1] = (soma1 / (1.0 + soma2)); } double[] Vi = new double[wi.length]; for (int i = 0; i < wi.length; i++) { Vi[i] = Math.sqrt((1.0 - (k * (Math.pow(wi[i], 2)))) * (1.0 - (Math.pow(wi[i], 2)) / k)); } double[] A0i = new double[wi.length]; for (int i = 0; i < wi.length; i++) { A0i[i] = 1.0 / (Math.pow(wi[i], 2)); } double[] sqrA0i = new double[wi.length]; for (int i = 0; i < wi.length; i++) { sqrA0i[i] = 1.0 / wi[i]; } double[] B0i = new double[wi.length]; for (int i = 0; i < wi.length; i++) { B0i[i] = (Math.pow((sig0 * Vi[i]), 2) + Math.pow((w * wi[i]), 2)) / Math.pow((1.0 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)), 2); } double C01; if (wi.length == 0) { C01 = 1.0; } else { C01 = B0i[0] / A0i[0]; for (int i = 1; i < wi.length; i++) { C01 *= B0i[i] / A0i[i]; } } //Gain T0: if (n % 2 != 0) { T0 = sig0 * C01 * Math.sqrt(ws); } else { T0 = Math.pow(10, (-0.05 * Rp)) * C01; } //zeros: zer = new Complex[sqrA0i.length * 2]; for (int i = 0; i < sqrA0i.length; i++) { zer[i] = Complex.valueOf(0.0, sqrA0i[i]); zer[i + sqrA0i.length] = Complex.valueOf(0.0, -sqrA0i[i]); } //poles: pol = new Complex[Vi.length * 2]; for (int i = 0; i < Vi.length; i++) { pol[i] = new Complex(-2.0 * sig0 * Vi[i], 2.0 * wi[i] * w) .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2))); pol[i + Vi.length] = new Complex(-2.0 * sig0 * Vi[i], -2.0 * wi[i] * w) .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2))); } //If n odd, there is a real pole -sig0: if (n % 2 != 0) { pol = Arrays.copyOf(pol, pol.length + 1); pol[pol.length - 1] = new Complex(-sig0); } for (int i = 0; i < pol.length; i++) { pol[i] = pol[i].multiply(Math.sqrt(ws)); } for (int i = 0; i < zer.length; i++) { zer[i] = zer[i].multiply(Math.sqrt(ws)); } }