Example usage for org.apache.commons.math3.util FastMath log

List of usage examples for org.apache.commons.math3.util FastMath log

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath log.

Prototype

public static double log(final double x) 

Source Link

Document

Natural logarithm.

Usage

From source file:com.davidbracewell.math.functions.LogLoss.java

@Override
public double calculate(double n1, double n2) {
    return FastMath.log(1 + FastMath.exp(-(n1 * n2)));
}

From source file:com.insightml.math.distributions.AbstractGaussian.java

@Override
public double bhattacharyyaDistance(final IGaussian other) {
    final double var1 = Maths.pow(standardDeviation(), 2);
    final double var2 = Maths.pow(other.standardDeviation(), 2);

    final double left = 1.0 / 4 * FastMath.log(1.0 / 4 * (var1 / var2 + var2 / var1 + 2));
    return left + 1.0 / 4 * (Maths.pow(expectedValue() - other.expectedValue(), 2) / (var1 + var2));
}

From source file:com.davidbracewell.math.functions.LogLoss.java

@Override
public double derivative(double n1, double n2) {
    return n2 / FastMath.log(1 + FastMath.exp((n1 * n2)));
}

From source file:com.clust4j.kernel.LogKernel.java

@Override
public double getSimilarity(final double[] a, final double[] b) {
    final double sup = -(super.getSimilarity(a, b)); // super returns negative, so reverse it
    final double answer = -FastMath.log(sup + 1);
    return Double.isNaN(answer) ? Double.NEGATIVE_INFINITY : answer;
}

From source file:com.facebook.LinkBench.distributions.LogNormalDistribution.java

/**
 *
 * @param min//from  w w  w  .j  ava2s  . co m
 * @param max
 * @param median the median value of the distribution
 * @param sigma the standard deviation of the natural log of the variable
 * @param scale
 */
public void init(long min, long max, double median, double sigma) {
    this.min = min;
    this.max = max;
    this.mu = FastMath.log(median);
    this.sigma = sigma;
}

From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java

private static double differentialEntropy(StandardDeviation stdev) {
    return FastMath.log(stdev.getResult() * FastMath.sqrt(2.0 * FastMath.PI * FastMath.E));
}

From source file:net.nicoulaj.benchmarks.math.DoubleLog.java

@GenerateMicroBenchmark
public void commonsmath(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(FastMath.log(data[i]));
}

From source file:com.insightml.math.distributions.GaussianDistribution.java

@Override
public double logLikelihood(final double x) {
    // TODO: define better way to handle zero/min likelihood
    final double likelihood = probability(x);
    return FastMath.log(Math.max(0.0000000000000000001, likelihood));
}

From source file:com.clust4j.kernel.RadialBasisKernel.java

@Override
public double similarityToPartialSimilarity(double full) {
    return FastMath.log(full);
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheby2.java

private Cheby2(int n, double Rs, double[] W, boolean digital, boolean stop) {
    super(W, digital, stop);

    if (Rs < 0) {
        throw new IllegalArgumentException("cheby2: stopband attenuation must be positive decibels");
    }/*from  w  w  w  .ja  v  a  2 s.  c om*/

    this.Rs = Rs;

    //## Generate splane poles and zeros for the chebyshev type 2 filter
    //## From: Stearns, SD; David, RA; (1988). Signal Processing Algorithms.
    //##       New Jersey: Prentice-Hall.
    int C = 1; //# default cutoff frequency
    final double lambda = FastMath.pow(10, Rs / 20);
    final double phi = FastMath.log(lambda + FastMath.sqrt(FastMath.pow(lambda, 2) - 1)) / n;
    final double[] theta = new double[n];
    final double[] alpha = new double[n];
    final double[] beta = new double[n];

    for (int i = 0; i < n; i++) {
        theta[i] = FastMath.PI * (i + 0.5) / n;
        alpha[i] = -FastMath.sinh(phi) * FastMath.sin(theta[i]);
        beta[i] = FastMath.cosh(phi) * FastMath.cos(theta[i]);
    }
    final Complex IMAG_ONE = new Complex(0.0, 1);
    if (n % 2 != 0) {
        //## drop theta==pi/2 since it results in a zero at infinity
        zero = new Complex[n - 1];
        for (int i = 0; i < n / 2; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
        for (int i = n / 2 + 1; i < n; i++) {
            zero[i - 1] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    } else {
        zero = new Complex[n];
        for (int i = 0; i < n; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    }
    pole = new Complex[n];
    for (int i = 0; i < n; i++) {
        pole[i] = new Complex(C / (FastMath.pow(alpha[i], 2) + FastMath.pow(beta[i], 2)))
                .multiply(new Complex(alpha[i], -beta[i]));
    }

    /*
    ## Compensate for amplitude at s=0
    ## Because of the vagaries of floating point computations, the
    ## prod(pole)/prod(zero) sometimes comes out as negative and
    ## with a small imaginary component even though analytically
    ## the gain will always be positive, hence the abs(real(...))
     */
    gain = FastMath.abs(OctaveBuildIn.prod(pole).divide(OctaveBuildIn.prod(zero)).getReal());
}