Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

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

/**
 * Crates new CriteriaEntry with trailing ~ followed by levensteinDistance
 * /* w  w w .  java  2  s . co  m*/
 * @param s
 * @param levenshteinDistance
 * @return
 */
public Criteria fuzzy(String s, float levenshteinDistance) {
    if (!Float.isNaN(levenshteinDistance)) {
        if (levenshteinDistance < 0 || levenshteinDistance > 1) {
            throw new ApiUsageException("Levenshtein Distance has to be within its bounds (0.0 - 1.0).");
        }
    }
    criteria.add(new CriteriaEntry("$fuzzy#" + levenshteinDistance, s));
    return this;
}

From source file:SoftValuedHashMap.java

/**
 * Constructs a new, empty map with the specified initial 
 * capacity and the specified load factor. 
 *
 * @param      initialCapacity   the initial capacity of the HashMap.
 * @param      loadFactor        the load factor of the HashMap
 * @throws     IllegalArgumentException  if the initial capacity is less
 *               than zero, or if the load factor is nonpositive.
 *//*from  ww w .j  a v a2 s  .c om*/
public ReferencedValueHashMap(int initialCapacity, float loadFactor) {
    if (initialCapacity < 0) {
        throw new IllegalArgumentException("Illegal Initial Capacity: " + initialCapacity);
    }

    if (loadFactor <= 0 || Float.isNaN(loadFactor)) {
        throw new IllegalArgumentException("Illegal Load factor: " + loadFactor);
    }

    if (initialCapacity == 0) {
        initialCapacity = 1;
    }

    this.loadFactor = loadFactor;
    this.table = new Entry[initialCapacity];
    this.threshold = (int) (initialCapacity * loadFactor);
}

From source file:net.pms.util.Rational.java

/**
 * Returns an instance that represents the value of {@code value}.
 *
 * @param value the value.//ww w  .j a va 2  s.  com
 * @return An instance that represents the value of {@code value}.
 */
@Nonnull
public static Rational valueOf(float value) {
    if (value == Float.POSITIVE_INFINITY) {
        return POSITIVE_INFINITY;
    }
    if (value == Float.NEGATIVE_INFINITY) {
        return NEGATIVE_INFINITY;
    }
    if (Float.isNaN(value)) {
        return NaN;
    }
    return valueOf(BigDecimal.valueOf(value));
}

From source file:SoftHashMap.java

/**
 * Constructs a new, empty <tt>SoftHashMap</tt> with the given initial
 * capacity and the given load factor./*ww  w  . ja v a 2s  .  c o m*/
 *
 * @param initialCapacity
 *      The initial capacity of the <tt>SoftHashMap</tt>
 * @param loadFactor
 *      The load factor of the <tt>SoftHashMap</tt>
 * @throws IllegalArgumentException
 *      If the initial capacity is negative, or if the load factor is
 *      nonpositive.
 */
public SoftHashMap(int initialCapacity, float loadFactor) {
    if (initialCapacity < 0)
        throw new IllegalArgumentException("Illegal Initial Capacity: " + initialCapacity);
    if (initialCapacity > MAXIMUM_CAPACITY)
        initialCapacity = MAXIMUM_CAPACITY;
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
        throw new IllegalArgumentException("Illegal Load factor: " + loadFactor);

    int capacity = 1;
    while (capacity < initialCapacity)
        capacity <<= 1;
    table = new Entry[capacity];
    this.loadFactor = loadFactor;
    threshold = (int) (capacity * loadFactor);
}

From source file:org.caleydo.core.util.impute.KNNImpute.java

public static void main(String[] args) throws IOException {
    ImmutableList.Builder<Gene> b = ImmutableList.builder();
    List<String> lines = CharStreams
            .readLines(new InputStreamReader(KNNImpute.class.getResourceAsStream("khan.csv")));
    lines = lines.subList(1, lines.size());
    int j = 0;/*from   w  ww  . j a  v a2 s.co m*/
    for (String line : lines) {
        String[] l = line.split(";");
        float[] d = new float[l.length];
        int nans = 0;
        for (int i = 0; i < l.length; ++i) {
            if ("NA".equals(l[i])) {
                nans++;
                d[i] = Float.NaN;
            } else {
                d[i] = Float.parseFloat(l[i]);
            }
        }
        b.add(new Gene(j++, nans, d));
    }
    final KNNImputeDescription desc2 = new KNNImputeDescription();
    desc2.setMaxp(100000);
    KNNImpute r = new KNNImpute(desc2, b.build());
    ForkJoinPool p = new ForkJoinPool();
    p.invoke(r);
    try (PrintWriter w = new PrintWriter("khan.imputed.csv")) {
        w.println(StringUtils.repeat("sample", ";", r.samples));
        for (Gene g : r.genes) {
            float[] d = g.data;
            int nan = 0;
            w.print(Float.isNaN(d[0]) ? g.nanReplacements[nan++] : d[0]);
            for (int i = 1; i < d.length; ++i)
                w.append(';').append(String.valueOf(Float.isNaN(d[i]) ? g.nanReplacements[nan++] : d[i]));
            w.println();
        }
    }
}

