List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:beast.math.distribution.GammaDistributionTest.java
/** * This test stochastically draws gamma//from ww w . j a va2s . co m * variates and compares the coded pdf * with the actual pdf. * The tolerance is required to be at most 1e-10. */ static double mypdf(double value, double shape, double scale) { return Math.exp( (shape - 1) * Math.log(value) - value / scale - Gamma.logGamma(shape) - shape * Math.log(scale)); }
From source file:Main.java
/** * See: http://stackoverflow.com/questions/477572/android-strange * -out-of-memory-issue-while-loading-an-image * -to-a-bitmap-object/823966#823966 * Thanks to StackOverflow user named Fedor. *//* w ww . j ava 2 s . c o m*/ public static Bitmap decodeFile(File f, int size) { Bitmap b = null; try { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > size || o.outWidth > size) { scale = (int) Math.pow(2.0, (int) Math .round(Math.log(size / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inTempStorage = new byte[32 * 1024]; o2.inPurgeable = true; o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (IOException e) { } return b; }
From source file:com.opengamma.strata.math.impl.function.special.GammaFunctionTest.java
@Test public void test() { final double x = RANDOM.nextDouble(); assertEquals(Math.log(GAMMA.applyAsDouble(x)), LN_GAMMA.apply(x), EPS); }
From source file:gedi.util.math.stat.distributions.LfcDistribution.java
public static double var(double a, double b) { return (Gamma.trigamma(a) + Gamma.trigamma(b)) / Math.log(2) / Math.log(2); }
From source file:gov.nih.nci.calims2.business.inventory.container.CoordinateHelper.java
private static String convertValue(char firstCharacter, int maximum, int value) { int length = (int) Math.floor(Math.log(maximum) / Math.log(LETTER_BASE)) + 1; if (value == 0) { return StringUtils.repeat(Character.toString(firstCharacter), length); }//from w ww . j a v a2 s .com String result = ""; int remaining = value; while (remaining > 0) { result = Character.toString((char) (firstCharacter + remaining % LETTER_BASE)) + result; remaining /= LETTER_BASE; } while (result.length() < length) { result = firstCharacter + result; } return result; }
From source file:Main.java
/** * Returns the closest power-of-two number less than or equal to x. * * @param x input value/*from w w w. j av a 2s . c o m*/ * * @return the closest power-of-two number less then or equal to x */ public static int prevPow2(int x) { if (x < 1) { throw new IllegalArgumentException("x must be greater or equal 1"); } return (int) Math.pow(2, Math.floor(Math.log(x) / Math.log(2))); }
From source file:com.opengamma.analytics.financial.model.option.pricing.tree.LeisenReimerLatticeSpecification.java
@Override public double[] getParameters(final double spot, final double strike, final double timeToExpiry, final double volatility, final double interestRate, final int nSteps, final double dt) { Validate.isTrue((nSteps % 2 == 1), "The number of steps should be odd"); final double sigmaRootT = volatility * Math.sqrt(timeToExpiry); final double d1 = (Math.log(spot / strike) + interestRate * timeToExpiry) / sigmaRootT + 0.5 * sigmaRootT; final double d2 = d1 - sigmaRootT; final double sig1 = d1 >= 0. ? 1. : -1.; final double sig2 = d2 >= 0. ? 1. : -1.; final double coef1 = d1 / (nSteps + 1. / 3. + 0.1 / (nSteps + 1.)); final double coef2 = d2 / (nSteps + 1. / 3. + 0.1 / (nSteps + 1.)); final double p1 = 0.5 + sig1 * 0.5 * Math.sqrt(1. - Math.exp(-coef1 * coef1 * (nSteps + 1. / 6.))); final double p2 = 0.5 + sig2 * 0.5 * Math.sqrt(1. - Math.exp(-coef2 * coef2 * (nSteps + 1. / 6.))); final double rr = Math.exp(interestRate * dt); final double upFactor = rr * p1 / p2; final double downFactor = (rr - p2 * upFactor) / (1 - p2); return new double[] { upFactor, downFactor, p2, 1 - p2 }; }
From source file:gedi.core.data.reads.functions.ReadDirichletLikelihoodRatioTest.java
public static double logProbability(double[] alpha1, double[] p) { double re = 0; double asum = 0; double gsum = 0; for (int i = 0; i < p.length; i++) { re += Math.log(p[i]) * (alpha1[i]); asum += alpha1[i] + 1;/*from ww w . java 2 s . c om*/ gsum += Gamma.logGamma(alpha1[i] + 1); } return re + Gamma.logGamma(asum) - gsum; }
From source file:Main.java
public static Bitmap loadMpoBitmapFromFile(File file, long offset, int maxWidth, int maxHeight) throws IOException { // First, decode the width and height of the image, so that we know how much to scale // it down when loading it into our ImageView (so we don't need to do a huge allocation). BitmapFactory.Options opts = new BitmapFactory.Options(); InputStream fs = null;/* w w w . j av a 2s. co m*/ try { fs = new BufferedInputStream(new FileInputStream(file)); fs.skip(offset); opts.inJustDecodeBounds = true; BitmapFactory.decodeStream(fs, null, opts); } finally { if (fs != null) { try { fs.close(); } catch (IOException e) { // don't worry } } } int scale = 1; if (opts.outHeight > maxHeight || opts.outWidth > maxWidth) { scale = (int) Math.pow(2, (int) Math .round(Math.log(maxWidth / (double) Math.max(opts.outHeight, opts.outWidth)) / Math.log(0.5))); } if ((opts.outHeight <= 0) || (opts.outWidth <= 0)) { return null; } // Decode the image for real, but now with a sampleSize. // We have to reopen the file stream, and re-skip to the correct offset, since // FileInputStream doesn't support reset(). Bitmap bmp = null; fs = null; try { fs = new BufferedInputStream(new FileInputStream(file)); fs.skip(offset); BitmapFactory.Options opts2 = new BitmapFactory.Options(); opts2.inSampleSize = scale; bmp = BitmapFactory.decodeStream(fs, null, opts2); } finally { if (fs != null) { try { fs.close(); } catch (IOException e) { // don't worry } } } return bmp; }
From source file:Main.java
public static double logGamma(final double xx) { final double stp = 2.50662827465; final double[] cof = { 76.18009173, -86.50532033, 24.01409822, -1.231739516, 0.00120858003, -5.36382E-6 }; double x = xx - 1.0; double tmp = x + 5.5; tmp = (x + 0.5) * Math.log(tmp) - tmp; double ser = 1.0; for (int j = 0; j < 6; ++j) { ++x;/*from w w w . j a va2 s. c om*/ ser += cof[j] / x; } final double retVal = tmp + Math.log(2.50662827465 * ser); return retVal; }