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

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

Introduction

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

Prototype

public static double log10(final double x) 

Source Link

Document

Compute the base 10 logarithm.

Usage

From source file:com.davidbracewell.ml.classification.bayes.BernoulliNaiveBayes.java

@Override
protected ClassificationResult classifyImpl(Instance instance) {
    int numClasses = getTargetFeature().alphabetSize();
    double[] probabilities = new double[numClasses];
    double sum = 0d;
    for (int i = 0; i < numClasses; i++) {
        probabilities[i] = FastMath.log10(priors[i]);
        for (int f = 0; f < getFeatures().size(); f++) {
            if (instance.isDefined(f)) {
                probabilities[i] += FastMath.log10(conditionals[f][i]);
            } else {
                probabilities[i] += FastMath.log10(1 - conditionals[f][i]);
            }/*from www  .j  a  v a 2  s  . co  m*/
        }

        probabilities[i] = Math.exp(probabilities[i]);
        sum += probabilities[i];
    }

    //normalize to make probabilities add to one
    for (int i = 0; i < numClasses; i++) {
        probabilities[i] = probabilities[i] / sum;
    }

    return new ClassificationResult(getTargetFeature(), probabilities);
}

From source file:com.davidbracewell.ml.classification.bayes.NaiveBayes.java

@Override
protected ClassificationResult classifyImpl(Instance instance) {
    int numClasses = getTargetFeature().alphabetSize();
    double[] probabilities = new double[numClasses];
    double sum = 0d;
    for (int i = 0; i < numClasses; i++) {
        //prior/* w w w. j  av a2s.com*/
        probabilities[i] = FastMath.log10(priors[i]);
        //posterior
        for (DoubleEntry entry : CollectionUtils.asIterable(instance.nonZeroIterator())) {
            probabilities[i] += FastMath.log10(conditionals[entry.index][i]);
        }
        probabilities[i] = Math.exp(probabilities[i]);
        sum += probabilities[i];
    }

    //normalize to make probabilities add to one
    for (int i = 0; i < numClasses; i++) {
        probabilities[i] = probabilities[i] / sum;
    }

    return new ClassificationResult(getTargetFeature(), probabilities);
}

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

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

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "")
public double Log10(double x) {
    return FastMath.log10(x);
}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void log10(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.log10(operand[0]);
    if (order > 0) {
        final double inv = 1.0 / operand[0];
        double xk = inv / FastMath.log(10.0);
        for (int i = 1; i <= order; ++i) {
            function[i] = xk;//from  ww  w  .  j  av  a2 s  . c  o  m
            xk *= -i * inv;
        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable/*from w w  w .  j a  v  a  2  s  .c o m*/
@StrictLoops
public void log10(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    function[0] = FastMath.log10(operand[0]);
    if (order > 0) {
        final double inv = 1.0 / operand[0];
        double xk = inv / FastMath.log(10.0);
        for (int i = 1; i <= order; ++i) {
            function[i] = xk;
            xk *= -i * inv;
        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:org.esa.beam.util.math.FastMathPerformance.java

public void testLog10() {
    System.gc();/* w  w  w  .  j ava2 s. c  o m*/
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.log10(Math.PI + i/* 1.0 + i/1e9 */);
    long strictMath = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.log10(Math.PI + i/* 1.0 + i/1e9 */);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.log10(Math.PI + i/* 1.0 + i/1e9 */);
    long mathTime = System.nanoTime() - time;

    report("log10", x + y + z, strictMath, fastTime, mathTime);
}

From source file:org.esa.beam.util.math.FastMathTest.java

@Test
public void testMathLog10Fast() {
    for (double i = 0; i < numItr; ++i) {
        double val = FastMath.log10(i);
    }// w w  w.j  a  va  2  s  .  co  m
}

From source file:org.orekit.propagation.analytical.tle.TLE.java

/** Format a real number without 'e' exponent marker.
 * @param name parameter name//from  w ww  .  ja v  a2  s  . c o  m
 * @param d number to format
 * @param mantissaSize size of the mantissa (not counting initial '-' or ' ' for sign)
 * @param c padding character
 * @param size desired size
 * @param rightJustified if true, the resulting string is
 * right justified (i.e. space are added to the left)
 * @return formatted and padded number
 * @exception OrekitException if parameter is too large to fit format
 */
private String formatExponentMarkerFree(final String name, final double d, final int mantissaSize, final char c,
        final int size, final boolean rightJustified) throws OrekitException {
    final double dAbs = FastMath.abs(d);
    int exponent = (dAbs < 1.0e-9) ? -9 : (int) FastMath.ceil(FastMath.log10(dAbs));
    final long mantissa = FastMath.round(dAbs * FastMath.pow(10.0, mantissaSize - exponent));
    if (mantissa == 0) {
        exponent = 0;
    }
    final String sMantissa = addPadding(name, (int) mantissa, '0', mantissaSize, true);
    final String sExponent = Integer.toString(FastMath.abs(exponent));
    final String formatted = (d < 0 ? '-' : ' ') + sMantissa + (exponent <= 0 ? '-' : '+') + sExponent;

    return addPadding(name, formatted, c, size, rightJustified);

}

From source file:org.talend.dataprep.transformation.actions.math.Logarithm.java

@Override
protected String calculateResult(String columnValue, ActionContext context) {
    double value = BigDecimalParser.toBigDecimal(columnValue).doubleValue();

    double result = FastMath.log10(value);

    return Double.isNaN(result) ? ERROR_RESULT : Double.toString(result);
}