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:org.jfree.chart.demo.SampleXYSymbolicDataset.java

/**
 * Returns the y-value (as a double primitive) for an item within a series.
 * /*from   w  w w.j  a  va  2  s.  c om*/
 * @param series
 *           the series (zero-based index).
 * @param item
 *           the item (zero-based index).
 * @return The y-value.
 */
public double getY(int series, int item) {
    double result = Double.NaN;
    Number y = getYValue(series, item);
    if (y != null) {
        result = y.doubleValue();
    }
    return result;
}

From source file:com.fluidops.iwb.widget.GMapWidget.java

public static String[] parseGeoCoords(String coords) {
    double lat = Double.NaN, lng = Double.NaN;

    String toParse;//from  w  w  w  .  j a va 2  s.c om
    if (coords.startsWith("{{coord") && coords.endsWith("}}")) {
        toParse = coords.substring(coords.indexOf('|') + 1, coords.indexOf('}'));
        // single components
        String[] cs = toParse.split("\\|");

        switch (cs.length) {
        case 0:
        case 1:
            throw new IllegalArgumentException(coords + " is not a valid GeoCoord!!");

        case 2:
        case 3: /* decimal with sign */
            lat = valueOf(cs[0]);
            lng = valueOf(cs[1]);
            break;

        case 4:
        case 5: /* have decimal coords with [NS][WE] specs */
            if (Character.isLetter(cs[1].charAt(0)) && Character.isLetter(cs[3].charAt(0))) {
                lat = valueOf(cs[0]) * convertLatSpecToSign(cs[1]);
                lng = valueOf(cs[2]) * convertLngSpecToSign(cs[3]);
            } else {
                double hrslat = valueOf(cs[0]);
                double hrslng = valueOf(cs[2]);
                lat = convertDegToDec(Math.abs(hrslat), valueOf(cs[1]), 0, (int) Math.signum(hrslat));
                lng = convertDegToDec(Math.abs(hrslng), valueOf(cs[3]), 0, (int) Math.signum(hrslng));
            }
            break;

        case 6:
        case 7: /* now degree coords with sign or in DM format (degree, min) */
            if (Character.isLetter(cs[2].charAt(0)) && Character.isLetter(cs[5].charAt(0))) {
                /* is in DM format */
                lat = convertDegToDec(valueOf(cs[0]), valueOf(cs[1]), 0.0, convertLatSpecToSign(cs[2]));
                lng = convertDegToDec(valueOf(cs[3]), valueOf(cs[4]), 0.0, convertLngSpecToSign(cs[5]));
            } else {
                /* is degree coords with sign */
                double hrslat = valueOf(cs[0]);
                double hrslng = valueOf(cs[3]);
                lat = convertDegToDec(Math.abs(hrslat), valueOf(cs[1]), valueOf(cs[2]),
                        (int) Math.signum(hrslat));
                lng = convertDegToDec(Math.abs(hrslng), valueOf(cs[4]), valueOf(cs[5]),
                        (int) Math.signum(hrslng));
                break;
            }
            break;

        default: /* have degree coords with [NS][WE] specs */
            lat = convertDegToDec(valueOf(cs[0]), valueOf(cs[1]), valueOf(cs[2]), convertLatSpecToSign(cs[3]));
            lng = convertDegToDec(valueOf(cs[4]), valueOf(cs[5]), valueOf(cs[6]), convertLngSpecToSign(cs[7]));
            break;

        }
    } else {
        String[] sep = coords.split("\\s+");
        if (sep.length == 2) {
            return sep;
        }

        sep = coords.split(",");
        if (sep.length == 2) {
            return sep;
        }
    }

    return new String[] { String.format(Locale.US, "%3.6f", lat), String.format(Locale.US, "%3.6f", lng) };
}

From source file:com.fay.statics.SummaryStat.java

public double lastWeight() {
    if (numObs == 0)
        return Double.NaN;
    return lastWeight;
}

From source file:ch.epfl.lsir.xin.algorithm.core.UserBasedCF.java

/**
 * This function calculates the similarity matrix for users
 * *///from   www.j ava2s. c o  m
