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:mercury.core.AngularParameter.java

public Double getDouble(String aDouble) {
    return getDouble(aDouble, Double.NaN);
}

From source file:com.cti.vpx.controls.graph.utilities.ui.graphs.waterfallGraph.Variance.java

public double getVariance() {
    if (n == 0) {
        return Double.NaN;
    } else if (n == 1) {
        return 0d;
    } else {//from   www . ja  va 2 s  .co m
        return m2 / (n - 1d);
    }
}

From source file:com.cloudera.oryx.rdf.common.tree.DecisionForest.java

public DecisionForest(final int numTrees, double fractionOfFeaturesToTry, final int minNodeSize,
        final double minInfoGainNats, final int suggestedMaxSplitCandidates, final int maxDepth,
        final double sampleRate, final ExampleSet examples) {
    Preconditions.checkArgument(numTrees > 1);
    final int numFeatures = examples.getNumFeatures();
    Preconditions.checkArgument(fractionOfFeaturesToTry > 0.0 && fractionOfFeaturesToTry <= 1.0);
    final int featuresToTry = FastMath.max(1, (int) (fractionOfFeaturesToTry * numFeatures));
    Preconditions.checkArgument(numFeatures >= 1);
    Preconditions.checkArgument(minNodeSize >= 1);
    Preconditions.checkArgument(minInfoGainNats >= 0.0);
    Preconditions.checkArgument(suggestedMaxSplitCandidates >= 1);
    Preconditions.checkArgument(maxDepth >= 1);
    Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0);

    weights = new double[numTrees];
    Arrays.fill(weights, 1.0);//  www .j  ava  2 s  .  c om
    evaluations = new double[numTrees];
    Arrays.fill(evaluations, Double.NaN);
    final double[][] perTreeFeatureImportances = new double[numTrees][];

    // Going to set an arbitrary upper bound on the training size of about 90%
    int maxFolds = FastMath.min(numTrees - 1, (int) (0.9 * numTrees));
    // Going to set an arbitrary lower bound on the CV size of about 10%
    int minFolds = FastMath.max(1, (int) (0.1 * numTrees));
    final int folds = FastMath.min(maxFolds, FastMath.max(minFolds, (int) (sampleRate * numTrees)));

    trees = new DecisionTree[numTrees];

    ExecutorService executor = Executors.newFixedThreadPool(determineParallelism(trees.length));
    try {
        Collection<Future<Object>> futures = Lists.newArrayListWithCapacity(trees.length);
        for (int i = 0; i < numTrees; i++) {
            final int treeID = i;
            futures.add(executor.submit(new Callable<Object>() {
                @Override
                public Void call() throws Exception {
                    Collection<Example> allExamples = examples.getExamples();
                    int totalExamples = allExamples.size();
                    int expectedTrainingSize = (int) (totalExamples * sampleRate);
                    int expectedCVSize = totalExamples - expectedTrainingSize;
                    List<Example> trainingExamples = Lists.newArrayListWithExpectedSize(expectedTrainingSize);
                    List<Example> cvExamples = Lists.newArrayListWithExpectedSize(expectedCVSize);
                    for (Example example : allExamples) {
                        if (IntMath.mod(IntMath.mod(example.hashCode(), numTrees) - treeID, numTrees) < folds) {
                            trainingExamples.add(example);
                        } else {
                            cvExamples.add(example);
                        }
                    }

                    Preconditions.checkState(!trainingExamples.isEmpty(), "No training examples sampled?");
                    Preconditions.checkState(!cvExamples.isEmpty(), "No CV examples sampled?");

                    trees[treeID] = new DecisionTree(numFeatures, featuresToTry, minNodeSize, minInfoGainNats,
                            suggestedMaxSplitCandidates, maxDepth, examples.subset(trainingExamples));
                    log.info("Finished tree {}", treeID);
                    ExampleSet cvExampleSet = examples.subset(cvExamples);
                    double[] weightEval = Evaluation.evaluateToWeight(trees[treeID], cvExampleSet);
                    weights[treeID] = weightEval[0];
                    evaluations[treeID] = weightEval[1];
                    perTreeFeatureImportances[treeID] = trees[treeID].featureImportance(cvExampleSet);
                    log.info("Tree {} eval: {}", treeID, weightEval[1]);
                    return null;
                }
            }));
        }
        ExecutorUtils.checkExceptions(futures);
    } finally {
        ExecutorUtils.shutdownNowAndAwait(executor);
    }

    featureImportances = new double[numFeatures];
    for (double[] perTreeFeatureImporatance : perTreeFeatureImportances) {
        for (int i = 0; i < numFeatures; i++) {
            featureImportances[i] += perTreeFeatureImporatance[i];
        }
    }
    for (int i = 0; i < numFeatures; i++) {
        featureImportances[i] /= numTrees;
    }
}

