Example usage for java.lang Math sqrt

List of usage examples for java.lang Math sqrt

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double sqrt(double a) 

Source Link

Document

Returns the correctly rounded positive square root of a double value.

Usage

From source file:com.itemanalysis.psychometrics.rasch.ScaleQualityStatistics.java

public double adjustedStandardDeviation() {
    return Math.sqrt(adjustedVariance());
}

From source file:es.udc.gii.common.eaf.stoptest.cma.CMATolXStopTest.java

@Override
public boolean isReach(EvolutionaryAlgorithm algorithm) {

    double current_tol_x, sigma, minstartsigma, maxsqrtdiagC, pc;
    CMAEvolutionaryAlgorithm cma = (CMAEvolutionaryAlgorithm) algorithm;

    minstartsigma = StatUtils.min(cma.getStartSigma());
    current_tol_x = Math.max(this.tol_x, this.tol_x_factor * minstartsigma);
    maxsqrtdiagC = Math.sqrt(StatUtils.max(cma.diag(cma.getC())));
    sigma = cma.getSigma();//from w w  w  .j a  v a  2s.  c  om

    pc = -Double.MAX_VALUE;
    for (double d : cma.getPc()) {
        pc = Math.max(pc, Math.abs(d));
    }

    if (sigma * maxsqrtdiagC < current_tol_x && sigma * pc < current_tol_x) {
        return true;
    }

    return false;

}

From source file:apiserver.services.images.services.jhlabs.BumpFilterService.java

public Object doFilter(Message<?> message) throws MessageConfigException {
    BumpJob props = (BumpJob) message.getPayload();

    int edgeAction = props.getEdgeAction();
    boolean useAlpha = props.isUseAlpha();
    float[] embossMatrix = props.getMatrix();

    try {// w w w. j  a  v a 2s.  c  o  m

        // calculate
        int rows = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue();
        int cols = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue();

        //run filter
        BumpFilter filter = new BumpFilter();
        filter.setEdgeAction(edgeAction);
        filter.setUseAlpha(useAlpha);
        filter.setKernel(new Kernel(rows, cols, embossMatrix));

        BufferedImage bufferedImage = props.getBufferedImage();
        if (bufferedImage == null) {
            throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY);
        }

        BufferedImage outFile = filter.filter(bufferedImage, null);

        props.setBufferedImage(outFile);
        return message;
    } catch (Throwable e) {
        //log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.GramCharlierModel.java

@Override
public Function1D<SkewKurtosisOptionDataBundle, Double> getPricingFunction(final OptionDefinition definition) {
    Validate.notNull(definition);/*  w w w.j  a  va  2  s  .  co  m*/
    final Function1D<SkewKurtosisOptionDataBundle, Double> pricingFunction = new Function1D<SkewKurtosisOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final SkewKurtosisOptionDataBundle data) {
            Validate.notNull(data);
            final double s = data.getSpot();
            final double k = definition.getStrike();
            final double t = definition.getTimeToExpiry(data.getDate());
            final double b = data.getCostOfCarry();
            final double r = data.getInterestRate(t);
            final double sigma = data.getVolatility(t, k);
            final double sigmaT = sigma * Math.sqrt(t);
            final double d1 = getD1(s, k, t, sigma, b);
            final double d2 = getD2(d1, sigma, t);
            final double skew = data.getAnnualizedSkew();
            final double kurtosis = data.getAnnualizedPearsonKurtosis();
            final double correction = sigmaT * (skew * (2 * sigmaT - d1) / (6. * Math.sqrt(t))
                    - kurtosis * (1 - d1 * d1 + 3 * sigmaT * (d1 - sigmaT)) / (24 * t));
            final double df1 = Math.exp(-r * t);
            final double df2 = getDF(r, b, t);
            final double callPrice = s * df2 * (NORMAL.getCDF(d1) + NORMAL.getPDF(d1) * correction)
                    - k * df1 * NORMAL.getCDF(d2);
            if (!definition.isCall()) {
                return callPrice + k * df1 - s * df2;
            }
            return callPrice;
        }
    };
    return pricingFunction;
}

