List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:com.doplgangr.secrecy.FileSystem.File.java
private static String humanReadableByteCount(long bytes) { int unit = 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); char pre = ("KMGTPE").charAt(exp - 1); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
From source file:it.cnr.jatecs.indexing.tsr.ConfWeight.java
private double strength(double minPosRelFreq, double minPos, double maxNeg) { if (minPos > maxNeg) { return Math.log(2 * minPosRelFreq) / log2; } else {// w w w.ja v a 2 s . c o m return 0.0; } }
From source file:hivemall.utils.math.MathUtils.java
/** * <a href="https://en.wikipedia.org/wiki/Logit">Logit</a> is the inverse of * {@link #sigmoid(double)} function./*from w w w . j a v a 2s .c o m*/ */ public static double logit(final double p) { return Math.log(p / (1.d - p)); }
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.ForwardStartOptionModel.java
@Override public Function1D<StandardOptionDataBundle, Double> getPricingFunction( final ForwardStartOptionDefinition definition) { Validate.notNull(definition, "definition"); return new Function1D<StandardOptionDataBundle, Double>() { @SuppressWarnings("synthetic-access") @Override//ww w . j a v a 2 s. com public Double evaluate(final StandardOptionDataBundle data) { Validate.notNull(data, "data"); final ZonedDateTime date = data.getDate(); final double s = data.getSpot(); final double t = definition.getTimeToExpiry(date); final double start = definition.getTimeToStart(date); final double b = data.getCostOfCarry(); final double r = data.getInterestRate(t); // does this need r at both times? final double alpha = definition.getAlpha(); final double sigma = data.getVolatility(t, alpha * s); final double deltaT = t - start; final double df1 = Math.exp(start * (b - r)); final double df2 = Math.exp(deltaT * (b - r)); final double df3 = Math.exp(-r * deltaT); final double sigmaT = sigma * Math.sqrt(deltaT); final double d1 = (Math.log(1. / alpha) + deltaT * (b + 0.5 * sigma * sigma)) / sigmaT; final double d2 = d1 - sigmaT; final int sign = definition.isCall() ? 1 : -1; return s * df1 * (sign * (df2 * NORMAL.getCDF(sign * d1) - alpha * df3 * NORMAL.getCDF(sign * d2))); } }; }
From source file:dr.evomodel.epidemiology.casetocase.periodpriors.OneOverStDevPeriodPriorDistribution.java
public double calculateLogLikelihood(double[] values) { DescriptiveStatistics stats = new DescriptiveStatistics(values); logL = -Math.log(stats.getStandardDeviation()); return logL;// w w w . j ava2 s . co m }
From source file:com.mapr.synth.samplers.VectorSamplerTest.java
@Test public void testVector() throws IOException { SchemaSampler s = new SchemaSampler( Resources.asCharSource(Resources.getResource("schema029.json"), Charsets.UTF_8).read()); for (int i = 0; i < 10; i++) { JsonNode data = s.sample();/*from w ww. j av a 2 s . c o m*/ /* { "class": "vector", "name": "prices", "mean": 4.65, "sd": 0.01, "length": 10000, "transform": "exp", "seed": 1, }, */ JsonNode v = data.get("prices"); assertTrue(v.isArray()); assertEquals(10000, v.size()); double[] v1 = new double[10000]; double[] v2 = new double[10000]; for (int j = 0; j < 10000; j++) { v1[j] = v.get(j).asDouble(); v2[j] = Math.log(v1[j]); } assertEquals(100, median(v1), 0.03); assertEquals(100, mean(v1), 0.05); assertEquals(Math.log(100), mean(v2), 0.001); assertEquals(0.01, sd(v2), 0.0003); assertTrue(isNormal(v2, Math.log(100), 0.01)); /* { "class": "vector", "name": "zero", "mean": 0, "sd": 10, "length": 10000, "seed": 2 }, */ v = data.get("zero"); assertTrue(v.isArray()); for (int j = 0; j < 10000; j++) { v1[j] = v.get(j).asDouble(); } assertEquals(0, mean(v1), 0.3); assertEquals(10, sd(v1), 0.2); assertTrue(isNormal(v1, 0, 10)); /* { "class": "vector", "name": "clipped", "mean": 0, "sd": 10, "length": 10000, "max": 0, "seed": 3 }, */ v = data.get("clipped"); assertTrue(v.isArray()); Random rand = new Random(); for (int j = 0; j < 10000; j++) { v1[j] = v.get(j).asDouble(); assertTrue(v1[j] <= 0); v1[j] = v1[j] * (rand.nextBoolean() ? 1 : -1); } assertEquals(0, mean(v1), 0.3); assertEquals(10, sd(v1), 0.3); assertTrue(isNormal(v1, 0, 10)); /* { "class": "vector", "name": "ten", "min": 1, "max": 10, "length": 20000, "transform": "log", "seed": 4 } ] */ v = data.get("ten"); assertTrue(v.isArray()); for (int j = 0; j < 10000; j++) { v1[j] = v.get(j).asDouble(); v2[j] = Math.exp(v1[j]); assertTrue(v1[j] >= 1); assertTrue(v1[j] <= 10); } assertTrue(isUniform(v2, Math.exp(1), Math.exp(10))); v = data.get("coarse"); assertTrue(v.isArray()); for (int j = 0; j < 10000; j++) { double x = v.get(j).asDouble(); assertTrue(x >= 1); assertTrue(x <= 10); assertEquals(Math.rint(x / 0.1) * 0.1, x, 1e-10); } } }
From source file:de.tudarmstadt.ukp.dkpro.bigdata.collocations.AssociationMetrics.java
public double pmi() { return Math.log(e11 / (e12) * (e21)) / Math.log(2); }
From source file:beast.math.distributions.NormalGamma.java
@Override public double calcLogP(Function fun) { if (fun.getDimension() != 2) { throw new IllegalArgumentException("Argument to calcLogP has the wrong dimension (should be 2)"); }// w ww. ja v a 2 s. c o m double mu = getMu(); double lambda = getLambda(); double alpha = getAlpha(); double beta = getBeta(); double x = fun.getArrayValue(0); double tau = fun.getArrayValue(1); return alpha * Math.log(beta) + 0.5 * Math.log(lambda) + (alpha - 0.5) * Math.log(tau) - beta * tau - lambda * tau * Math.pow(x - mu, 2) / 2 - GammaFunction.lnGamma(alpha) - 0.5 * Math.log(2 * Math.PI); }
From source file:etymology.util.EtyMath.java
public static double logPlus(double a, double b) { double logPlus = 0; double max = Math.max(a, b); double min = Math.min(a, b); logPlus = max + Math.log(1.0 + Math.exp(min - max)); return logPlus; }
From source file:com.exzogeni.dk.graphics.Bitmaps.java
public static int calculateInSampleSize(BitmapFactory.Options ops, int hwSize) { final int outHeight = ops.outHeight; final int outWidth = ops.outWidth; if (outWidth > hwSize || outHeight > hwSize) { final double ratio = Math.max(Math.round((double) outWidth / (double) hwSize), Math.round((double) outHeight / (double) hwSize)); return ratio > 0 ? (int) Math.pow(2, Math.floor(Math.log(ratio) / LN_2)) : 1; }//from w w w . j a v a 2 s.c o m return 1; }