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.cloudera.oryx.als.serving.ServerRecommender.java

@Override
public float[] similarityToItem(String toItemID, String... itemIDs)
        throws NotReadyException, NoSuchItemException {

    Generation generation = getCurrentGeneration();
    LongObjectMap<float[]> Y = generation.getY();

    float[] similarities = new float[itemIDs.length];
    Lock yLock = generation.getYLock().readLock();
    yLock.lock();//from  www. j a  v a 2s . c  om
    try {

        float[] toFeatures = Y.get(StringLongMapping.toLong(toItemID));
        if (toFeatures == null) {
            throw new NoSuchItemException(toItemID);
        }
        double toFeaturesNorm = SimpleVectorMath.norm(toFeatures);

        boolean anyFound = false;
        for (int i = 0; i < similarities.length; i++) {
            float[] features = Y.get(StringLongMapping.toLong(itemIDs[i]));
            if (features == null) {
                similarities[i] = Float.NaN;
            } else {
                anyFound = true;
                double featuresNorm = SimpleVectorMath.norm(features);
                similarities[i] = (float) (SimpleVectorMath.dot(features, toFeatures)
                        / (featuresNorm * toFeaturesNorm));
            }
        }
        if (!anyFound) {
            throw new NoSuchItemException(Arrays.toString(itemIDs));
        }

    } finally {
        yLock.unlock();
    }

    return similarities;
}

From source file:pipeline.misc_util.Utils.java

private static float[] minMaxSlidingWindow(float[][] numbers, float windowLength) {
    int windowStart = 0;

    float[] result = new float[numbers.length];
    int arrayIndex = 0;
    float globalMin = Float.MAX_VALUE;

    for (float[] number : numbers) {
        if (number[1] < globalMin)
            globalMin = number[1];// w ww. j  ava  2  s .  co m
    }

    while (arrayIndex < numbers.length - 1) {
        int effectiveEnd = windowStart;
        while ((numbers[effectiveEnd][0] - numbers[windowStart][0] < windowLength)
                && (effectiveEnd < numbers.length - 1))
            effectiveEnd++;

        float max = -Float.MAX_VALUE;
        float min = Float.MAX_VALUE;

        for (int i = windowStart; i < effectiveEnd; i++) {
            if (numbers[i][1] > max)
                max = numbers[i][1];
            if (numbers[i][1] < min)
                min = numbers[i][1];
        }

        if (min > globalMin)
            result[arrayIndex] = (max - min) / (min - globalMin);
        else
            result[arrayIndex] = Float.NaN;

        windowStart++;
        arrayIndex++;
    }

    return result;
}

From source file:com.affectiva.affdexme.MainActivity.java

/**
 * Use the method that we saved in activateMetric() to get the metric score and display it
 *//*from   w  ww.  java2 s.c om*/
void updateMetricScore(MetricDisplay metricDisplay, Face face) {

    MetricsManager.Metrics metric = metricDisplay.getMetricToDisplay();
    float score = Float.NaN;

    try {
        switch (metric.getType()) {
        case Emotion:
            score = (Float) metricDisplay.getFaceScoreMethod().invoke(face.emotions);
            break;
        case Expression:
            score = (Float) metricDisplay.getFaceScoreMethod().invoke(face.expressions);
            break;
        case Emoji:
            score = (Float) metricDisplay.getFaceScoreMethod().invoke(face.emojis);
            break;
        default:
            throw new Exception("Unknown Metric Type: " + metric.getType().toString());
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, String.format("Error using reflecting to get %s score from face.", metric.toString()));
    }
    metricDisplay.setScore(score);
}

From source file:com.yahoo.egads.models.tsmm.TestOlympicModel2.java