From source file:dnimp.Statistics.java

private double studT(double t, int n) {
    t = Math.abs(t);// w w w . jav  a  2 s  . co  m
    double th = Math.atan(t / Math.sqrt(n));
    double sth = Math.sin(th);
    double cth = Math.cos(th);

    if (n == 1)
        return 1 - th / (Math.PI / 2.0);

    if (n % 2 == 1) {
        return 1 - (th + sth * cth * statCom(cth * cth, 2, n - 3, -1)) / (Math.PI / 2.0);
    } else {
        return 1 - sth * statCom(cth * cth, 1, n - 3, -1);
    }
}

From source file:edu.umd.umiacs.clip.tools.math.CorrelationUtils.java

public static double pr(final double[] xUnsorted, final double[] yUnsorted) {
    Pair<double[], double[]> pairs = sort(xUnsorted, yUnsorted);
    double[] x = minMaxScale(pairs.getLeft());
    double[] y = minMaxScale(pairs.getRight());
    return range(1, x.length).parallel()
            .mapToDouble(i -> x[i] * (range(0, i).mapToDouble(j -> (x[j] - x[i]) * (y[j] - y[i])).sum())
                    / (Math.sqrt((range(0, i).mapToDouble(j -> Math.pow(x[j] - x[i], 2)).sum())
                            * (range(0, i).mapToDouble(j -> Math.pow(y[j] - y[i], 2)).sum()))))
            .sum() / range(1, x.length).mapToDouble(i -> x[i]).sum();

}

From source file:es.logongas.encuestas.modelo.resultados.InferenciaEstadistica.java

public InferenciaEstadistica(EstadisticaDescriptiva estadisticaDescriptiva, BigDecimal nivelConfianza,
        int numDecimals) {
    this.numDecimals = numDecimals;
    if (nivelConfianza.compareTo(BigDecimal.ZERO) <= 0) {
        throw new IllegalArgumentException("El nivelConfianza debe ser mayor que 0");
    }//from w w w . j  a  va  2s . c  o  m
    if (nivelConfianza.compareTo(BigDecimal.ONE) >= 0) {
        throw new IllegalArgumentException("El nivelConfianza debe ser menor que 1");
    }

    TDistribution tDistribution = new TDistribution(estadisticaDescriptiva.getNumMuestras() - 1);
    double t = tDistribution.inverseCumulativeProbability(nivelConfianza.doubleValue());
    BigDecimal delta = new BigDecimal(t * (estadisticaDescriptiva.getDesviacionEstandar().doubleValue()
            / Math.sqrt(estadisticaDescriptiva.getNumMuestras())));

    BigDecimal min = estadisticaDescriptiva.getMedia().subtract(delta).setScale(this.numDecimals,
            RoundingMode.HALF_UP);
    BigDecimal max = estadisticaDescriptiva.getMedia().add(delta).setScale(this.numDecimals,
            RoundingMode.HALF_UP);
    intervaloConfianzaMedia = new IntervaloConfianza(min, max, nivelConfianza);

}

From source file:org.wallerlab.yoink.density.service.densityProperties.ReducedDensityGradientComputer.java

private double calculateRdg(double density, double gradient) {
    double rdg = Math.sqrt(gradient) / (Math.pow(density, 4.0 / 3));
    rdg = rdg / Constants.RDG_COEFFICIENT;
    return rdg;//from   w w w.  j a  v  a 2 s  .c o m
}

From source file:Float11.java

static public double asin(double x) {
    if (x < -1. || x > 1.)
        return Double.NaN;
    if (x == -1.)
        return -Math.PI / 2;
    if (x == 1)/* w w  w .j  a v a 2  s .c  om*/
        return Math.PI / 2;
    return atan(x / Math.sqrt(1 - x * x));
}

