List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:org.gwaspi.reports.PlinkReportLoader.java
public static CombinedRangeXYPlot loadAssocUnadjLogPvsPos(File plinkReport, Set<String> redMarkersHS) throws IOException { XYSeriesCollection chrData = new XYSeriesCollection(); NumberAxis sharedAxis = new NumberAxis("-log?(P)"); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis); combinedPlot.setGap(0);/*from ww w .ja v a2s .com*/ XYSeries series1 = null; XYSeries series2 = null; FileReader inputFileReader = null; BufferedReader inputBufferReader = null; String tempChr = null; try { inputFileReader = new FileReader(plinkReport); inputBufferReader = new BufferedReader(inputFileReader); // Getting data from file and subdividing to series all points by chromosome String l; tempChr = ""; String header = inputBufferReader.readLine(); int count = 0; while ((l = inputBufferReader.readLine()) != null) { if (count % 10000 == 0) { log.info("loadAssocUnadjLogPvsPos -> reader count: {}", count); } count++; l = l.trim().replaceAll("\\s+", ","); String[] cVals = l.split(","); String markerId = cVals[1]; int position = Integer.parseInt(cVals[2]); String s_pVal = cVals[8]; if (!s_pVal.equals("NA")) { double logPValue = Math.abs(Math.log(Double.parseDouble(s_pVal)) / Math.log(10)); if (cVals[0].toString().equals(tempChr)) { if (redMarkersHS.contains(markerId)) { series2.add(position, logPValue); } else { series1.add(position, logPValue); } labeler.put(tempChr + "_" + position, markerId); } else { if (!tempChr.isEmpty()) { // SKIP FIRST TIME (NO DATA YET!) chrData.addSeries(series1); chrData.addSeries(series2); appendToCombinedRangePlot(combinedPlot, tempChr, chrData); } tempChr = cVals[0]; series1 = new XYSeries("Imputed"); series2 = new XYSeries("Observed"); labeler.put(tempChr + "_" + position, markerId); if (redMarkersHS.contains(markerId)) { series2.add(position, logPValue); } else { series1.add(position, logPValue); } } } } } finally { if (inputBufferReader != null) { inputBufferReader.close(); } else if (inputFileReader != null) { inputFileReader.close(); } } chrData.addSeries(series1); chrData.addSeries(series2); appendToCombinedRangePlot(combinedPlot, tempChr, chrData); // ADD LAST CHR TO PLOT return combinedPlot; }
From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierPricer.java
public double price(final BlackFunctionData data, final EuropeanVanillaOption option, final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance, final boolean useVarianceReduction) { Validate.notNull(data, "data"); Validate.notNull(option, "option"); Validate.notNull(ce, "characteristic exponent"); Validate.isTrue(limitTolerance > 0, "limit tolerance must be > 0"); Validate.isTrue(alpha <= ce.getLargestAlpha() && alpha >= ce.getSmallestAlpha(), "The value of alpha is not valid for the Characteristic Exponent and will most likely lead to mispricing. Choose a value between " + ce.getSmallestAlpha() + " and " + ce.getLargestAlpha()); final EuropeanPriceIntegrand integrand = new EuropeanPriceIntegrand(ce, alpha, useVarianceReduction); final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce); final double strike = option.getStrike(); final double t = option.getTimeToExpiry(); final boolean isCall = option.isCall(); final double forward = data.getForward(); final double discountFactor = data.getDiscountFactor(); final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = psi.getFunction(t); final double xMax = LIMIT_CALCULATOR.solve(characteristicFunction, alpha, limitTolerance); final Function1D<Double, Double> func = integrand.getFunction(data, option); final double integral = Math.exp(-alpha * Math.log(strike / forward)) * _integrator.integrate(func, 0.0, xMax) / Math.PI; if (useVarianceReduction) { final double black = BLACK_PRICE_FUNCTION.getPriceFunction(option).evaluate(data); final double diff = discountFactor * forward * integral; return diff + black; }/*from w ww .j av a 2 s .c om*/ if (isCall) { if (alpha > 0.0) { return discountFactor * forward * integral; } else if (alpha < -1.0) { return discountFactor * (forward * (1 + integral) - strike); } else { return discountFactor * forward * (integral + 1); } } if (alpha > 0.0) { return discountFactor * (forward * (integral - 1) + strike); } else if (alpha < -1.0) { return discountFactor * forward * integral; } return discountFactor * (forward * integral + strike); }
From source file:de.bund.bfr.math.LodFunction.java
@Override public double value(double[] point) { double sd = Double.NaN; for (int ip = 0; ip < nParams; ip++) { if (parameters.get(ip).equals(sdParam)) { sd = Math.abs(point[ip]); } else {/*from ww w .j a v a 2s . c o m*/ parser.setVarValue(parameters.get(ip), point[ip]); } } if (sd == 0.0) { return Double.NaN; } double logLikelihood = 0.0; for (int iv = 0; iv < nValues; iv++) { for (Map.Entry<String, List<Double>> entry : variableValues.entrySet()) { parser.setVarValue(entry.getKey(), entry.getValue().get(iv)); } try { double value = parser.evaluate(function); if (!Double.isFinite(value)) { return Double.NaN; } NormalDistribution normDist = new NormalDistribution(value, sd); logLikelihood += targetValues.get(iv) > levelOfDetection ? Math.log(normDist.density(targetValues.get(iv))) : Math.log(normDist.cumulativeProbability(levelOfDetection)); } catch (ParseException e) { e.printStackTrace(); return Double.NaN; } } return logLikelihood; }
From source file:net.sourceforge.jags.model.ModelTest.java
@Test public void testDeterministicNode() { Node n = model.addConstantNode(new int[] { 1 }, new double[] { 8.8 }); Node l = model.addDeterministicNode("log", new Node[] { n }); model.initialize(true);//from w w w. j a v a 2s . c o m model.stopAdapting(); Monitor m = model.addTraceMonitor(l); model.update(10); assertEquals(10, model.getCurrentIteration()); assertEquals(1, m.dim()[0]); // Node dimension assertEquals(10, m.dim()[1]); // Iterations dimension assertEquals(1, m.dim()[2]); // Chains dimension assertEquals(10, m.value(0).length); for (double v : m.value(0)) { assertEquals(Math.log(8.8), v, 0.00001); } }
From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.BetaParameters.java
@Override public double evalEnergy(Value value) { final double x = value.getDouble(); if (x < 0 | x > 1) { return Double.POSITIVE_INFINITY; }// ww w . ja v a2 s. c o m double y; if (_alphaMinusOne == 0.0) { if (_betaMinusOne == 0.0) { return 0.0; } else { y = Math.log(1 - x) * _betaMinusOne; } } else if (_betaMinusOne == 0.0) { y = Math.log(x) * _alphaMinusOne; } else { y = _alphaMinusOne * Math.log(x) + _betaMinusOne * Math.log(1 - x); } return -y; }
From source file:edu.byu.nlp.stats.RandomGenerators.java
/** * This routine generates a random number between 0 and n inclusive, following * the binomial distribution with probability p and n trials. The routine is * based on the BTPE algorithm, described in: * /*w ww .j a v a 2 s. c o m*/ * Voratas Kachitvichyanukul and Bruce W. Schmeiser: * Binomial Random Variate Generation * Communications of the ACM, Volume 31, Number 2, February 1988, pages 216-222. * * Snagged on March 19, 2009 from: * * http://chianti.ucsd.edu/svn/csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/kmeans/KCluster.java * * by Robbie who also converted the uniform() calls to RandomGenerator.nextDouble() * * @param p The probability of a single event. This should be less than or equal to 0.5. * @param n The number of trials * @return An integer drawn from a binomial distribution with parameters (p, n). */ public static int nextBinom(RandomGenerator rnd, int n, double p) { // rah67 March 19, 2007; didn't properly handle the degenerate case if (p == 1.0) return n; double q = 1 - p; if (n * p < 30.0) /* Algorithm BINV */ { double s = p / q; double a = (n + 1) * s; // double r = Math.exp(n*Math.log(q)); /* pow() causes a crash on AIX */ double r = Math.pow(q, n); /* rah67 March 19, 2007 */ int x = 0; double u = rnd.nextDouble(); while (true) { if (u < r) return x; u -= r; x++; r *= (a / x) - s; } } else /* Algorithm BTPE */ { /* Step 0 */ double fm = n * p + p; int m = (int) fm; double p1 = Math.floor(2.195 * Math.sqrt(n * p * q) - 4.6 * q) + 0.5; double xm = m + 0.5; double xl = xm - p1; double xr = xm + p1; double c = 0.134 + 20.5 / (15.3 + m); double a = (fm - xl) / (fm - xl * p); double b = (xr - fm) / (xr * q); double lambdal = a * (1.0 + 0.5 * a); double lambdar = b * (1.0 + 0.5 * b); double p2 = p1 * (1 + 2 * c); double p3 = p2 + c / lambdal; double p4 = p3 + c / lambdar; while (true) { /* Step 1 */ int y; int k; double u = rnd.nextDouble(); double v = rnd.nextDouble(); u *= p4; if (u <= p1) return (int) (xm - p1 * v + u); /* Step 2 */ if (u > p2) { /* Step 3 */ if (u > p3) { /* Step 4 */ y = (int) (xr - Math.log(v) / lambdar); if (y > n) continue; /* Go to step 5 */ v = v * (u - p3) * lambdar; } else { y = (int) (xl + Math.log(v) / lambdal); if (y < 0) continue; /* Go to step 5 */ v = v * (u - p2) * lambdal; } } else { double x = xl + (u - p1) / c; v = v * c + 1.0 - Math.abs(m - x + 0.5) / p1; if (v > 1) continue; /* Go to step 5 */ y = (int) x; } /* Step 5 */ /* Step 5.0 */ k = Math.abs(y - m); if (k > 20 && k < 0.5 * n * p * q - 1.0) { /* Step 5.2 */ double rho = (k / (n * p * q)) * ((k * (k / 3.0 + 0.625) + 0.1666666666666) / (n * p * q) + 0.5); double t = -k * k / (2 * n * p * q); double A = Math.log(v); if (A < t - rho) return y; else if (A > t + rho) continue; else { /* Step 5.3 */ double x1 = y + 1; double f1 = m + 1; double z = n + 1 - m; double w = n - y + 1; double x2 = x1 * x1; double f2 = f1 * f1; double z2 = z * z; double w2 = w * w; if (A > xm * Math.log(f1 / x1) + (n - m + 0.5) * Math.log(z / w) + (y - m) * Math.log(w * p / (x1 * q)) + (13860. - (462. - (132. - (99. - 140. / f2) / f2) / f2) / f2) / f1 / 166320. + (13860. - (462. - (132. - (99. - 140. / z2) / z2) / z2) / z2) / z / 166320. + (13860. - (462. - (132. - (99. - 140. / x2) / x2) / x2) / x2) / x1 / 166320. + (13860. - (462. - (132. - (99. - 140. / w2) / w2) / w2) / w2) / w / 166320.) continue; return y; } } else { /* Step 5.1 */ int i; double s = p / q; double aa = s * (n + 1); double f = 1.0; for (i = m; i < y; f *= (aa / (++i) - s)) ; for (i = y; i < m; f /= (aa / (++i) - s)) ; if (v > f) continue; return y; } } } }
From source file:com.cloudera.oryx.als.common.candidate.LocationSensitiveHashIT.java
private static double[] doTestRandomVecs(LongObjectMap<float[]> Y, float[] userVec) { LocationSensitiveHash lsh = new LocationSensitiveHash(Y, 0.1, 20); LongSet candidates = new LongSet(); float[][] userVecs = { userVec }; for (Iterator<LongObjectMap.MapEntry<float[]>> candidatesIterator : lsh.getCandidateIterator(userVecs)) { while (candidatesIterator.hasNext()) { candidates.add(candidatesIterator.next().getKey()); }/*w ww .j a v a2 s. c om*/ } List<Long> topIDs = findTopRecommendations(Y, userVec); double score = 0.0; double maxScore = 0.0; int intersectionSize = 0; for (int i = 0; i < topIDs.size(); i++) { double value = LN2 / Math.log(2.0 + i); long id = topIDs.get(i); if (candidates.contains(id)) { intersectionSize++; score += value; } maxScore += value; } double percentTopRecsConsidered = (double) intersectionSize / topIDs.size(); double ndcg = maxScore == 0.0 ? 0.0 : score / maxScore; double percentAllItemsConsidered = (double) candidates.size() / Y.size(); return new double[] { percentTopRecsConsidered, ndcg, percentAllItemsConsidered }; }
From source file:com.datumbox.framework.statistics.distributions.ContinuousDistributions.java
/** * Log Gamma Function/*from ww w .j a va2 s . c o m*/ * * @param Z * @return */ public static double LogGamma(double Z) { double S = 1.0 + 76.18009173 / Z - 86.50532033 / (Z + 1.0) + 24.01409822 / (Z + 2.0) - 1.231739516 / (Z + 3.0) + 0.00120858003 / (Z + 4.0) - 0.00000536382 / (Z + 5.0); double LG = (Z - 0.5) * Math.log(Z + 4.5) - (Z + 4.5) + Math.log(S * 2.50662827465); return LG; }
From source file:eu.amidst.core.exponentialfamily.EF_JointNormalGamma.java
/** * {@inheritDoc}/*from ww w .j a v a2 s.c om*/ */ @Override public double computeLogBaseMeasure(double val) { return -0.5 * Math.log(2 * Math.PI); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.AnalyticOptionModel.java
protected double getD1(final double s, final double k, final double t, final double sigma, final double b) { final double numerator = (Math.log(s / k) + t * (b + sigma * sigma / 2)); if (CompareUtils.closeEquals(numerator, 0, 1e-16)) { return 0; }/* w ww . j a va 2 s. c om*/ return numerator / (sigma * Math.sqrt(t)); }