@Test
public void trainDrop() throws Exception {
    // one high/* w  w  w. j a  v  a2 s. co  m*/
    config.setProperty("NUM_TO_DROP_HIGHEST", "1");
    config.setProperty("NUM_TO_DROP_LOWEST", "0");
    OlympicModel2 model = new OlympicModel2(config);
    TimeSeries ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(20.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(41.66666, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // two high
    config.setProperty("NUM_TO_DROP_HIGHEST", "2");
    config.setProperty("NUM_TO_DROP_LOWEST", "0");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(15.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(35.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // one low
    config.setProperty("NUM_TO_DROP_HIGHEST", "0");
    config.setProperty("NUM_TO_DROP_LOWEST", "1");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(30.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(55.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // two low
    config.setProperty("NUM_TO_DROP_HIGHEST", "0");
    config.setProperty("NUM_TO_DROP_LOWEST", "2");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(35.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(60.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // one each
    config.setProperty("NUM_TO_DROP_HIGHEST", "1");
    config.setProperty("NUM_TO_DROP_LOWEST", "1");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(25.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(50.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // two each - TOO MANY so we drop as much as possible
    config.setProperty("NUM_TO_DROP_HIGHEST", "2");
    config.setProperty("NUM_TO_DROP_LOWEST", "2");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, 20);
    ts.append(1476057900, 45);

    ts.append(1476662400, 30);
    ts.append(1476662700, 55);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(30.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(55.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));

    // one each - TOO MANY so we drop as much as possible
    config.setProperty("NUM_TO_DROP_HIGHEST", "1");
    config.setProperty("NUM_TO_DROP_LOWEST", "1");
    model = new OlympicModel2(config);
    ts = new TimeSeries();
    ts.append(1475452800, 10);
    ts.append(1475453100, 25);

    ts.append(1476057600, Float.NaN);
    ts.append(1476057900, Float.NaN);

    ts.append(1476662400, Float.NaN);
    ts.append(1476662700, Float.NaN);

    ts.append(1477267200, 40);
    ts.append(1477267500, 65);

    model.train(ts.data);

    assertEquals(13, model.model.size());
    assertEquals(1477872000, (long) model.model.get(0).getKey());
    assertEquals(40.0, model.model.get(0).getValue(), 0.00001);
    assertEquals(1477872300, (long) model.model.get(1).getKey());
    assertEquals(65.0, model.model.get(1).getValue(), 0.00001);
    assertEquals(1477872600, (long) model.model.get(2).getKey());
    assertTrue(Double.isNaN(model.model.get(2).getValue()));
}

From source file:au.org.ala.layers.intersect.Grid.java

/**
 * do get values of grid for provided points.
 * <p/>/* ww  w.  j  av  a 2s .co  m*/
 * loads whole grid file as double[] in process
 *
 * @param points
 * @return
 */
public float[] getValues2(double[][] points) {
    if (points == null || points.length == 0) {
        return null;
    }

    if (subgrid)
        return getValues3(points, Math.min(1024 * 1024, 64 * points.length));

    //init output structure
    float[] ret = new float[points.length];

    //load whole grid
    float[] grid = getGrid();
    int glen = grid.length;
    int length = points.length;
    int i, pos;

    //points loop
    for (i = 0; i < length; i++) {
        pos = (int) getcellnumber(points[i][0], points[i][1]);
        if (pos >= 0 && pos < glen) {
            ret[i] = grid[pos];
        } else {
            ret[i] = Float.NaN;
        }
    }

    return ret;
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#isNaN(java.lang.Object)}.
 *///from  ww  w.jav a2 s.co  m
@Test
public void testIsNaNObject() {
    assertEquals("null", false, isNaN(null));
    assertEquals("empty", false, isNaN(""));
    assertEquals("invalidString", false, isNaN("not a number"));
    assertEquals("notParsable", false, isNaN(new int[] { 1, 2, 3 }));
    assertEquals("notParsable", false, isNaN(new float[] { Float.NaN }));
    assertEquals("Infinity", false, isNaN(Double.POSITIVE_INFINITY));
    assertEquals("-Infinity", false, isNaN(Float.NEGATIVE_INFINITY));
}

From source file:net.myrrix.online.ServerRecommender.java

@Override
public float[] similarityToItem(long toItemID, long... itemIDs) throws TasteException {

    Generation generation = getCurrentGeneration();
    FastByIDMap<float[]> Y = generation.getY();

    float[] similarities = new float[itemIDs.length];
    Lock yLock = generation.getYLock().readLock();
    yLock.lock();/*from  ww w .  j a  va2  s  .c o  m*/
    try {

        float[] toFeatures = Y.get(toItemID);
        if (toFeatures == null) {
            throw new NoSuchItemException(toItemID);
        }
        double toFeaturesNorm = SimpleVectorMath.norm(toFeatures);

        boolean anyFound = false;
        for (int i = 0; i < similarities.length; i++) {
            float[] features = Y.get(itemIDs[i]);
            if (features == null) {
                similarities[i] = Float.NaN;
            } else {
                anyFound = true;
                double featuresNorm = SimpleVectorMath.norm(features);
                similarities[i] = (float) (SimpleVectorMath.dot(features, toFeatures)
                        / (featuresNorm * toFeaturesNorm));
            }
        }
        if (!anyFound) {
            throw new NoSuchItemException(Arrays.toString(itemIDs));
        }

    } finally {
        yLock.unlock();
    }

    return similarities;
}

From source file:au.org.ala.layers.intersect.Grid.java

float[] getGrid(double xmin, double ymin, double xmax, double ymax) {
    //expects largest y at the top
    //expects input ranges inside of grid ranges

    int width = (int) ((xmax - xmin) / xres);
    int height = (int) ((ymax - ymin) / yres);
    int startx = (int) ((xmin - this.xmin) / xres);
    int endx = startx + width;
    int starty = (int) ((ymin - this.ymin) / yres);
    //int endy = starty + height;

    int length = width * height;

    float[] ret = new float[length];
    int pos = 0;/*ww  w.  j av a  2  s .c o  m*/

    int i;
    RandomAccessFile afile = null;
    File f2 = new File(filename + ".GRI");

    int size = 4;
    if (datatype.equals("BYTE") || datatype.equals("UBYTE")) {
        size = 1;
    } else if (datatype.equals("SHORT")) {
        size = 2;
    } else if (datatype.equals("INT")) {
        size = 4;
    } else if (datatype.equals("LONG")) {
        size = 8;
    } else if (datatype.equals("FLOAT")) {
        size = 4;
    } else if (datatype.equals("DOUBLE")) {
        size = 8;
    }

    try { //read of random access file can throw an exception
        if (!f2.exists()) {
            afile = new RandomAccessFile(filename + ".gri", "r");
        } else {
            afile = new RandomAccessFile(filename + ".GRI", "r");
        }

        //seek to first raster
        afile.seek(((long) this.ncols) * starty * size);

        //read relevant rasters
        int readSize = this.ncols * height * size;
        int readLen = this.ncols * height;
        byte[] b = new byte[readSize];
        afile.read(b);
        ByteBuffer bb = ByteBuffer.wrap(b);

        if (byteorderLSB) {
            bb.order(ByteOrder.LITTLE_ENDIAN);
        }

        if (datatype.equalsIgnoreCase("BYTE")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.get();
                } else {
                    ret[pos++] = bb.get();
                }
            }
        } else if (datatype.equalsIgnoreCase("UBYTE")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.get();
                } else {
                    ret[pos] = bb.get();
                    if (ret[pos] < 0) {
                        ret[pos] += 256;
                    }
                    pos++;
                }
            }
        } else if (datatype.equalsIgnoreCase("SHORT")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.getShort();
                } else {
                    ret[pos++] = bb.getShort();
                }
            }
        } else if (datatype.equalsIgnoreCase("INT")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.getInt();
                } else {
                    ret[pos++] = bb.getInt();
                }
            }
        } else if (datatype.equalsIgnoreCase("LONG")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.getLong();
                } else {
                    ret[pos++] = bb.getLong();
                }
            }
        } else if (datatype.equalsIgnoreCase("FLOAT")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.getFloat();
                } else {
                    ret[pos++] = bb.getFloat();
                }
            }
        } else if (datatype.equalsIgnoreCase("DOUBLE")) {
            for (i = 0; i < readLen; i++) {
                int x = i % this.ncols;
                if (x < startx || x >= endx) {
                    bb.getDouble();
                } else {
                    ret[pos++] = (float) bb.getDouble();
                }
            }
        } else {
            // / should not happen; catch anyway...
            for (i = 0; i < length; i++) {
                ret[i] = Float.NaN;
            }
        }
        //replace not a number
        for (i = 0; i < length; i++) {
            if ((float) ret[i] == (float) nodatavalue) {
                ret[i] = Float.NaN;
            } else {
                ret[i] *= rescale;
            }
        }
    } catch (Exception e) {
        logger.error("GRID: " + e.toString(), e);
    } finally {
        if (afile != null) {
            try {
                afile.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    grid_data = ret;
    return ret;
}

From source file:com.androzic.Androzic.java

public float getHDOP() {
    if (locationService != null)
        return locationService.getHDOP();
    else//from   w w  w. j  a  v a 2  s.co  m
        return Float.NaN;
}

From source file:com.androzic.Androzic.java

public float getVDOP() {
    if (locationService != null)
        return locationService.getVDOP();
    else//w ww .j a  v a  2s .com
        return Float.NaN;
}