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:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java

/**
 *
 * @param x a matrix of dimension 1 x k, where k is the number of variables
 * @return/*from   w w w . j ava  2  s  . c  o m*/
 */
public double density(RealMatrix x) throws SingularMatrixException {
    double prob = 0.0;
    RealMatrix xTran = x.transpose();
    int d = xTran.getRowDimension();
    double det = new LUDecomposition(sigma).getDeterminant();
    double nconst = 1.0 / Math.sqrt(det * Math.pow(2.0 * Math.PI, d));
    RealMatrix Sinv = new LUDecomposition(sigma).getSolver().getInverse();
    RealMatrix delta = xTran.subtract(mu);
    RealMatrix dist = (delta.transpose().multiply(Sinv).multiply(delta));
    prob = nconst * Math.exp(-0.5 * dist.getEntry(0, 0));
    return prob;
}

From source file:com.davidbracewell.math.distribution.NormalDistribution.java

/**
 * Default Constructor//ww  w .  j a v a2  s  . com
 *
 * @param mean   The mean of the distribution
 * @param stddev The standard deviation of the distribution
 */
public NormalDistribution(double mean, double stddev) {
    super(0d);
    this.mean = mean;
    this.stddev = stddev;
    this.var = Math.pow(stddev, 2);
}

From source file:com.github.lynxdb.server.core.aggregators.Dev.java

@Override
public TimeSerie aggregate(List<TimeSerie> _series) {
    return doInterpolate(_series, new Reducer() {
        double sum;
        double sumSquares;
        double count;

        @Override/*from ww  w  .jav a 2s. c  o m*/
        public void update(Entry _entry) {
            sum += _entry.getValue();
            sumSquares += Math.pow(_entry.getValue(), 2);
            count++;
        }

        @Override
        public double result() {
            //divisor is (count -1) because of Bessel's correction
            return (count < 2) ? 0.0 : Math.sqrt((sumSquares / (count - 1)) - (Math.pow(sum, 2) / (count - 1)));
        }

        @Override
        public void reset() {
            sum = 0;
            count = 0;
            sumSquares = 0;
        }
    });
}

From source file:com.swcguild.springmvcwebapp.controller.InterCalcController.java

@RequestMapping(value = "/intercalc", method = RequestMethod.POST)
public String doPost(HttpServletRequest request, Model model) {

    try {/*from   ww w. j ava  2s.  c om*/
        originalBalance = Double.parseDouble(request.getParameter("myAnswer"));
        startingBalance = originalBalance;
        intRate = Double.parseDouble(request.getParameter("myRate"));
        numYears = Double.parseDouble(request.getParameter("myYears"));
        numPeriods = Double.parseDouble(request.getParameter("myPeriods"));
        message = "";
        //totalInterest;
        //newBalance;
        //List<Map> annualInterest = new ArrayList<>();
        Map yearMap = new HashMap<>();
        DecimalFormat df = new DecimalFormat("#.00");

        int yearCount = 0;

        do {
            newBalance = originalBalance * (Math.pow(1 + ((intRate * .01) / numPeriods), (numPeriods)));
            yearCount++;

            double interestPerYear = newBalance - originalBalance;

            String interestPerYearString = df.format(interestPerYear);

            yearMap.put(yearCount, interestPerYearString);

            originalBalance = newBalance;

        } while (yearCount <= (numYears - 1));
        totalInterest = newBalance - startingBalance;
        //annualInterest.add(yearMap);
        String annualInterestString = yearMap.toString().replace("{", "").replace("}", "").trim();

        model.addAttribute("originalBalance", df.format(startingBalance));
        model.addAttribute("newBalance", df.format(newBalance));
        model.addAttribute("interestRate", intRate);
        model.addAttribute("interestEarned", df.format(totalInterest));
        model.addAttribute("years", df.format(numYears));
        model.addAttribute("periods", df.format(numPeriods));
        model.addAttribute("annualInterest", yearMap);

    } catch (NumberFormatException e) {
    }

    return "intercalcResponse";
    //<td><c:out value="${current.id}" /><td>
}

From source file:de.termininistic.serein.examples.benchmarks.functions.unimodal.PermFunction.java

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

From source file:math2605.gn_exp.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;/*from w w  w  . ja  va2 s.  c om*/
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.pow(Math.E, b * x) + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:com.opengamma.analytics.financial.model.volatility.surface.ConstantElasticityOfVarianceBlackEquivalentVolatilitySurfaceModel.java

@Override
public VolatilitySurface getSurface(final Map<OptionDefinition, Double> optionData,
        final ConstantElasticityOfVarianceModelDataBundle data) {
    Validate.notNull(optionData, "option data");
    ArgumentChecker.notEmpty(optionData, "option data");
    Validate.notNull(data, "data");
    if (optionData.size() > 1) {
        s_logger.warn("Have more than one option: only using the first");
    }//from   w w  w  . jav  a2s . c o m
    final OptionDefinition option = optionData.keySet().iterator().next();
    final double k = option.getStrike();
    final double t = option.getTimeToExpiry(data.getDate());
    final double sigma = data.getVolatility(t, k);
    final double beta = data.getElasticity();
    final double forward = data.getSpot();
    final double f = 0.5 * (forward + k);
    final double beta1 = 1 - beta;
    final double sigmaAdjusted = sigma * (1 + beta1 * (2 + beta) * (f - k) * (f - k) / 24 / f / f
            + beta1 * beta1 * sigma * sigma * t / 24 / Math.pow(f, 2 * beta1)) / Math.pow(f, beta1);
    return new VolatilitySurface(ConstantDoublesSurface.from(sigmaAdjusted));
}

From source file:Callers.BiasedBinomialCaller.java

/**
 * Calls a genotype based on reads//  ww  w .  jav a 2s . com
 * @param d The reads
 * @return The called genotype
 */
public double[] callSingle(int[] d) {
    if ((d[0] + d[1]) != 0) {
        double[] probs = new double[3];

        double l0 = Math.pow(1 - error, d[0]) * Math.pow(error, d[1]);
        double l1 = Math.pow(bias, d[0]) * Math.pow(1 - bias, d[1]);
        double l2 = Math.pow(error, d[0]) * Math.pow(1 - error, d[1]);

        double totall = l0 + l1 + l2;

        probs[0] = l0 / totall;
        probs[1] = l1 / totall;
        probs[2] = l2 / totall;

        return probs;
    } else {
        double[] probs = { 1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0 };
        return probs;
    }
}

From source file:math2605.gn_qua.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;/*  w ww  .  j  a  v  a2 s.co  m*/
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.pow(x, 2) + b * x + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:ardufocuser.starfocusing.Utils.java

/**
 * Calcula la distancia euclidea de dos puntos, dado sus coordenadas.
 *//*  w ww.ja v  a 2 s. c  o  m*/
public static double computeDistance(int p1x, int p1y, int p2x, int p2y) {

    int cat1 = Math.abs(p1x - p2x);
    int cat2 = Math.abs(p1y - p2y);
    double dis = Math.sqrt((Math.pow(cat1, 2) + Math.pow(cat2, 2)));
    return dis;

}