From source file:fr.amap.lidar.amapvox.jeeb.archimed.raytracing.voxel.DirectionalTransmittance.java

public double directionalTransmittance(Point3d origin, Vector3d direction) {

    List<Double> distances = distToVoxelWallsV2(origin, direction);

    //we can optimize this by storing the angle value to avoid repeating this for each position
    double directionAngle = FastMath.toDegrees(FastMath.acos(direction.z));

    double dMoy;/*from  w ww  .j  a v a2 s . com*/
    Point3d pMoy;

    double d1 = 0;
    double transmitted = 1;
    for (Double d2 : distances) {
        double pathLength = d2 - d1;
        dMoy = (d1 + d2) / 2.0;
        pMoy = new Point3d(direction);
        pMoy.scale(dMoy);
        pMoy.add(origin);
        pMoy.sub(min);

        int i = (int) Math.floor(pMoy.x / voxSize.x);
        int j = (int) Math.floor(pMoy.y / voxSize.y);
        int k = (int) Math.floor(pMoy.z / voxSize.z);

        if (i < 0 || j < 0 || k < 0 || i >= splitting.x || j >= splitting.y || k >= splitting.z) {

            if (toricity) {

                while (i < 0) {
                    i += splitting.x;
                }
                while (j < 0) {
                    j += splitting.y;
                }
                while (i >= splitting.x) {
                    i -= splitting.x;
                }
                while (j >= splitting.y) {
                    j -= splitting.y;
                }

                if (k < 0 || k >= splitting.z) {
                    break;
                }

            } else {
                break;
            }
        }

        // Test if current voxel is below the ground level
        if (pMoy.z < mnt[i][j]) {
            transmitted = 0;
        } else {
            if (Float.isNaN(voxels[i][j][k].padBV)) {
                //test
                //voxels[i][j][k].padBV = 3.536958f;
                return Double.NaN;
            }

            float coefficientGTheta = (float) direcTrans.getGThetaFromAngle(directionAngle, true);

            //input transmittance
            //double transmittedBefore = transmitted;

            transmitted *= Math.exp(-coefficientGTheta * voxels[i][j][k].padBV * pathLength);

            //output transmittance
            //double transmittedAfter = transmitted;

            //intercepted transmittance
            //double interceptedTrans = transmittedAfter - transmittedBefore;

            //transmitted *= Math.exp(-0.5 * voxels[i][j][k].padBV * pathLength)/*(default coeff)*/;
        }

        if (transmitted <= EPSILON && toricity) {
            break;
        }

        d1 = d2;
    }

    return transmitted;
}

From source file:au.org.ala.layers.dao.LayerIntersectDAOImpl.java

