Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

In this page you can find the example usage for java.lang Double NaN.

Prototype

double NaN

To view the source code for java.lang Double NaN.

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type double .

Usage

From source file:bb.mcmc.analysis.ESSConvergeStat.java

@Override
protected boolean checkEachConverged(double stat, String key) {

    boolean isConverged = true;

    if (Double.isNaN(stat)) {
        System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + "("
                + Double.NaN + "). Check log file for details. ");
    } else if (stat < essThreshold && !Double.isInfinite(stat)) {// || Double.isNaN(stat)) {
        isConverged = false;/*from  ww w  . jav  a  2s. c  o  m*/
    }

    return isConverged;

}

From source file:geogebra.kernel.AlgoRootNewton.java

final double calcRoot(Function fun, double start) {
    double root = Double.NaN;
    if (rootFinderBrent == null)
        rootFinderBrent = new BrentSolver(Kernel.STANDARD_PRECISION);

    // try Brent method with borders close to start value
    try {/* w w w.j  a v a2s.  c om*/
        double step = (kernel.getXmax() - kernel.getXmin()) / 10;
        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), start - step, start + step,
                start);
        if (checkRoot(fun, root)) {
            //System.out.println("1. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Brent method on valid interval around start
    double[] borders = getDomain(fun, start);
    try {
        root = rootFinderBrent.solve(MAX_ITERATIONS, new RealRootAdapter(fun), borders[0], borders[1], start);
        if (checkRoot(fun, root)) {
            //System.out.println("2. Brent worked: " + root);
            return root;
        }
    } catch (Exception e) {
        root = Double.NaN;
    }

    // try Newton's method
    RealRootDerivFunction derivFun = fun.getRealRootDerivFunction();
    if (derivFun != null) {
        // check if fun(start) is defined
        double eval = fun.evaluate(start);
        if (Double.isNaN(eval) || Double.isInfinite(eval)) {
            // shift left border slightly right
            borders[0] = 0.9 * borders[0] + 0.1 * borders[1];
            start = (borders[0] + borders[1]) / 2;
        }

        if (rootFinderNewton == null) {
            rootFinderNewton = new NewtonSolver();
        }

        try {
            root = rootFinderNewton.solve(MAX_ITERATIONS, new RealRootDerivAdapter(derivFun), borders[0],
                    borders[1], start);
            if (checkRoot(fun, root)) {
                //System.out.println("Newton worked: " + root);
                return root;
            }
        } catch (Exception e) {
            root = Double.NaN;
        }
    }

    // neither Brent nor Newton worked
    return Double.NaN;
}

From source file:eu.crisis_economics.utilities.EmpiricalDistribution.java

public EmpiricalDistribution(int memoryLength) {
    m_dataStream = new CircularFifoBuffer<Double>(memoryLength);
    m_sortedData = new TreeSet<EmpiricalDistribution.SortedDatum>();
    lastValueInserted = Double.NaN;
}

From source file:geogebra.common.kernel.algos.AlgoRootInterval.java

@SuppressWarnings("deprecation")
final double calcRoot() {
    if (!(f.isDefined() && aGeo.isDefined() && bGeo.isDefined())) {
        return Double.NaN;
    }/* w  w w. j  av a 2s .c om*/

    double root = Double.NaN;
    Function fun = f.getFunction();

    if (rootFinder == null) {
        UnivariateRealSolverFactory fact = UnivariateRealSolverFactory.newInstance();
        rootFinder = fact.newBrentSolver();

        rootPolisher = fact.newNewtonSolver();
    }

    double min = a.getDouble();
    double max = b.getDouble();

    double newtonRoot = Double.NaN;

    try {
        // Brent's method (Apache 2.2)
        root = rootFinder.solve(new RealRootAdapter(fun), min, max);

        // Apache 3.3 - solver seems more accurate
        // #4691
        // BrentSolver brent3 = new BrentSolver();
        // root = brent3.solve(100, new RealRootAdapter3(fun), min, max);

    } catch (Exception e) {
        // e.printStackTrace();
        Log.debug("problem finding root: " + e.getMessage());

        try {
            // Let's try again by searching for a valid domain first
            double[] borders = RealRootUtil.getDefinedInterval(fun, min, max);
            root = rootFinder.solve(new RealRootAdapter(fun), borders[0], borders[1]);
        } catch (Exception ex) {
            // ex.printStackTrace();
            Log.debug("problem finding root: " + ex.getMessage());
            return Double.NaN;
        }
    }

    // Log.debug("result from Brent: " + root);

    // ******** Polish Root ***************
    // adpated from EquationSolver
    // #4691

    try {
        newtonRoot = rootPolisher.solve(new RealRootDerivAdapter(fun), min, max, root);

        if (Math.abs(fun.evaluate(newtonRoot)) < Math.abs(fun.evaluate(root))) {
            root = newtonRoot;
            // Log.debug("polished result from Newton is better: " +
            // newtonRoot);
        }

    } catch (Exception e) {
        Log.debug("problem polishing root: " + e.getMessage());
    }

    // check result
    if (Math.abs(fun.evaluate(root)) < Kernel.MIN_PRECISION) {
        return root;
    }

    Log.debug("problem with root accuracy");
    return Double.NaN;
}

