List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:co.mitro.core.util.RPCLogReplayer.java
private static double nextExp(double lambda) { double u;/*from w w w . ja v a 2s . c o m*/ do { u = RNG.nextDouble(); } while (0 == u); return (-Math.log(u)) / lambda; }
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SABRPaulotVolatilityFunction.java
@Override public Function1D<SABRFormulaData, Double> getVolatilityFunction(final EuropeanVanillaOption option, final double forward) { Validate.notNull(option, "option"); final double strike = option.getStrike(); final double cutoff = forward * CUTOFF_MONEYNESS; final double k; if (strike < cutoff) { s_logger.info("Given strike of " + strike + " is less than cutoff at " + cutoff + ", therefore the strike is taken as " + cutoff); k = cutoff;/*from www . ja va2 s . com*/ } else { k = strike; } final double t = option.getTimeToExpiry(); return new Function1D<SABRFormulaData, Double>() { @SuppressWarnings("synthetic-access") @Override public final Double evaluate(final SABRFormulaData data) { Validate.notNull(data, "data"); final double alpha = data.getAlpha(); final double beta = data.getBeta(); final double rho = data.getRho(); final double nu = data.getNu(); double sigma0, sigma1; final double beta1 = 1 - beta; final double x = Math.log(k / forward); if (CompareUtils.closeEquals(nu, 0, EPS)) { if (CompareUtils.closeEquals(beta, 1.0, EPS)) { return alpha; // this is just log-normal } throw new NotImplementedException("Have not implemented the case where nu = 0, beta != 0"); } // the formula behaves very badly close to ATM if (CompareUtils.closeEquals(x, 0.0, 1e-3)) { final double delta = 1.01e-3; final double a0 = (HAGAN.getVolatilityFunction(option, forward)).evaluate(data); double kPlus, kMinus; kPlus = forward * Math.exp(delta); kMinus = forward * Math.exp(-delta); EuropeanVanillaOption other = new EuropeanVanillaOption(kPlus, option.getTimeToExpiry(), option.isCall()); final double yPlus = getVolatilityFunction(other, forward).evaluate(data); other = new EuropeanVanillaOption(kMinus, option.getTimeToExpiry(), option.isCall()); final double yMinus = getVolatilityFunction(other, forward).evaluate(data); final double a2 = (yPlus + yMinus - 2 * a0) / 2 / delta / delta; final double a1 = (yPlus - yMinus) / 2 / delta; return a2 * x * x + a1 * x + a0; } final double tScale = nu * nu * t; final double alphaScale = alpha / nu; double q; if (CompareUtils.closeEquals(beta, 1.0, EPS)) { q = x; } else { q = (Math.pow(k, beta1) - Math.pow(forward, beta1)) / beta1; } final double vMin = Math.sqrt(alphaScale * alphaScale + 2 * rho * alphaScale * q + q * q); final double logTerm = Math.log((vMin + rho * alphaScale + q) / (1 + rho) / alphaScale); sigma0 = x / logTerm; final double cTilde = getCTilde(forward, k, alphaScale, beta, rho, q); sigma1 = -(cTilde + Math.log(sigma0 * Math.sqrt(k * forward))) / square(logTerm); return nu * sigma0 * (1 + sigma1 * tScale); } }; }
From source file:de.unijena.bioinf.FragmentationTreeConstruction.computation.scoring.MassDeviationVertexScorer.java
@Override public double score(MolecularFormula formula, ProcessedPeak peak, ProcessedInput input, Object _) { if (peak.getOriginalPeaks().isEmpty()) return 0d; // don't score synthetic peaks final double theoreticalMass = formula.getMass(); final double realMass = useOriginalMz ? (peak.getUnmodifiedOriginalMass()) : peak.getUnmodifiedMass(); final MeasurementProfile profile = input.getMeasurementProfile(); final Deviation dev = standardDeviation != null ? standardDeviation : profile.getStandardMs2MassDeviation(); final double sd = dev.absoluteFor(realMass); return Math.log(Erf.erfc(Math.abs(realMass - theoreticalMass) / (sd * sqrt2))); }
From source file:edu.cmu.tetrad.search.Test.java
private double logOfSum(List<Double> logs) { Collections.sort(logs, new Comparator<Double>() { @Override//from ww w. j av a 2 s . c o m public int compare(Double o1, Double o2) { return -Double.compare(o1, o2); } }); double sum = 0.0; int N = logs.size() - 1; double loga0 = logs.get(0); for (int i = 1; i <= N; i++) { sum += Math.exp(logs.get(i) - loga0); } sum += 1; return loga0 + Math.log(sum); }
From source file:hammingcode.HammingCode.java
String addCheckBits(String str, String parity) { String codeWord = ""; double noOfCheckBits = Math.log(str.length()); noOfCheckBits /= Math.log(2); noOfCheckBits++;/*from w w w . jav a 2 s. c o m*/ for (int i = 0, j = 1; j <= str.length() + noOfCheckBits; j++) { if ((j & (j - 1)) == 0) { codeWord += "0"; } else { codeWord += str.charAt(i); i++; } } str = codeWord; codeWord = ""; for (int i = 0, j = 1; j <= str.length() + noOfCheckBits; j++) { if ((j & (j - 1)) == 0) { if (StringUtils.equalsIgnoreCase(parity, "even")) { if (StringUtils.countMatches(takeNthPower(str, j), "1") % 2 == 0) { codeWord += "0"; } else { codeWord += "1"; } } else if (StringUtils.equalsIgnoreCase(parity, "odd")) { if (StringUtils.countMatches(takeNthPower(str, j), "1") % 2 == 0) { codeWord += "1"; } else { codeWord += "0"; } } } else { codeWord += str.charAt(i); i++; } } return codeWord; }
From source file:com.opengamma.analytics.math.interpolation.ExponentialExtrapolator1D.java
private Double leftExtrapolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(data, "data"); Validate.notNull(value, "value"); final double x = data.firstKey(); final double y = data.firstValue(); final double m = Math.log(y) / x; return Math.exp(m * value); }
From source file:edu.illinois.cs.cogcomp.utils.Utils.java
/** * This measures the WAVE score of a set of productions. WAVE score comes from (Kumaran et al 2010) * It is a measure of transliterability. * @param fname the file name of a set of learned productions. * @return WAVE score/*from www.ja va 2s . c o m*/ */ public static double WAVE(String fname) throws FileNotFoundException { List<String> lines = LineIO.read(fname); HashMap<String, Integer> srcFreq = new HashMap<>(); HashMap<String, Integer> tgtFreq = new HashMap<>(); HashMap<String, Double> entropy = new HashMap<>(); for (String line : lines) { if (line.trim().length() == 0 || line.startsWith("#")) { continue; } String[] sline = line.split("\t"); String src = sline[0]; String tgt = sline[1]; double prob = Double.parseDouble(sline[2]); Dictionaries.IncrementOrSet(srcFreq, src, 1, 1); Dictionaries.IncrementOrSet(tgtFreq, tgt, 1, 1); double v = prob * Math.log(prob); Dictionaries.IncrementOrSet(entropy, src, v, v); } double total = 0; for (int v : srcFreq.values()) { total += v; } double WAVE = 0; for (String i : srcFreq.keySet()) { // -= because entropy should be negative, but I never do it. WAVE -= srcFreq.get(i) / total * entropy.get(i); } return WAVE; }
From source file:dr.math.distributions.KernelDensityEstimatorDistribution.java
/** * the natural log of the probability density function of the distribution * * @param x argument/*w ww .j a v a2s .c o m*/ * @return log pdf value */ public double logPdf(double x) { return Math.log(pdf(x)); }
From source file:de.unijena.bioinf.IsotopePatternAnalysis.scoring.MassDeviationScorer.java
@Override public double score(Spectrum<Peak> measured, Spectrum<Peak> theoretical, Normalization norm, Ms2Experiment experiment, MeasurementProfile profile) { if (measured.size() > theoretical.size()) throw new IllegalArgumentException("Theoretical spectrum is smaller than measured spectrum"); // remove peaks from theoretical pattern until the length of both spectra is equal final MutableSpectrum<Peak> theoreticalSpectrum = new SimpleMutableSpectrum(theoretical); while (measured.size() < theoreticalSpectrum.size()) { theoreticalSpectrum.removePeakAt(theoreticalSpectrum.size() - 1); }//from w ww . j ava 2 s . com // re-normalize Spectrums.normalize(theoreticalSpectrum, norm); final double mz0 = measured.getMzAt(0); final double thMz0 = theoreticalSpectrum.getMzAt(0); final double int0 = measured.getIntensityAt(0); double score = Math.log( Erf.erfc(Math.abs(thMz0 - mz0) / (root2 * (profile.getStandardMs1MassDeviation().absoluteFor(mz0) * intensityDependency.getValueAt(int0))))); for (int i = 1; i < measured.size(); ++i) { final double mz = measured.getMzAt(i) - mz0; final double thMz = theoreticalSpectrum.getMzAt(i) - thMz0; final double thIntensity = measured.getIntensityAt(i); // TODO: thMz hier richtig? final double sd = profile.getStandardMassDifferenceDeviation().absoluteFor(measured.getMzAt(i)) * intensityDependency.getValueAt(thIntensity); score += Math.log(Erf.erfc(Math.abs(thMz - mz) / (root2 * sd))); } return score; }
From source file:com.datumbox.common.utilities.PHPfunctions.java
public static double log(double d, double base) { if (base == 1.0 || base <= 0.0) { throw new RuntimeException("Invalid base for logarithm"); }//from w w w .ja v a2s. c om return Math.log(d) / Math.log(base); }