@Override
public Vector samplingFull(String fieldIds, double longitude, double latitude) {
    init();/*from   ww  w.  jav  a  2s.co m*/

    Vector out = new Vector();

    for (String id : fieldIds.split(",")) {
        Layer layer = null;
        int newid = cleanObjectId(id);

        IntersectionFile f = intersectConfig.getIntersectionFile(id);
        if (f != null) {
            layer = layerDao.getLayerByName(f.getLayerName(), false);
        } else {
            if (newid != -1) {
                layer = layerDao.getLayerById(newid, false);
            }
            if (layer == null) {
                layer = layerDao.getLayerByName(id, false);
            }
        }

        double[][] p = { { longitude, latitude } };

        if (layer != null) {
            if (layer.isShape() && (f != null && f.getClasses() == null)) {
                ObjectDAO objectDao = (ObjectDAO) appcontext.getBean("objectDao");
                Objects o = objectDao.getObjectByIdAndLocation(f.getFieldId(), longitude, latitude);
                if (o != null) {
                    Map m = new HashMap();
                    m.put("field", id);
                    m.put("value", o.getName());
                    m.put("layername", f.getFieldName());
                    m.put("pid", o.getPid());
                    m.put("description", o.getDescription());

                    out.add(m);
                } else {
                    Map m = new HashMap();
                    m.put("field", id);
                    m.put("value", "");
                    m.put("layername", f.getFieldName());

                    out.add(m);
                }
            } else if (layer.isGrid() || (f != null && f.getClasses() != null)) {
                Grid g = new Grid(getConfig().getLayerFilesPath() + layer.getPath_orig());
                if (g != null) {
                    float[] v = g.getValues3(p, 40960);

                    Map m = new HashMap();
                    m.put("field", id);
                    m.put("layername", f.getFieldName()); //close enough

                    if (f != null && f.getClasses() != null) {
                        GridClass gc = f.getClasses().get((int) v[0]);
                        m.put("value", (gc == null ? "" : gc.getName()));
                        if (gc != null) {
                            //TODO: re-enable intersection for type 'a' after correct implementation
                            //TODO: of 'defaultField' fields table column

                            //some grid classes may not have individual polygons created
                            if (new File(f.getFilePath() + File.separator + "polygons.grd").exists()) {
                                g = new Grid(f.getFilePath() + File.separator + "polygons");
                                if (g != null) {
                                    int v0 = (int) v[0];
                                    v = g.getValues(p);
                                    m.put("pid", f.getLayerPid() + ":" + v0 + ":" + ((int) v[0]));
                                }
                            } else {
                                //no shapes available
                                m.put("pid", f.getLayerPid() + ":" + ((int) v[0]));
                            }
                        }
                    }
                    if (!m.containsKey("value")) {
                        m.put("value", (Float.isNaN(v[0]) ? "" : v[0]));
                        m.put("units", layer.getEnvironmentalvalueunits());
                    }
                    out.add(m);
                } else {
                    logger.error(
                            "Cannot find grid file: " + getConfig().getLayerFilesPath() + layer.getPath_orig());
                    Map m = new HashMap();
                    m.put("field", id);
                    m.put("value", "");
                    m.put("layername", f.getFieldName()); //close enough

                    out.add(m);
                }
            }
        } else {
            String[] info = getConfig().getAnalysisLayerInfo(id);

            if (info != null) {
                String gid = info[0];
                String filename = info[1];
                String name = info[2];
                Grid grid = new Grid(filename);

                if (grid != null && (new File(filename + ".grd").exists())) {
                    float[] v = grid.getValues(p);
                    if (v != null) {
                        Map m = new HashMap();
                        m.put("field", id);
                        m.put("layername", name + "(" + gid + ")");
                        if (Float.isNaN(v[0])) {
                            m.put("value", "");
                        } else {
                            m.put("value", (Float.isNaN(v[0]) ? "" : v[0]));
                        }

                        out.add(m);
                    }
                }
            }
        }
    }

    return out;
}

From source file:dk.dma.ais.abnormal.analyzer.analysis.CloseEncounterAnalysis.java

void analyseCloseEncounter(Track track1, Track track2) {
    if (track1.getSpeedOverGround() > sogMin && !isTrackPairAnalyzed(track1, track2)) {

        final long t = max(track1.getTimeOfLastPositionReport(), track2.getTimeOfLastPositionReport());

        if (t > track1.getTimeOfLastPositionReport()) {
            track1.predict(t);/*from www.  j a v a2 s . c  om*/
        }
        if (t > track2.getTimeOfLastPositionReport()) {
            track2.predict(t);
        }

        if (isLastAisTrackingReportTooOld(track1, t)) {
            LOG.debug("Skipping analysis: MMSI " + track1.getMmsi() + " was predicted for too long.");
            return;
        }
        if (isLastAisTrackingReportTooOld(track2, t)) {
            LOG.debug("Skipping analysis: MMSI " + track2.getMmsi() + " was predicted for too long.");
            return;
        }

        boolean allValuesPresent = false;
        float track1Cog = Float.NaN, track1Sog = Float.NaN, track2Hdg = Float.NaN;
        int track1Loa = -1, track1Beam = -1, track1Stern = -1, track1Starboard = -1, track2Loa = -1,
                track2Beam = -1, track2Stern = -1, track2Starboard = -1;
        try {
            track1Cog = track1.getCourseOverGround();
            track1Sog = track1.getSpeedOverGround();
            track1Loa = track1.getVesselLength();
            track1Beam = track1.getVesselBeam();
            track1Stern = track1.getShipDimensionStern();
            track1Starboard = track1.getShipDimensionStarboard();
            track2Hdg = track2.getTrueHeading();
            track2Loa = track2.getVesselLength();
            track2Beam = track2.getVesselBeam();
            track2Stern = track2.getShipDimensionStern();
            track2Starboard = track2.getShipDimensionStarboard();
            allValuesPresent = true;
        } catch (NullPointerException e) {
        }

        if (allValuesPresent && !Float.isNaN(track1Cog) && !Float.isNaN(track2Hdg)) {
            Ellipse safetyEllipseTrack1 = safetyZone(track1.getPosition(), track1.getPosition(), track1Cog,
                    track1Sog, track1Loa, track1Beam, track1Stern, track1Starboard);
            Ellipse extentTrack2 = vesselExtent(track1.getPosition(), track2.getPosition(), track2Hdg,
                    track2Loa, track2Beam, track2Stern, track2Starboard);

            if (safetyEllipseTrack1 != null && extentTrack2 != null
                    && safetyEllipseTrack1.intersects(extentTrack2)) {
                track1.setProperty(Track.SAFETY_ZONE, safetyEllipseTrack1);
                track2.setProperty(Track.EXTENT, extentTrack2);
                raiseOrMaintainAbnormalEvent(CloseEncounterEvent.class, track1, track2);
            } else {
                lowerExistingAbnormalEventIfExists(CloseEncounterEvent.class, track1);
            }
        }

        markTrackPairAnalyzed(track1, track2);
    } else {
        LOG.debug("PREVIOUSLY COMPARED " + track1.getMmsi() + " AGAINST " + track2.getMmsi());
    }
}

