Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:de.biomedical_imaging.traj.math.RadiusGyrationTensor2D.java

/**
 * Calculates the radius of gyration tensor according to formula (6.3) in
 * /*from   ww w  .  j  a  v a 2 s.co m*/
 * ELEMENTS OF THE RANDOM WALK by Rudnick and Gaspari
 * 
 * @return Radius of gyration tensor
 */
public static Array2DRowRealMatrix getRadiusOfGyrationTensor(Trajectory t) {
    double meanx = 0;
    double meany = 0;
    for (int i = 0; i < t.size(); i++) {
        meanx += t.get(i).x;
        meany += t.get(i).y;
    }
    meanx = meanx / t.size();
    meany = meany / t.size();

    double e11 = 0;
    double e12 = 0;
    double e21 = 0;
    double e22 = 0;

    for (int i = 0; i < t.size(); i++) {
        e11 += Math.pow(t.get(i).x - meanx, 2);
        e12 += (t.get(i).x - meanx) * (t.get(i).y - meany);
        e22 += Math.pow(t.get(i).y - meany, 2);
    }
    e11 = e11 / t.size();
    e12 = e12 / t.size();
    e21 = e12;
    e22 = e22 / t.size();
    int rows = 2;
    int columns = 2;
    Array2DRowRealMatrix gyr = new Array2DRowRealMatrix(rows, columns);

    gyr.addToEntry(0, 0, e11);
    gyr.addToEntry(0, 1, e12);
    gyr.addToEntry(1, 0, e21);
    gyr.addToEntry(1, 1, e22);

    return gyr;
}

From source file:com.mapr.synth.ForeignKeySamplerTest.java

private DoubleFunction getDistribution(final double alpha) {
    return new DoubleFunction() {
        @Override//from  w  w w.ja va 2s.  c om
        public double apply(double rank) {
            return Math.pow(rank + 1, -alpha);
        }
    };
}

From source file:net.bioclipse.brunn.ui.editors.plateEditor.model.HillCurveIC50Calculator.java

public double calculateIC50(double[] conc, double[] si) {

    LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();

    CurveFitter fitter = new CurveFitter(optimizer);

    for (int i = 0; i < si.length; i++) {
        fitter.addObservedPoint(conc[i], si[i] / 100);
        System.out.println("Added point: " + conc[i] + "; " + si[i] / 100);
    }/*  ww  w .j  a  va2  s.c  om*/

    ParametricRealFunction function = new ParametricRealFunction() {

        @Override
        public double value(double c, double[] paramaters) throws FunctionEvaluationException {

            double d = paramaters[0];
            double n = paramaters[1];
            double c_pow_n = Math.pow(c, n);

            return c_pow_n / (c_pow_n + Math.pow(d, n));
        }

        @Override
        public double[] gradient(double c, double[] paramaters) throws FunctionEvaluationException {

            double d = paramaters[0];
            double n = paramaters[1];
            double c_pow_n = Math.pow(c, n);
            double d_pow_n = Math.pow(d, n);

            double ddd = -n * c_pow_n * Math.pow(d, n - 1) / Math.pow(c_pow_n + d_pow_n, 2);

            double ddn = (c_pow_n * d_pow_n * (Math.log(c) - Math.log(d))) / Math.pow(c_pow_n + d_pow_n, 2);

            return new double[] { ddd, ddn };
        }

    };

    double[] params = null;
    try {
        params = fitter.fit(function, new double[] { 1, 1 });
    } catch (Exception e) {
        Logger.getLogger(HillCurveIC50Calculator.class)
                .debug("Caught Exception while fitting dose response curve", e);
        return Double.NaN;
    }

    double d = params[0];
    double n = params[1];

    System.out.println("d=" + d);
    System.out.println("n=" + n);

    return Math.pow(-(0.5 - 1) * Math.pow(d, -n) / 0.5, -1 / n);
}

From source file:demo.vmware.commands.poweroftwo.CommandPowerOfTwoHelper.java