From source file:com.opengamma.analytics.financial.model.volatility.curve.FXVannaVolgaVolatilityCurveModel.java

@Override
public VolatilityCurve getCurve(final FXVannaVolgaVolatilityCurveDataBundle marketQuotes,
        final FXOptionDataBundle data) {
    Validate.notNull(marketQuotes);/* w ww.  j  a  v a  2 s.  c  om*/
    Validate.notNull(data);
    final double sigmaRR = marketQuotes.getRiskReversal();
    final double sigmaATM = marketQuotes.getAtTheMoney();
    final double sigmaVWB = marketQuotes.getVegaWeightedButterfly();
    final double sigmaDeltaCall = sigmaVWB + sigmaATM + 0.5 * sigmaRR;
    final double sigmaDeltaPut = sigmaDeltaCall - sigmaRR;
    final double t = DateUtils.getDifferenceInYears(data.getDate(), marketQuotes.getMaturity());
    if (t < 0) {
        throw new IllegalArgumentException("Cannot have date after time to maturity");
    }
    final double sqrtT = Math.sqrt(t);
    final double s = data.getSpot();
    final double rd = data.getInterestRate(t);
    final double rf = data.getForeignInterestRate(t);
    final double alpha = -NORMAL.getInverseCDF(Math.exp(rf * t) * marketQuotes.getDelta());
    final double k1 = s
            * Math.exp(-alpha * sigmaDeltaPut * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaPut * sigmaDeltaPut));
    final double k2 = s * Math.exp(t * (rd - rf + 0.5 * sigmaATM * sigmaATM));
    final double k3 = s
            * Math.exp(alpha * sigmaDeltaCall * sqrtT + t * (rd - rf + 0.5 * sigmaDeltaCall * sigmaDeltaCall));
    final double lnk21 = Math.log(k2 / k1);
    final double lnk31 = Math.log(k3 / k1);
    final double lnk32 = Math.log(k3 / k2);
    final double sigma = sigmaATM;
    return new VolatilityCurve(FunctionalDoublesCurve.from(new Function1D<Double, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final Double x) {
            Validate.notNull(x);

            final double k = x;
            final double a1 = Math.log(k2 / k) * Math.log(k3 / k) / lnk21 / lnk31;
            final double a2 = Math.log(k / k1) * Math.log(k3 / k) / lnk21 / lnk32;
            final double a3 = Math.log(k / k1) * Math.log(k / k2) / lnk31 / lnk32;
            final double x1 = a1 * sigmaDeltaPut;
            final double x2 = a2 * sigmaATM;
            final double x3 = a3 * sigmaDeltaCall;
            final double e1 = x1 + x2 + x3 - sigma;
            final double d1k1 = getD1(s, k1, t, rd, rf, sigma, sqrtT);
            final double d1k2 = getD1(s, k2, t, rd, rf, sigma, sqrtT);
            final double d1k3 = getD1(s, k3, t, rd, rf, sigma, sqrtT);
            final double x4 = a1 * d1k1 * getD2(d1k1, sigma, sqrtT) * (sigmaDeltaPut - sigma)
                    * (sigmaDeltaPut - sigma);
            final double x5 = a2 * d1k2 * getD2(d1k2, sigma, sqrtT) * (sigmaATM - sigma) * (sigmaATM - sigma);
            final double x6 = a3 * d1k3 * getD2(d1k3, sigma, sqrtT) * (sigmaDeltaCall - sigma)
                    * (sigmaDeltaCall - sigma);
            final double e2 = x4 + x5 + x6;
            final double d1k = getD1(s, k, t, rd, rf, sigma, sqrtT);
            final double d2k = getD2(d1k, sigma, sqrtT);
            return sigma + (-sigma + Math.sqrt(sigma * sigma + d1k * d2k * (2 * sigma * e1 + e2))) / d1k / d2k;
        }

    }));
}