From source file:ExposedFloat.java

public boolean action(Event evt, Object arg) {

    if (evt.target instanceof Button) {
        String bname = (String) arg;
        if (bname.equals(incrementButtonString)) {

            ++value;/*w w  w. j  a  v  a2 s  .c o m*/
        } else if (bname.equals(decrementButtonString)) {

            --value;
        } else if (bname.equals(multByZeroButtonString)) {

            value *= (float) 0.0;
        } else if (bname.equals(piButtonString)) {

            value = (float) Math.PI;
        } else if (bname.equals(positiveInfinityButtonString)) {

            value = Float.POSITIVE_INFINITY;
        } else if (bname.equals(negativeInfinityButtonString)) {

            value = Float.NEGATIVE_INFINITY;
        } else if (bname.equals(maximumButtonString)) {

            value = Float.MAX_VALUE;
        } else if (bname.equals(minimumButtonString)) {

            value = Float.MIN_VALUE;
        } else if (bname.equals(notANumberButtonString)) {

            value = Float.NaN;
        } else if (bname.equals(changeSignButtonString)) {

            value *= -1.0;
        } else if (bname.equals(doubleButtonString)) {

            value *= 2.0;
        } else if (bname.equals(halveButtonString)) {

            value /= 2.0;
        }
        updateNumberFields();
        enableDisableButton(maximumButton, Float.MAX_VALUE);
        enableDisableButton(minimumButton, Float.MIN_VALUE);
        enableDisableButton(positiveInfinityButton, Float.POSITIVE_INFINITY);
        enableDisableButton(negativeInfinityButton, Float.NEGATIVE_INFINITY);
        enableDisableButton(piButton, (float) Math.PI);
        enableDisableButton(notANumberButton, Float.NaN);
        if (!notANumberButton.isEnabled()) {
            if (!Float.isNaN(value)) {
                notANumberButton.enable();
            }
        } else if (Float.isNaN(value)) {
            notANumberButton.disable();
        }
    }
    return true;
}

From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java

private static void writeAttributesFiles(Set<RuleId> rulesIds,
        Map<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> valuesPerRulePerCase, Path outputDir)
        throws IOException {
    for (RuleId ruleId : rulesIds) {
        Path attributesFile = outputDir.resolve("attributes_" + ruleId.toString() + ".csv");

        System.out.println("writing " + attributesFile + "...");

        try (BufferedWriter writer = Files.newBufferedWriter(attributesFile, StandardCharsets.UTF_8)) {
            writer.write("base case");

            Set<HistoDbAttributeId> allAttributeIds = new LinkedHashSet<>();
            for (Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule : valuesPerRulePerCase.values()) {
                Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId);
                if (values != null) {
                    allAttributeIds.addAll(values.keySet());
                }/*from  ww w.j a  v a 2s .  co  m*/
            }

            for (HistoDbAttributeId attributeId : allAttributeIds) {
                writer.write(CSV_SEPARATOR);
                writer.write(attributeId.toString());
            }
            writer.newLine();

            for (Map.Entry<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> e : valuesPerRulePerCase
                    .entrySet()) {
                String baseCaseName = e.getKey();
                Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule = e.getValue();
                writer.write(baseCaseName);

                Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId);
                for (HistoDbAttributeId attributeId : allAttributeIds) {
                    writer.write(CSV_SEPARATOR);
                    Object value = values.get(attributeId);
                    if (value != null && !(value instanceof Float && Float.isNaN((Float) value))) {
                        writer.write(Objects.toString(values.get(attributeId)));
                    }
                }

                writer.newLine();
            }
        }
    }
}