From source file:com.ironiacorp.statistics.r.type.LinearModelSummary.java

/**
 * @param fnames names of the factors//w  ww.  ja  va  2 s .c  o m
 * @return
 * @see ubic.basecode.util.r.type.GenericAnovaResult#getInteractionEffectP(java.lang.String)
 */
public Double getInteractionEffectP(String... fnames) {
    if (anovaResult == null)
        return Double.NaN;
    return anovaResult.getInteractionEffectP(fnames);
}

From source file:edu.duke.cs.osprey.tupexp.IterativeCGTupleFitter.java

double getCurTarget(int s) {//get current "target" value (for iteration of modified lsq)
    //for the given sample.  NaN if not applicable (restraints inactive for sample)
    double bounds[] = goodRegionBounds.get(s);
    if (curFitVals == null) {//First iteration.  Assume
        //samples with any leeway don't have a target
        if (bounds[0] == bounds[1])
            return bounds[0];
        else/*w w  w. j a va  2  s . c  o  m*/
            return Double.NaN;
    } else {
        double curFitVal = curFitVals[s];
        if (curFitVal < bounds[0])//lower restraint active
            return bounds[0];
        else if (curFitVal > bounds[1])//upper
            return bounds[1];
        else//neither
            return Double.NaN;
    }
}

From source file:ffx.xray.MTZFilterTest.java

@Test
public void testMTZHKL() {
    MTZFilter mtzFilter = new MTZFilter();
    assertTrue("mtz file errors", mtzFilter.readFile(mtzFile, reflectionList, refinementData, null));
    HKL hkl = reflectionList.getHKL(-10, 1, 1);
    assertEquals("-10 1 1 FP value", 229.90, refinementData.getF(hkl.index()), 0.02);
    assertEquals("-10 1 1 SIGFP value", 2.50, refinementData.getSigF(hkl.index()), 0.02);
    assertEquals("-10 1 1 FREE value", 1, refinementData.getFreeR(hkl.index()));
    hkl = reflectionList.getHKL(-10, 1, 10);
    assertEquals("-10 1 10 FP value should be NaN", Double.NaN, refinementData.getF(hkl.index()), 0.1);
    assertEquals("-10 1 10 SIGFP value should be NaN", Double.NaN, refinementData.getSigF(hkl.index()), 0.1);
}

From source file:org.jsharkey.sky.webservice.WebserviceHelper.java

/**
 * Perform a webservice query to retrieve and store the forecast for the
 * given widget. This call blocks until request is finished and
 * {@link Forecasts#CONTENT_URI} has been updated.
 *//*from   w w  w. j  av  a  2 s. co m*/