@Override
@Cacheable("POWERTABLE")
public Integer calculateNthPower(Integer targetNumber) {
    LOG.info("Not cached so calculating 2^" + targetNumber);
    hitCount++;/*from w  ww  .  j av a  2  s  .c o m*/
    Double result = Math.pow(2.0, targetNumber);
    try {
        // simulate long running service with 3 second delay
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // don't care
    }

    return new Integer(result.intValue());
}

From source file:Main.java

private static double calculateSubPixelLuminance(double subPixelValue) {
    return subPixelValue < 0.03928 ? subPixelValue / 12.92 : Math.pow((subPixelValue + 0.055) / 1.055, 2.4);
}

From source file:com.opengamma.analytics.financial.riskfactor.TaylorExpansionMultiplierCalculator.java

public static double getValue(final Map<UnderlyingType, Double> underlyingData, final Underlying underlying) {
    Validate.notNull(underlying, "underlying");
    Validate.notNull(underlyingData, "underlying data");
    Validate.notEmpty(underlyingData, "underlying data");
    Validate.noNullElements(underlyingData.keySet(), "underlying data keys");
    Validate.noNullElements(underlyingData.values(), "underlying data values");
    if (underlying instanceof NthOrderUnderlying) {
        final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying;
        final int n = nthOrder.getOrder();
        if (n == 0) {
            return 1;
        }//  www. j  av  a 2s . c om
        final UnderlyingType type = nthOrder.getUnderlying();
        Validate.isTrue(underlyingData.containsKey(type));
        final double value = Math.pow(underlyingData.get(type), n);
        return value * getMultiplier(underlying);
    } else if (underlying instanceof MixedOrderUnderlying) {
        final MixedOrderUnderlying mixedOrder = (MixedOrderUnderlying) underlying;
        Double result = null;
        double multiplier;
        for (final NthOrderUnderlying underlyingOrder : mixedOrder.getUnderlyingOrders()) {
            if (result == null) {
                result = getValue(underlyingData, underlyingOrder);
            } else {
                multiplier = getValue(underlyingData, underlyingOrder);
                result = result * multiplier;
            }
        }
        if (result != null) {
            return result;
        }
    }
    throw new IllegalArgumentException(
            "Order was neither NthOrderUnderlying nor MixedOrderUnderlying: have " + underlying.getClass());
}

From source file:com.opengamma.analytics.math.statistics.descriptive.SampleSkewnessCalculator.java

/**
 * @param x The array of data, not null, must contain at least three data points
 * @return The sample skewness//from   w w  w.ja  v a2 s.  c  o m
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    Validate.isTrue(x.length >= 3, "Need at least three points to calculate sample skewness");
    double sum = 0;
    double variance = 0;
    final double mean = MEAN.evaluate(x);
    for (final Double d : x) {
        final double diff = d - mean;
        variance += diff * diff;
        sum += diff * diff * diff;
    }
    final int n = x.length;
    variance /= n - 1;
    return Math.sqrt(n - 1.) * sum / (Math.pow(variance, 1.5) * Math.sqrt(n) * (n - 2));
}

From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.MichalewiczFunction.java

@Override
public double map(RealVector v) {
    double[] x = v.toArray();
    double sum = 0.0;
    for (int i = 0; i < x.length; i++) {
        sum += Math.sin(x[i]) * Math.pow(Math.sin((i + 1) * x[i] * x[i] / Math.PI), 2 * m);
    }//from w w w  . j a  va2  s  . c o  m
    return -sum;
}

From source file:com.itemanalysis.psychometrics.irt.estimation.RaschScaleQualityStatistics.java

/**
 * An incremental update to the scale quality statistics.
 *
 * @param estimate a person ability or item difficulty estimate.
 * @param stdError/* w  ww .ja  v a  2 s . com*/
 */
public void increment(double estimate, double stdError) {
    var.increment(estimate);
    mean.increment(Math.pow(stdError, 2));
}

From source file:com.wormsim.tracking.ConstantDoubleInstance.java

@Override
public double getRecentSquareMean() {
    return Math.pow(((ConstantDouble) parent).value, 2);
}