Example usage for java.lang Math log

List of usage examples for java.lang Math log

Introduction

In this page you can find the example usage for java.lang Math log.

Prototype

@HotSpotIntrinsicCandidate
public static double log(double a) 

Source Link

Document

Returns the natural logarithm (base e) of a double value.

Usage

From source file:Main.java

public static Bitmap decodeFile(File theFile, int IMAGE_MAX_SIZE) {
    Bitmap bmp = null;// www  . j a v  a 2  s.c  o m
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(theFile);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
            scale = (int) Math.pow(2, (int) Math.round(
                    Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(theFile);
        bmp = BitmapFactory.decodeStream(fis, null, o2);

        fis.close();
    } catch (IOException e) {
    }
    return bmp;
}

From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java

public static Bitmap loadPrescaledBitmap(String filename) throws IOException {
    // Facebook image size
    final int IMAGE_MAX_SIZE = 630;

    File file = null;/* w ww. jav  a2 s. c  o  m*/
    FileInputStream fis;

    BitmapFactory.Options opts;
    int resizeScale;
    Bitmap bmp;

    file = new File(filename);

    // This bit determines only the width/height of the bitmap without loading the contents
    opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;
    fis = new FileInputStream(file);
    BitmapFactory.decodeStream(fis, null, opts);
    fis.close();

    // Find the correct scale value. It should be a power of 2
    resizeScale = 1;

    if (opts.outHeight > IMAGE_MAX_SIZE || opts.outWidth > IMAGE_MAX_SIZE) {
        resizeScale = (int) Math.pow(2, (int) Math.round(
                Math.log(IMAGE_MAX_SIZE / (double) Math.max(opts.outHeight, opts.outWidth)) / Math.log(0.5)));
    }

    // Load pre-scaled bitmap
    opts = new BitmapFactory.Options();
    opts.inSampleSize = resizeScale;
    fis = new FileInputStream(file);
    bmp = BitmapFactory.decodeStream(fis, null, opts);

    fis.close();

    return bmp;
}

From source file:edu.byu.nlp.stats.UniformDistribution.java

/** {@inheritDoc} */
@Override
public double entropy() {
    return Math.log(numLabels);
}

From source file:emlab.util.GeometricTrendRegression.java

public void addData(double[][] data) {
    for (int i = 0; i < data.length; i++) {
        addData(data[i][0], Math.log(data[i][1]));
    }//from  w  w w . ja v a2  s .  co  m
}

From source file:ldbc.snb.datagen.generator.distribution.utils.Bucket.java

public static ArrayList<Bucket> bucketizeHistogram(ArrayList<Pair<Integer, Integer>> histogram,
        int num_buckets) {

    ArrayList<Bucket> buckets = new ArrayList<Bucket>();
    int population = 0;
    int num_edges = 0;
    for (Pair<Integer, Integer> i : histogram) {
        population += i.getValue();/*from   ww w  . j a va 2  s. c  o m*/
        num_edges += i.getValue() * i.getKey();
    }
    num_edges /= 2;

    int avgDegreeAt1B = 200;
    int avgDegree = num_edges / population;
    double aCoeff = Math.log(avgDegreeAt1B) / Math.log(1000000000);
    double bCoeff = (aCoeff - (Math.log(avgDegree) / Math.log(population))) / Math.log10(population);

    int target_mean = (int) Math.round(
            Math.pow(DatagenParams.numPersons, (aCoeff - bCoeff * Math.log10(DatagenParams.numPersons))));
    System.out.println("Distribution mean degree: " + avgDegree + " Distribution target mean " + target_mean);
    int bucket_size = (int) (Math.ceil(population / (double) (num_buckets)));
    int current_histogram_index = 0;
    int current_histogram_left = histogram.get(current_histogram_index).getValue();
    for (int i = 0; i < num_buckets && (current_histogram_index < histogram.size()); ++i) {
        int current_bucket_count = 0;
        int min = population;
        int max = 0;
        while (current_bucket_count < bucket_size && current_histogram_index < histogram.size()) {
            int degree = histogram.get(current_histogram_index).getKey();
            min = degree < min ? degree : min;
            max = degree > max ? degree : max;
            if ((bucket_size - current_bucket_count) > current_histogram_left) {
                current_bucket_count += current_histogram_left;
                current_histogram_index++;
                if (current_histogram_index < histogram.size()) {
                    current_histogram_left = histogram.get(current_histogram_index).getValue();
                }
            } else {
                current_histogram_left -= (bucket_size - current_bucket_count);
                current_bucket_count = bucket_size;
            }
        }
        min = (int) (min * target_mean / (double) avgDegree);
        max = (int) (max * target_mean / (double) avgDegree);
        buckets.add(new Bucket(min, max));
    }
    return buckets;
}

From source file:io.seldon.vw.VwFeatureHash.java

private double log2(int val, int base) {
    return Math.log(val) / Math.log(base);
}

From source file:com.opengamma.analytics.financial.interestrate.market.MarketDiscountingTimeDecorated.java

@Override
public double getDiscountingFactor(Currency ccy, Double time) {
    if ((ccy == _ccy) && (_time == time)) {
        double rate = -Math.log(super.getDiscountingFactor(ccy, time)) / time;
        return Math.exp(-(rate + _shift) * time);
    }//  ww w.j  a va2s.  c o m
    return super.getDiscountingFactor(ccy, time);
}

From source file:geogebra.util.MyMath.java

final public static double atanh(double a) {
    return Math.log((1.0 + a) / (1.0 - a)) * 0.5;
}

From source file:beast.math.distributions.NegativeBinomialDistribution.java

public double logPdf(double x) {
    if (x < 0)
        return Double.NEGATIVE_INFINITY;
    double r = -1 * (mean * mean) / (mean - stdev * stdev);
    double p = mean / (stdev * stdev);
    return Math.log(Math.pow(1 - p, x)) + Math.log(Math.pow(p, r)) + GammaFunction.lnGamma(r + x)
            - GammaFunction.lnGamma(r) - GammaFunction.lnGamma(x + 1);
}

From source file:com.opengamma.analytics.financial.interestrate.market.description.MarketDiscountingTimeDecorated.java

@Override
public double getDiscountFactor(Currency ccy, Double time) {
    if ((ccy == _ccy) && (_time == time)) {
        double rate = -Math.log(super.getDiscountFactor(ccy, time)) / time;
        return Math.exp(-(rate + _shift) * time);
    }//from w w  w .ja  v a2  s  .  c o  m
    return super.getDiscountFactor(ccy, time);
}