From source file:geogebra.util.MyMath.java

final public static double gammaIncomplete(double a, double x, Kernel kernel) {

    try {/*from  w  ww.j av a  2  s .c  o  m*/
        // see http://mathworld.wolfram.com/RegularizedGammaFunction.html
        // http://en.wikipedia.org/wiki/Incomplete_gamma_function#Regularized_Gamma_functions_and_Poisson_random_variables
        return Gamma.regularizedGammaP(a, x) * gamma(a, kernel);
    } catch (MathException e) {
        return Double.NaN;
    }

}

From source file:bb.mcmc.analysis.GewekeConvergeStat.java

@Override
protected boolean checkEachConverged(double stat, String key) {

    boolean isConverged = true;

    if (Double.isNaN(stat)) {
        System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + "("
                + Double.NaN + "). Geweke algorithm might not converged. Check log file for details. ");
    } else if (Math.abs(stat) > gewekeThreshold && !Double.isInfinite(stat)) {
        isConverged = false;/*from   w  w  w  .ja  va2  s. co  m*/
    }
    return isConverged;

}

From source file:com.zatarox.chess.skychess.tables.TranspositionTable.java

/**
* Returns the upperbound for the current board.
*
* @param position//ww w . jav a  2s  .  c om
* @return
*/
public synchronized double getLowerbound(Board position) {
    double result = Double.NaN;
    if (getTable().containsKey(position)) {
        result = ((Entry) getTable().get(position)).lowerbound;
    }
    return result;
}

From source file:gedi.lfc.gui.LfcMapper.java

@Override
public PixelBlockToValuesMap map(ReferenceSequence reference, GenomicRegion region,
        PixelLocationMapping pixelMapping, PixelBlockToValuesMap data) {

    double[] counts = new double[2];

    PixelBlockToValuesMap re = new PixelBlockToValuesMap(data.getBlocks(), 2, NumericArrayType.Double);
    for (int i = 0; i < pixelMapping.size(); i++) {
        NumericArray in = data.getValues(i);
        Arrays.fill(counts, 0);/*from  www. ja  v  a2 s  . co m*/

        for (int c = 0; c < in.length(); c++) {
            int cond = contrast == null ? (c * 2) / in.length() : contrast.getMappedIndex(c);
            if (cond != -1)
                counts[cond] += in.getDouble(c);
        }
        NumericArray out = re.getValues(i);
        if (ArrayUtils.max(counts) > 0) {
            //            out.set(0, Math.log(counts[0]/counts[1])/Math.log(2));

            BetaDistribution dist = new BetaDistribution(counts[0] + 1, counts[1] + 1);
            out.set(0, pToLfc(dist.inverseCumulativeProbability(lower)));
            out.set(1, pToLfc(dist.inverseCumulativeProbability(upper)));
        } else {
            out.setDouble(0, Double.NaN);
            out.setDouble(1, Double.NaN);
        }
    }

    return re;
}

From source file:it.units.malelab.ege.util.Utils.java

public static double mean(double[] values) {
    if (values.length == 0) {
        return Double.NaN;
    }/*from  w w w.  j  ava 2 s.c om*/
    double mean = 0;
    for (double value : values) {
        mean = mean + value;
    }
    return mean / (double) values.length;
}

From source file:de.biomedical_imaging.traJ.features.SplineCurveDynamicsFeature.java

@Override
public double[] evaluate() {
    PolynomialSplineFunction spline = null;
    if (recalculate) {
        splinefit = new TrajectorySplineFit(t, nSegments);
        spline = splinefit.calculateSpline();
    } else {//from   ww w  . j av  a  2  s. co m
        spline = splinefit.getSpline();
    }
    if (!splinefit.wasSuccessfull()) {
        return new double[] { Double.NaN, Double.NaN, Double.NaN };
    }
    Trajectory tr = splinefit.getRotatedTrajectory();
    UnivariateFunction derivative = spline.derivative();
    int N = 0;
    double sumParallel = 0;
    double sumPerpendicular = 0;
    //Split each step into replacment rependicular and parallel to spline tangent
    for (int i = timelag; i < t.size(); i += timelag) {
        Point2D.Double pRef = splinefit.minDistancePointSpline(new Point2D.Double(tr.get(i).x, tr.get(i).y),
                50);

        Point2D.Double pTangend = new Point2D.Double(pRef.x + 1,
                derivative.value(pRef.x) * (pRef.x + 1 - pRef.x) + spline.value(pRef.x));

        Point2D.Double pNormal = new Point2D.Double(-1 * pTangend.y, pTangend.x);

        Point2D.Double dp = new Point2D.Double(pRef.x + tr.get(i).x - tr.get(i - timelag).x,
                pRef.y + tr.get(i).y - tr.get(i - timelag).y);
        sumParallel += Math.pow(splinefit.distancePointLine(pRef, pNormal, dp), 2);
        sumPerpendicular += Math.pow(splinefit.distancePointLine(pRef, pTangend, dp), 2);

        N++;
    }
    //System.out.println("N: " +spline.getN());
    double msdParallel = sumParallel / N;
    double msdPerpendicular = sumPerpendicular / N;
    result = new double[] { msdParallel, msdPerpendicular, N };
    recalculate = false;
    return result;
}