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

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

Introduction

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

Prototype

public static double sqrt(final double a) 

Source Link

Document

Compute the square root of a number.

Usage

From source file:com.cloudera.oryx.common.math.SimpleVectorMath.java

/**
 * @return the L2 norm of vector x// ww  w . ja v  a2s. c  o m
 */
public static double norm(float[] x) {
    double total = 0.0;
    for (float f : x) {
        total += f * f;
    }
    return FastMath.sqrt(total);
}

From source file:net.myrrix.common.math.SimpleVectorMath.java

/**
 * @return the L2 norm of vector x/*from  ww w.  jav  a2 s. c o m*/
 */
public static double norm(double[] x) {
    double total = 0.0;
    for (double d : x) {
        total += d * d;
    }
    return FastMath.sqrt(total);
}

From source file:darks.learning.lossfunc.RMSELoss.java

@Override
public double getLossValue() {
    DoubleMatrix target = reConstructon.reconstruct(input);
    DoubleMatrix diff = pow(target.sub(input), 2);
    return FastMath.sqrt(diff.sum() / input.rows);
}

From source file:gentracklets.conversions.java

public static double[] geo2radec(PVCoordinates obj, TopocentricFrame staF, Frame inertialFrame,
        AbsoluteDate epoch) {//from  w  ww  .jav a 2 s  .co m

    Vector3D rho = new Vector3D(0, 0, 0);

    try {
        rho = obj.getPosition().subtract(staF.getPVCoordinates(epoch, inertialFrame).getPosition());
    } catch (OrekitException ex) {
        Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex);
    }

    double rho_mag = rho.getNorm();
    double DEC = FastMath.asin(rho.getZ() / rho_mag);
    double cosRA = 0.0;
    double sinRA = 0.0;
    double RA = 0.0;

    Vector3D v_site = new Vector3D(0, 0, 0);
    try {
        v_site = staF.getPVCoordinates(epoch, inertialFrame).getVelocity();
    } catch (OrekitException ex) {
        Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex);
    }

    Vector3D rhoDot = obj.getVelocity().subtract(v_site);

    if (FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)) != 0) {
        cosRA = rho.getX() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));
        sinRA = rho.getY() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));
        RA = FastMath.atan2(sinRA, cosRA);
        if (RA <= 0) {
            RA = RA + 2 * FastMath.PI;
        }
    } else {
        sinRA = rhoDot.getY() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2));
        cosRA = rhoDot.getX() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2));
        RA = FastMath.atan2(sinRA, cosRA);
        if (RA <= 0) {
            RA = RA + 2 * FastMath.PI;
        }
    }

    double rhoDot_mag = rho.dotProduct(rhoDot) / rho_mag;
    double RAdot = (rhoDot.getX() * rho.getY() - rhoDot.getY() * rho.getX())
            / (-1 * FastMath.pow(rho.getY(), 2) - FastMath.pow(rho.getX(), 2));
    double DECdot = (rhoDot.getZ() - rhoDot_mag * FastMath.sin(DEC))
            / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));

    double[] out = { RA, RAdot, DEC, DECdot, rho_mag, rhoDot_mag };

    return out;
}

From source file:io.crate.execution.engine.aggregation.statistics.StandardDeviation.java

@Override
public double result() {
    return FastMath.sqrt(super.result());
}

From source file:com.cloudera.oryx.rdf.common.eval.Evaluation.java

/**
 * @param classifier a {@link com.cloudera.oryx.rdf.common.tree.TreeBasedClassifier} (e.g. {@link com.cloudera.oryx.rdf.common.tree.DecisionForest})
 *  trained on data with a numeric target
 * @param testSet test set to evaluate on
 * @return root mean squared error over the test set square root of mean squared difference between actual
 *  and predicted numeric target value//from  w w  w. j a v  a  2s  .  c o  m
 */
public static double rootMeanSquaredError(TreeBasedClassifier classifier, Iterable<Example> testSet) {
    StorelessUnivariateStatistic mse = new Mean();
    for (Example test : testSet) {
        NumericFeature actual = (NumericFeature) test.getTarget();
        NumericPrediction prediction = (NumericPrediction) classifier.classify(test);
        double diff = actual.getValue() - prediction.getPrediction();
        mse.increment(diff * diff);
    }
    return FastMath.sqrt(mse.getResult());
}

From source file:mase.app.herding.HerdingFitnessDists.java

@Override
protected void postSimulation(MasonSimState sim) {
    super.postSimulation(null);
    Herding herd = (Herding) sim;/*from w w w .  j a v  a 2  s . com*/
    if (currentEvaluationStep < maxEvaluationSteps) {
        Double2D gate = new Double2D(herd.par.arenaSize, herd.par.arenaSize / 2);
        accum += gate.distance(herd.sheeps.get(0).getLocation()) * (maxEvaluationSteps - currentEvaluationStep);
    }
    double maxDist = FastMath
            .sqrt(FastMath.pow(herd.par.arenaSize, 2) + FastMath.pow(herd.par.arenaSize / 2, 2));
    res = new FitnessResult((1 - accum / maxEvaluationSteps / maxDist), FitnessResult.ARITHMETIC);
}

From source file:com.cloudera.oryx.common.random.RandomUtils.java

private static void doRandomUnitVector(float[] vector, RandomGenerator random) {
    int dimensions = vector.length;
    double total = 0.0;
    for (int i = 0; i < dimensions; i++) {
        double d = random.nextGaussian();
        vector[i] = (float) d;
        total += d * d;/*w  w w  .ja v a  2  s  .  com*/
    }
    float normalization = (float) FastMath.sqrt(total);
    for (int i = 0; i < dimensions; i++) {
        vector[i] /= normalization;
    }
}

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

@Override
public double standardDeviation() {
    return FastMath.sqrt(1.0 / getPrecision());
}

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

@Override
public double getSimilarity(final double[] a, final double[] b) {
    double lp = toHilbertPSpace(a, b);
    double sqnm = FastMath.pow(lp, 2);
    return FastMath.sqrt(sqnm + FastMath.pow(getConstant(), 2));
}