public void similarityMatrixCalculation() {
    for (int i = 0; i < this.ratingMatrix.getRow(); i++) {
        for (int j = i; j < this.ratingMatrix.getRow(); j++) {
            if (i == j) //the similarity with herself is 1 
            {
                this.similarityMatrix[i][j] = 1;
            } else {
                ArrayList<Double> commonRatings1 = new ArrayList<Double>();
                ArrayList<Double> commonRatings2 = new ArrayList<Double>();
                //find common items for the two users
                for (Map.Entry<Integer, Double> entry : this.ratingMatrix.getRatingMatrix().get(i).entrySet()) {
                    int itemI = entry.getKey();
                    if (entry.getValue() != null
                            && this.ratingMatrix.getRatingMatrix().get(j).get(itemI) != null) {
                        commonRatings1.add(this.ratingMatrix.getRatingMatrix().get(i).get(itemI));
                        commonRatings2.add(this.ratingMatrix.getRatingMatrix().get(j).get(itemI));
                    }
                }

                double similarity = Double.NaN;
                if (this.similarityCalculation.equals("pcc")) {
                    similarity = SimilarityCalculator.getSimilarityPCC(commonRatings1, commonRatings2,
                            this.config.getInt("SHRINKAGE"));
                } else if (this.similarityCalculation.equals("cosine")) {
                    similarity = SimilarityCalculator.getSimilarityCosine(commonRatings1, commonRatings2,
                            this.config.getInt("SHRINKAGE"));
                } else {
                    logger.append("Cannot determine which similarity calculation method is used for. \n");
                    return;
                }

                if (Double.isNaN(similarity)) {
                    similarity = 0;
                }
                this.similarityMatrix[i][j] = similarity;
                this.similarityMatrix[j][i] = similarity;
            }
        }
    }
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalMixtureModel.java

public double posteriorProbability(int group, int dataRow) {
    int index = 0;
    double value = 0.0;
    double sum = 0.0;
    double pi = 0.0;
    RealMatrix row = data.getRowMatrix(dataRow);
    try {/*from   w  w  w .ja v a2 s.co m*/
        for (ComponentDistribution compDist : compDistribution) {
            pi = compDist.getMixingProportion();
            sum += pi * compDist.density(row);
            if (index == group)
                value = pi * compDist.density(row);
            index++;
        }
        if (sum == 0.0)
            return Double.NaN;
    } catch (SingularMatrixException ex) {
        statusMessage = "Singular Matrix";
    }

    return value / sum;
}

From source file:de.bund.bfr.math.MultivariateOptimization.java

@Override
public Result optimize(int nParameterSpace, int nOptimizations, boolean stopWhenSuccessful,
        Map<String, Double> minStartValues, Map<String, Double> maxStartValues, int maxIterations,
        DoubleConsumer progessListener, ExecutionContext exec) throws CanceledExecutionException {
    if (exec != null) {
        exec.checkCanceled();//from   w  ww.  ja v a 2 s. co  m
    }

    progessListener.accept(0.0);

    List<ParamRange> ranges = MathUtils.getParamRanges(parameters, minStartValues, maxStartValues,
            nParameterSpace);

    ranges.set(parameters.indexOf(sdParam), new ParamRange(1.0, 1, 1.0));

    List<StartValues> startValuesList = MathUtils.createStartValuesList(ranges, nOptimizations,
            values -> optimizerFunction.value(Doubles.toArray(values)),
            progress -> progessListener.accept(0.5 * progress), exec);
    Result result = new Result();
    AtomicInteger currentIteration = new AtomicInteger();
    SimplexOptimizer optimizer = new SimplexOptimizer(new SimpleValueChecker(1e-10, 1e-10) {

        @Override
        public boolean converged(int iteration, PointValuePair previous, PointValuePair current) {
            if (super.converged(iteration, previous, current)) {
                return true;
            }

            return currentIteration.incrementAndGet() >= maxIterations;
        }
    });
    int count = 0;

    for (StartValues startValues : startValuesList) {
        if (exec != null) {
            exec.checkCanceled();
        }

        progessListener.accept(0.5 * count++ / startValuesList.size() + 0.5);

        try {
            PointValuePair optimizerResults = optimizer.optimize(new MaxEval(Integer.MAX_VALUE),
                    new MaxIter(maxIterations), new InitialGuess(Doubles.toArray(startValues.getValues())),
                    new ObjectiveFunction(optimizerFunction), GoalType.MAXIMIZE,
                    new NelderMeadSimplex(parameters.size()));
            double logLikelihood = optimizerResults.getValue() != null ? optimizerResults.getValue()
                    : Double.NaN;

            if (result.logLikelihood == null || logLikelihood > result.logLikelihood) {
                result = getResults(optimizerResults);

                if (result.logLikelihood == 0.0 || stopWhenSuccessful) {
                    break;
                }
            }
        } catch (TooManyEvaluationsException | TooManyIterationsException | ConvergenceException e) {
        }
    }

    return result;
}

From source file:mase.mason.generic.systematic.SystematicEvaluator.java

@Override
protected void evaluate(MasonSimState sim) {
    int index = 0;
    for (int gi = 0; gi < td.groups().length; gi++) {
        EntityGroup eg = td.groups()[gi];
        if (evaluateGroup[gi]) {
            // Percentage of alive agents
            if (numAlive && eg.getMaxSize() > eg.getMinSize()) {
                features.get(index++)//from   w w w.j a v  a 2s  .c o m
                        .add((double) (eg.size() - eg.getMinSize()) / (eg.getMaxSize() - eg.getMinSize()));
            }

            // Average state of the group -- if none alive it is filled with NaN
            double[] averageState = eg.getAverageState();
            if (stateMean) {
                for (int i = 0; i < averageState.length; i++) {
                    features.get(index++).add(averageState[i]);
                }
            }

            // StateVariables dispersion -- average difference to the mean value
            if (stateDeviation && eg.getMaxSize() > 1) {
                // If the group has more than one alive
                if (eg.size() > 1) {
                    double[] diffs = new double[averageState.length];
                    for (Entity e : eg.getEntities()) {
                        double[] vars = e.getStateVariables();
                        for (int i = 0; i < averageState.length; i++) {
                            diffs[i] += FastMath.pow2(averageState[i] - vars[i]);
                        }
                    }
                    for (int i = 0; i < diffs.length; i++) {
                        double sd = FastMath.sqrtQuick(diffs[i] / eg.size());
                        features.get(index++).add(sd);
                    }
                } else {
                    for (int i = 0; i < 1 + averageState.length; i++) {
                        features.get(index++).add(Double.NaN);
                    }
                }
            }

            // Physical dispersion -- mean distance of each entity to the other entities
            if (physicalRelations && eg.getMaxSize() > 1 && !eg.isStatic()) {
                throw new UnsupportedOperationException("Distance function undefined");
                //double dist = td.distanceFunction().distance(eg, eg); 
                //features.get(index++).add(dist);
            }
        }

        // Relations with other entities -- physical distances
        if (physicalRelations) {
            for (int go = gi + 1; go < td.groups().length; go++) {
                EntityGroup otherG = td.groups()[go];
                if ((!eg.isStatic() || !otherG.isStatic()) && (evaluateGroup[gi] || evaluateGroup[go])) {
                    throw new UnsupportedOperationException("Distance function undefined");
                    //features.get(index++).add(td.distanceFunction().distance(eg, otherG));
                }
            }
        }
    }
    if (size == -1) {
        size = index;
    } else if (size != index) {
        System.out.println("Incoherent size! Expected: " + size + " Got: " + index);
    }
}

From source file:com.rapidminer.operator.preprocessing.filter.InfiniteValueReplenishment.java

/**
 * Replaces the values/*from  w  ww.  j  a  v  a 2s . c  om*/
 *
 * @throws UndefinedParameterError
 */
@Override
public double getReplenishmentValue(int functionIndex, ExampleSet exampleSet, Attribute attribute)
        throws UndefinedParameterError {
    int chosen = getParameterAsInt(PARAMETER_REPLENISHMENT_WHAT);
    switch (functionIndex) {
    case NONE:
        return Double.POSITIVE_INFINITY;
    case ZERO:
        return 0.0;
    case MAX_BYTE:
        return (chosen == 0) ? Byte.MAX_VALUE : Byte.MIN_VALUE;
    case MAX_INT:
        return (chosen == 0) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
    case MAX_DOUBLE:
        return (chosen == 0) ? Double.MAX_VALUE : -Double.MAX_VALUE;
    case MISSING:
        return Double.NaN;
    case VALUE:
        return getParameterAsDouble(PARAMETER_REPLENISHMENT_VALUE);
    default:
        throw new RuntimeException("Illegal value functionIndex: " + functionIndex);
    }
}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.CurveDataset.java

/**
 * @see org.jfree.data.xy.XYDataset#getYValue(int, int)
 *//*from   w  w  w. j a v a2 s .  co  m*/
@Override
public double getYValue(final int series, final int item) {
    final Number y = getY(series, item);

    return y == null ? Double.NaN : y.doubleValue();
}

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

/** Get the maximum recorded value (range maximum). */
public double getMinRecordedValue() {
    if (lastValueInserted == Double.NaN)
        throw new IllegalStateException("EmpiricalDistribution.getMinRecordedValue: no records.");
    return minRecordValue;
}