List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:edu.columbia.sel.grout.util.TileUtils.java
/** * For a description see://w w w . j a v a 2s .co m * * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames For a * code-description see: * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames# * compute_bounding_box_for_tile_number * @param aLat * latitude to get the {@link OSMTileInfo} for. * @param aLon * longitude to get the {@link OSMTileInfo} for. * @return The {@link OSMTileInfo} providing 'x' 'y' and 'z'(oom) for the * coordinates passed. */ public static OSMTileInfo getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int y = (int) Math .floor((1 - Math.log(Math.tan(aLat * Math.PI / 180) + 1 / Math.cos(aLat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)); final int x = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return new OSMTileInfo(x, y, zoom); }
From source file:Util.java
/** * Sums an array of numbers log(x1)...log(xn). This saves some of * the unnecessary calls to Math.log in the two-argument version. * <p>/*from w ww . j av a 2 s . c om*/ * Note that this implementation IGNORES elements of the input * array that are more than LOGTOLERANCE (currently 30.0) less * than the maximum element. * <p> * Cursory testing makes me wonder if this is actually much faster than * repeated use of the 2-argument version, however -cas. * @param vals An array log(x1), log(x2), ..., log(xn) * @return log(x1+x2+...+xn) */ public static double sumLogProb(double[] vals) { double max = Double.NEGATIVE_INFINITY; int len = vals.length; int maxidx = 0; for (int i = 0; i < len; i++) { if (vals[i] > max) { max = vals[i]; maxidx = i; } } boolean anyAdded = false; double intermediate = 0.0; double cutoff = max - LOGTOLERANCE; for (int i = 0; i < maxidx; i++) { if (vals[i] >= cutoff) { anyAdded = true; intermediate += Math.exp(vals[i] - max); } } for (int i = maxidx + 1; i < len; i++) { if (vals[i] >= cutoff) { anyAdded = true; intermediate += Math.exp(vals[i] - max); } } if (anyAdded) { return max + Math.log(1.0 + intermediate); } else { return max; } }
From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SVIVolatilityFunction.java
@Override public Function1D<SVIFormulaData, Double> getVolatilityFunction(final EuropeanVanillaOption option, final double forward) { Validate.notNull(option, "option"); Validate.isTrue(forward > 0, "Need forward >= 0"); final double strike = option.getStrike(); Validate.isTrue(strike > 0, "Need strike >= 0"); final double kappa = Math.log(strike / forward); return new Function1D<SVIFormulaData, Double>() { @SuppressWarnings("synthetic-access") @Override//from w ww. jav a2 s .co m public Double evaluate(final SVIFormulaData data) { return getVolatility(kappa, data); } }; }
From source file:com.linkedin.pinot.perf.ForwardIndexWriterBenchmark.java
public static void convertRawToForwardIndex(File rawFile) throws Exception { List<String> lines = IOUtils.readLines(new FileReader(rawFile)); int totalDocs = lines.size(); int max = Integer.MIN_VALUE; int maxNumberOfMultiValues = Integer.MIN_VALUE; int totalNumValues = 0; int data[][] = new int[totalDocs][]; for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String[] split = line.split(","); totalNumValues = totalNumValues + split.length; if (split.length > maxNumberOfMultiValues) { maxNumberOfMultiValues = split.length; }// www . j a v a2 s . c om data[i] = new int[split.length]; for (int j = 0; j < split.length; j++) { String token = split[j]; int val = Integer.parseInt(token); data[i][j] = val; if (val > max) { max = val; } } } int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2)); int size = 2048; int[] offsets = new int[size]; int bitMapSize = 0; File outputFile = new File("output.mv.fwd"); FixedBitMultiValueWriter fixedBitSkipListSCMVWriter = new FixedBitMultiValueWriter(outputFile, totalDocs, totalNumValues, maxBitsNeeded); for (int i = 0; i < totalDocs; i++) { fixedBitSkipListSCMVWriter.setIntArray(i, data[i]); if (i % size == size - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } else if (i == totalDocs - 1) { MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); rr1.serialize(dos); dos.close(); // System.out.println("Chunk " + i / size + " bitmap size:" + bos.size()); bitMapSize += bos.size(); } } fixedBitSkipListSCMVWriter.close(); System.out.println("Output file size:" + outputFile.length()); System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs); System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues); System.out.println("chunk size\t\t\t\t:" + size); System.out.println("Num chunks\t\t\t\t:" + totalDocs / size); int numChunks = totalDocs / size + 1; int totalBits = (totalNumValues * maxBitsNeeded); int dataSizeinBytes = (totalBits + 7) / 8; System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes); System.out.println("\nPer encoding size"); System.out.println(); System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes)); System.out.println(); System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes)); System.out.println(); System.out.println("bitMapSize\t\t\t\t:" + bitMapSize); System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes)); System.out.println(); System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8); System.out.println("size (with custom bitset)\t\t\t:" + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes)); }
From source file:com.cloudera.science.mgps.NFunction.java
public double eval(int n, double e) { double x = -n * Math.log(1 + beta / e); double y = -alpha * Math.log(1 + e / beta); double z = Gamma.logGamma(alpha + n); double d = Gamma.logGamma(alpha) + MathUtils.factorialLog(n); return Math.exp(x + y + z - d); }
From source file:emlab.util.GeometricTrendRegression.java
public void addData(double x, double y) { super.addData(x, Math.log(y)); }
From source file:etomica.math.SpecialFunctions.java
public static double lnFactorial(int n) { if (n < 0) { throw new IllegalArgumentException("Argument less than zero: " + n); }/*from w ww .ja v a2s . c om*/ if (n < 2) { return 0; } long p = 1; double sum = 0; for (int i = n; i > 1; i--) { p *= i; if (p > Integer.MAX_VALUE / (p - 1)) { sum += Math.log(p); p = 1; } } sum += Math.log(p); return sum; }
From source file:com.opengamma.analytics.financial.model.volatility.surface.SkewnessKurtosisBlackScholesMertonEquivalentVolatilitySurfaceModel.java
@Override public VolatilitySurface getSurface(final OptionDefinition option, final SkewKurtosisOptionDataBundle data) { Validate.notNull(option, "option"); Validate.notNull(data, "data"); final double s = data.getSpot(); final double t = option.getTimeToExpiry(data.getDate()); final double k = option.getStrike(); final double sigma = data.getVolatility(t, k); final double b = data.getCostOfCarry(); final double skew = data.getAnnualizedSkew(); final double kurtosis = data.getAnnualizedFisherKurtosis(); final double d1 = (Math.log(s / k) + t * (b + sigma * sigma * 0.5)) / sigma / Math.sqrt(t); return new VolatilitySurface( ConstantDoublesSurface.from(sigma * (1 - skew * d1 / 6 - kurtosis * (1 - d1 * d1) / 24))); }
From source file:geogebra.util.MyMath.java
final public static double acosh(double a) { return Math.log(a + Math.sqrt(a * a - 1.0)); }
From source file:edu.byu.nlp.stats.UniformDistribution.java
/** {@inheritDoc} */ @Override public double logMax() { return -Math.log(numLabels); }