public static void updateForecasts(Context context, Uri appWidgetUri, int days) throws ParseException {

    if (sUserAgent == null) {
        prepareUserAgent(context);
    }

    Uri appWidgetForecasts = Uri.withAppendedPath(appWidgetUri, AppWidgets.TWIG_FORECASTS);

    ContentResolver resolver = context.getContentResolver();

    Cursor cursor = null;
    double lat = Double.NaN;
    double lon = Double.NaN;
    String countryCode = null;

    // Pull exact forecast location from database
    try {
        cursor = resolver.query(appWidgetUri, PROJECTION_APPWIDGET, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            lat = cursor.getDouble(COL_LAT);
            lon = cursor.getDouble(COL_LON);
            countryCode = cursor.getString(COL_COUNTRY_CODE);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    Log.d(TAG, "using country code=" + countryCode);

    // Query webservice for this location
    List<Forecast> forecasts = null;
    if (COUNTRY_US.equals(countryCode)) {
        forecasts = new NoaaSource().getForecasts(lat, lon, days);
    } else {
        forecasts = new MetarSource().getForecasts(lat, lon, days);
    }

    if (forecasts == null || forecasts.size() == 0) {
        throw new ParseException("No forecasts found from webservice query");
    }

    // Purge existing forecasts covered by incoming data, and anything
    // before today
    long lastMidnight = ForecastUtils.getLastMidnight();
    long earliest = Long.MAX_VALUE;
    for (Forecast forecast : forecasts) {
        earliest = Math.min(earliest, forecast.validStart);
    }

    resolver.delete(appWidgetForecasts, ForecastsColumns.VALID_START + " >= " + earliest + " OR "
            + ForecastsColumns.VALID_START + " <= " + lastMidnight, null);

    // Insert any new forecasts found
    ContentValues values = new ContentValues();
    for (Forecast forecast : forecasts) {
        Log.d(TAG, "inserting forecast with validStart=" + forecast.validStart);
        values.clear();
        values.put(ForecastsColumns.VALID_START, forecast.validStart);
        values.put(ForecastsColumns.TEMP_HIGH, forecast.tempHigh);
        values.put(ForecastsColumns.TEMP_LOW, forecast.tempLow);
        values.put(ForecastsColumns.CONDITIONS, forecast.conditions);
        values.put(ForecastsColumns.URL, forecast.url);
        if (forecast.alert) {
            values.put(ForecastsColumns.ALERT, ForecastsColumns.ALERT_TRUE);
        }
        resolver.insert(appWidgetForecasts, values);
    }

    // Mark widget cache as being updated
    values.clear();
    values.put(AppWidgetsColumns.LAST_UPDATED, System.currentTimeMillis());
    resolver.update(appWidgetUri, values, null, null);
}

From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java

public void summarize() throws SQLException {
    Statement stmt = null;//from  w  ww  .  j  ava  2  s  .  c  om
    ResultSet rs = null;

    DescriptiveStatistics temp = null;

    Table sqlTable = new Table(tableName.getNameForDatabase());
    SelectQuery select = new SelectQuery();
    for (VariableAttributes v : variables) {
        select.addColumn(sqlTable, v.getName().nameForDatabase());
    }
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs = stmt.executeQuery(select.toString());

    double value = Double.NaN;
    while (rs.next()) {
        for (VariableAttributes v : variables) {
            temp = data.get(v);
            if (temp == null) {
                temp = new DescriptiveStatistics();
                data.put(v, temp);
            }

            //only increment for non null doubles
            value = rs.getDouble(v.getName().nameForDatabase());
            if (!rs.wasNull()) {
                temp.addValue(value);
            }
        }
        updateProgress();
    }

    rs.close();
    stmt.close();

    for (VariableAttributes v : data.keySet()) {
        publishTable(v);
    }

}

From source file:org.jfree.data.statistics.MeanAndStandardDeviation.java

/**
 * Returns the standard deviation as a double primitive.  If the underlying
 * standard deviation is <code>null</code>, this method will return
 * <code>Double.NaN</code>./*from w  w  w .j  a  v a 2 s .  c om*/
 *
 * @return The standard deviation.
 *
 * @since 1.0.7
 */
public double getStandardDeviationValue() {
    double result = Double.NaN;
    if (this.standardDeviation != null) {
        result = this.standardDeviation.doubleValue();
    }
    return result;
}

From source file:com.clust4j.algo.preprocess.ImputationTests.java

@Test
public void testBootstrapImputation() {
    final double[][] d = new double[][] { new double[] { Double.NaN, 1, 2 }, new double[] { 1, Double.NaN, 4 },
            new double[] { 2, 2, 1 }, new double[] { 5, 7, 12 }, new double[] { 1.2, 3, 9 },
            new double[] { 2.8, 0, 0 }, new double[] { 0, 1.5, 1 }, new double[] { 3, 5, Double.NaN } };

    final CentralTendencyMethod[] ctm = CentralTendencyMethod.values();
    final Bootstrapper[] strappers = Bootstrapper.values();

    double[][] res;
    for (CentralTendencyMethod method : ctm) {
        for (Bootstrapper strap : strappers) {
            res = new BootstrapImputation(new BootstrapImputationPlanner().setBootstrapper(strap)
                    .setVerbose(true).setMethodOfCentralTendency(method)).transform(d);

            BootstrapTest.printMatrix(res);
        }//  ww w .  j  a  v a  2 s .  c  o  m
    }

    new BootstrapImputation().transform(new Array2DRowRealMatrix(d)); // ensure doesn't break;
}