Example usage for java.lang Float NaN

List of usage examples for java.lang Float NaN

Introduction

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

Prototype

float NaN

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

Click Source Link

Document

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

Usage

From source file:com.numenta.htmit.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date//from ww w  .j  av  a 2s  .c om
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, HTMITApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - HTMITApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        HTMITDatabase database = HTMITApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = database.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:norbert.mynemo.core.evaluation.PersonnalRecommenderEvaluator.java

/**
 * Returns the absolute difference between the given preference and the estimated one. Depending
 * on the recommender, the returned float may be NaN.
 *///from  www  . ja  v a 2  s.  com
private float getError(DataModel trainingModel, Recommender recommender, Preference preference)
        throws TasteException {
    float estimation = Float.NaN;
    predictionRequestNumber++;
    try {
        // may return Float.NaN
        estimation = capEstimatedPreference(recommender.estimatePreference(targetUser, preference.getItemID()),
                trainingModel);
    } catch (NoSuchUserException | NoSuchItemException exception) {
        // It's possible that an item exists in the test data but not
        // training data in which case NSEE or NSIE will be thrown.
    }
    return Math.abs(estimation - preference.getValue());
}

From source file:com.YOMPsolutions.YOMP.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date/*from   w  w w  . ja  v  a 2 s . com*/
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, YOMPApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - YOMPApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        YOMPDatabase YOMPdb = YOMPApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = YOMPdb.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:com.groksolutions.grok.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date//w w  w  .  j  a v  a 2 s .c  om
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, HTMITApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - HTMITApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        GrokDatabase grokdb = HTMITApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = grokdb.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:edu.ucsc.barrel.cdf_gen.SpectrumExtract.java

private static float[] binvert(float[] start, float f) {
    int size = start.length, bad_vals = 0;

    float[] iter1 = new float[size];
    float[] iter2 = new float[size];

    //first iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (start[i] < 0) {
            iter1[i] = Float.NaN;
        } else {/*from w  w w.j ava2  s. c o  m*/
            iter1[i] = (start[i] + f * start[i]) / (1.0f + f * (1.0f + (float) Math.log(start[i])));
            if (iter1[i] < 0) {
                iter1[i] = Float.NaN;
            }
        }
    }

    //second iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (Float.isNaN(iter1[i])) {
            bad_vals++;
        } else {
            iter2[i] = (start[i] + f * iter1[i]) / (1.0f + f * (1.0f + (float) Math.log(iter1[i])));
            if (Float.isInfinite(iter2[i]) || iter2[i] < 0) {
                bad_vals++;
                iter2[i] = Float.NaN;
            }
        }
    }

    //turn bad values into negatives ascending to zero
    if (bad_vals > 0) {
        for (int i = 0; i < size; i++) {
            if (Float.isNaN(iter2[i])) {
                bad_vals--;
                iter2[i] = 0 - bad_vals;
            }
        }
    }

    return iter2;
}

From source file:org.bitpipeline.lib.owm.SampledWeatherData.java

public float getHumidity() {
    if (this.humidity != null && this.humidity.hasValue())
        return this.humidity.getValue();
    if (hasMain() && this.main.hasHumidity())
        return this.main.getHumidity();
    return Float.NaN;
}

From source file:com.cognitect.transit.TransitMPTest.java

public void testWriteReadSpecialNumbers() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer w = TransitFactory.writer(TransitFactory.Format.MSGPACK, out);
    w.write(Double.NaN);/* w  w  w  . ja v a 2 s .co m*/
    w.write(Float.NaN);
    w.write(Double.POSITIVE_INFINITY);
    w.write(Float.POSITIVE_INFINITY);
    w.write(Double.NEGATIVE_INFINITY);
    w.write(Float.NEGATIVE_INFINITY);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Reader r = TransitFactory.reader(TransitFactory.Format.MSGPACK, in);
    assert ((Double) r.read()).isNaN();
    assert ((Double) r.read()).isNaN();
    assertEquals(Double.POSITIVE_INFINITY, (Double) r.read());
    assertEquals(Double.POSITIVE_INFINITY, (Double) r.read());
    assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read());
    assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read());
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static float convertToFloat(String s) {
    if ((s == null) || s.equals("")) {
        return Float.NaN;
    }/*  w w w  .  j av  a2s .  c o m*/
    if (s.startsWith("+")) {
        s = s.substring(1);
    }
    if (POSITIVE_INFINITY.equals(s)) {
        return Float.POSITIVE_INFINITY;
    } else if (NEGATIVE_INFINITY.equals(s)) {
        return Float.NEGATIVE_INFINITY;
    }
    return Float.parseFloat(s);
}

From source file:org.bitpipeline.lib.owm.SampledWeatherData.java

public float getPressure() {
    if (this.pressure != null && this.pressure.hasValue())
        return this.pressure.getValue();
    if (hasMain() && this.main.hasPressure())
        return this.main.getPressure();
    return Float.NaN;
}

From source file:at.pagu.soldockr.core.query.Criteria.java

private String processCriteriaEntry(String key, Object value) {
    if (value == null) {
        return null;
    }//  w w  w.j  a  v a  2 s.  c om

    // do not filter espressions
    if (StringUtils.equals(OperationKey.EXPRESSION.getKey(), key)) {
        return value.toString();
    }

    if (StringUtils.equals(OperationKey.BETWEEN.getKey(), key)) {
        Object[] args = (Object[]) value;
        String rangeFragment = "[";
        rangeFragment += args[0] != null ? filterCriteriaValue(args[0]) : WILDCARD;
        rangeFragment += RANGE_OPERATOR;
        rangeFragment += args[1] != null ? filterCriteriaValue(args[1]) : WILDCARD;
        rangeFragment += "]";
        return rangeFragment;
    }

    Object filteredValue = filterCriteriaValue(value);
    if (StringUtils.equals(OperationKey.CONTAINS.getKey(), key)) {
        return WILDCARD + filteredValue + WILDCARD;
    }
    if (StringUtils.equals(OperationKey.STARTS_WITH.getKey(), key)) {
        return filteredValue + WILDCARD;
    }
    if (StringUtils.equals(OperationKey.ENDS_WITH.getKey(), key)) {
        return WILDCARD + filteredValue;
    }
    if (StringUtils.equals(OperationKey.IS_NOT.getKey(), key)) {
        return "-" + filteredValue;
    }

    if (StringUtils.startsWith(key, "$fuzzy")) {
        String sDistance = StringUtils.substringAfter(key, "$fuzzy#");
        float distance = Float.NaN;
        if (StringUtils.isNotBlank(sDistance)) {
            distance = Float.parseFloat(sDistance);
        }
        return filteredValue + "~" + (Float.isNaN(distance) ? "" : sDistance);
    }

    return filteredValue.toString();
}