Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public static boolean isNaN(double v) 

Source Link

Document

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

Usage

From source file:fr.ign.cogit.simplu3d.rjmcmc.trapezoid.optimizer.OptimisedParallelTrapezoidFinalDirectRejection.java

public GraphConfiguration<ParallelTrapezoid2> create_configuration(Parameters p, Geometry geom,
        BasicPropertyUnit bpu) {//from ww w  .j av  a2  s .c om
    // nergie constante :  la cration d'un nouvel objet

    double energyCrea = Double.isNaN(this.energyCreation) ? p.getDouble("energy") : this.energyCreation;

    ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2> energyCreation = new ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2>(
            energyCrea);

    // nergie constante : pondration de l'intersection
    ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2> ponderationVolume = new ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2>(
            p.getDouble("ponderation_volume"));
    // nergie unaire : aire dans la parcelle
    UnaryEnergy<ParallelTrapezoid2> energyVolume = new VolumeUnaryEnergy<ParallelTrapezoid2>();
    // Multiplication de l'nergie d'intersection et de l'aire
    UnaryEnergy<ParallelTrapezoid2> energyVolumePondere = new MultipliesUnaryEnergy<ParallelTrapezoid2>(
            ponderationVolume, energyVolume);

    // On retire de l'nergie de cration, l'nergie de l'aire
    UnaryEnergy<ParallelTrapezoid2> u3 = new MinusUnaryEnergy<ParallelTrapezoid2>(energyCreation,
            energyVolumePondere);

    // nergie constante : pondration de la diffrence
    ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2> ponderationDifference = new ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2>(
            p.getDouble("ponderation_difference_ext"));
    // On ajoute l'nergie de diffrence : la zone en dehors de la parcelle
    UnaryEnergy<ParallelTrapezoid2> u4 = new DifferenceVolumeUnaryEnergy<ParallelTrapezoid2>(geom);
    UnaryEnergy<ParallelTrapezoid2> u5 = new MultipliesUnaryEnergy<ParallelTrapezoid2>(ponderationDifference,
            u4);
    UnaryEnergy<ParallelTrapezoid2> unaryEnergy = new PlusUnaryEnergy<ParallelTrapezoid2>(u3, u5);

    // nergie binaire : intersection entre deux rectangles
    ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2> c3 = new ConstantEnergy<ParallelTrapezoid2, ParallelTrapezoid2>(
            p.getDouble("ponderation_volume_inter"));
    BinaryEnergy<ParallelTrapezoid2, ParallelTrapezoid2> b1 = new IntersectionVolumeBinaryEnergy<ParallelTrapezoid2>();
    BinaryEnergy<ParallelTrapezoid2, ParallelTrapezoid2> binaryEnergy = new MultipliesBinaryEnergy<ParallelTrapezoid2, ParallelTrapezoid2>(
            c3, b1);
    // empty initial configuration*/
    GraphConfiguration<ParallelTrapezoid2> conf = new GraphConfiguration<>(unaryEnergy, binaryEnergy);
    return conf;
}

From source file:com.joptimizer.optimizers.OptimizationRequestHandler.java

/**
 * Objective function value at X./* w w  w. j  a v a  2 s .  c o m*/
 */
protected final boolean isInDomainF0(DoubleMatrix1D X) {
    double F0X = request.getF0().value(X.toArray());
    return !Double.isInfinite(F0X) && !Double.isNaN(F0X);
}

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

@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
    String negativeValue = getParameterAsString(PARAMETER_NEGATIVE_VALUE);
    String positiveValue = getParameterAsString(PARAMETER_POSITIVE_VALUE);

    Set<Attribute> attributes = attributeSelector.getAttributeSubset(exampleSet, false);
    Set<Attribute> remappedAttributes = new HashSet<>();

    for (Attribute attribute : attributes) {
        if (attribute.isNominal()) {
            if (negativeValue.equals(attribute.getMapping().getPositiveString())
                    && positiveValue.equals(attribute.getMapping().getNegativeString())) {
                // create inverse value mapping
                attribute.getMapping().clear();
                attribute.getMapping().mapString(negativeValue);
                attribute.getMapping().mapString(positiveValue);
                remappedAttributes.add(attribute);
            } else if (!negativeValue.equals(attribute.getMapping().getNegativeString())
                    || !positiveValue.equals(attribute.getMapping().getPositiveString())) {
                logWarning("specified values do not match values of attribute " + attribute.getName()
                        + ", attribute is skipped.");
            }//  w ww. ja  va2  s .  c o  m
        }
    }

    for (Attribute attribute : attributes) {
        if (remappedAttributes.contains(attribute)) {
            for (Example example : exampleSet) {
                double value = example.getValue(attribute);
                if (!Double.isNaN(value)) {
                    if (value == BinominalMapping.NEGATIVE_INDEX) {
                        example.setValue(attribute, BinominalMapping.POSITIVE_INDEX);
                    } else if (value == BinominalMapping.POSITIVE_INDEX) {
                        example.setValue(attribute, BinominalMapping.NEGATIVE_INDEX);
                    }
                }
            }
        }
    }

    return exampleSet;
}

From source file:com.revolsys.geometry.model.impl.BoundingBoxDoubleGf.java

public static boolean isEmpty(final double minX, final double maxX) {
    if (Double.isNaN(minX)) {
        return true;
    } else if (Double.isNaN(maxX)) {
        return true;
    } else {//w  w  w  . j a  v  a 2  s .co  m
        return maxX < minX;
    }
}

From source file:org.jfree.data.RangeTest.java

/**
 * Tests the constrain() method for various values.
 *//*  w w w  . j a  v a2s  .c o m*/
@Test
public void testConstrain() {
    Range r1 = new Range(0.0, 1.0);

    double d = r1.constrain(0.5);
    assertEquals(0.5, d, 0.0000001);

    d = r1.constrain(0.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(1.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(-1.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(2.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.POSITIVE_INFINITY);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.NEGATIVE_INFINITY);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(Double.NaN);
    assertTrue(Double.isNaN(d));
}

From source file:etomica.models.co2.PNCO2GCPM.java

public double energy(IMoleculeList atoms) {
    double sum = 0;
    if (component != Component.INDUCTION) {
        for (int i = 0; i < atoms.getMoleculeCount() - 1; i++) {
            pair.atom0 = atoms.getMolecule(i);
            for (int j = i + 1; j < atoms.getMoleculeCount(); j++) {
                pair.atom1 = atoms.getMolecule(j);
                sum += getNonPolarizationEnergy(pair);
                if (Double.isInfinite(sum)) {
                    return sum;
                }//from www.jav a 2s .  co m
            }
        }
    }
    if (component != Component.TWO_BODY) {
        sum += getPolarizationEnergy(atoms);
    }
    if (!oops && Double.isNaN(sum)) {
        oops = true;
        energy(atoms);
        throw new RuntimeException("oops NaN");
    }
    return sum;
}

From source file:com.joptimizer.optimizers.LPPrimalDualMethod.java

public LPPrimalDualMethod(double minLBValue, double maxUBValue) {
    if (Double.isNaN(minLBValue) || Double.isInfinite(minLBValue)) {
        throw new IllegalArgumentException(
                "The field minLBValue must not be set to Double.NaN or Double.NEGATIVE_INFINITY");
    }/* www.  ja v a 2s .  c  om*/
    if (Double.isNaN(maxUBValue) || Double.isInfinite(maxUBValue)) {
        throw new IllegalArgumentException(
                "The field maxUBValue must not be set to Double.NaN or Double.POSITIVE_INFINITY");
    }
    this.minLBValue = minLBValue;
    this.maxUBValue = maxUBValue;
}

From source file:com.nascent.android.glass.glasshackto.greenpfinder.model.GreenPSpots.java

/**
 * Converts a JSON object that represents a place into a {@link Place} object.
 *///from w  w w . j a v  a 2 s . co m
private ParkingLot jsonObjectToParkingLot(JSONObject object) {
    int id = object.optInt("id");
    String name = object.optString("address");
    String rate = object.optString("rate");
    double latitude = object.optDouble("lat", Double.NaN);
    double longitude = object.optDouble("lng", Double.NaN);

    if (!name.isEmpty() && !Double.isNaN(latitude) && !Double.isNaN(longitude)) {
        return new ParkingLot(id, latitude, longitude, name, rate);
    } else {
        return null;
    }
}

From source file:org.tsho.dmc2.core.chart.TrajectoryRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    Stroke stroke = new BasicStroke(7f);
    Stroke origStroke = g2.getStroke();
    Color color = Color.BLACK;

    /* transients */
    if (!continua) {
        stepper.initialize();//from w w w.j  av a  2  s  .  c  o  m

        state = STATE_TRANSIENTS;

        try {
            for (index = 0; index < transients; index++) {
                stepper.step();
                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        index = 0;
        prevX = 0;
        prevY = 0;
    }

    state = STATE_POINTS;

    Stepper.Point2D point;
    double[] fullPoint = new double[dataset.getNcol()];
    dataset.clearRows();
    int x, y;
    int start = index;
    int end = 0;
    if (index == 0) {
        end = start + iterations + 1;
    } else {
        end = start + iterations;
    }

    for (; index < end; index++) {
        point = stepper.getCurrentPoint2D();
        stepper.getCurrentValue(fullPoint);
        try {
            dataset.addRow((double[]) fullPoint.clone());
        } catch (DatasetException e) {
            System.err.println(e);
        }

        if (!timePlot) {
            x = (int) domainAxis.valueToJava2D(point.getX(), dataArea, RectangleEdge.BOTTOM);
        } else {
            x = (int) domainAxis.valueToJava2D(index + transients, dataArea, RectangleEdge.BOTTOM);
        }

        y = (int) rangeAxis.valueToJava2D(point.getY(), dataArea, RectangleEdge.LEFT);

        if (Double.isNaN(point.getX()) || Double.isNaN(point.getY())) {
            System.err.println("NaN values at iteration " + index);
            //FIXME
            //Don't simply throw exception: that would mess up the state machine!
            //throw new RuntimeException("NaN values at iteration " + index);
        }

        if (delay > 0) {
            boolean flag = false;

            try {
                Thread.sleep(delay * 5);

                drawItem(g2, index, x, y);

                g2.setXORMode(color);
                g2.setStroke(stroke);
                g2.drawRect(x - 1, y - 1, 3, 3);

                flag = true;

                Thread.sleep(delay * 5);
            } catch (final InterruptedException e) {
            }

            if (flag) {
                g2.drawRect(x - 1, y - 1, 3, 3);
                g2.setPaintMode();
                g2.setStroke(origStroke);
            } else {
                drawItem(g2, index, x, y);
            }
        } else {
            drawItem(g2, index, x, y);
        }

        try {
            stepper.step();
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }
    }

    state = STATE_FINISHED;
}

From source file:com.rapidminer.operator.preprocessing.GuessValueTypes.java

@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
    // init//from w  w w .j av  a2 s  .c om
    char decimalPointCharacter = getParameterAsString(PARAMETER_DECIMAL_POINT_CHARACTER).charAt(0);
    Character groupingCharacter = null;
    if (isParameterSet(PARAMETER_NUMBER_GROUPING_CHARACTER)) {
        groupingCharacter = getParameterAsString(PARAMETER_NUMBER_GROUPING_CHARACTER).charAt(0);
    }

    Set<Attribute> attributeSet = attributeSelector.getAttributeSubset(exampleSet, false);
    int size = attributeSet.size();

    int[] inputValueTypes = new int[size];

    int index = 0;
    for (Attribute attribute : attributeSet) {
        inputValueTypes[index++] = attribute.getValueType();
    }

    // init progress
    getProgress().setTotal(100);
    double totalProgress = exampleSet.size() * attributeSet.size();
    long progressCounter = 0;

    // guessed value types
    int[] guessedValueTypes = new int[size];
    index = 0;
    for (Attribute attribute : attributeSet) {
        progressCounter = exampleSet.size() * index;
        getProgress().setCompleted((int) (50 * ((progressCounter - 1) / totalProgress)));
        if (!attribute.isNominal() && !attribute.isNumerical()) {
            index++;
            continue;
        }
        for (Example example : exampleSet) {
            // trigger progress
            if (progressCounter++ % 500_000 == 0) {
                getProgress().setCompleted((int) (50 * ((progressCounter - 1) / totalProgress)));
            }
            double originalValue = example.getValue(attribute);
            if (!Double.isNaN(originalValue)) {
                if (guessedValueTypes[index] != Ontology.NOMINAL) {
                    try {
                        String valueString = example.getValueAsString(attribute);
                        if (!Attribute.MISSING_NOMINAL_VALUE.equals(valueString)) {
                            if (groupingCharacter != null) {
                                valueString = valueString.replace(groupingCharacter.toString(), "");
                            }
                            valueString = valueString.replace(decimalPointCharacter, '.');
                            double value = Double.parseDouble(valueString);
                            if (guessedValueTypes[index] != Ontology.REAL) {
                                if (Tools.isEqual(Math.round(value), value)) {
                                    guessedValueTypes[index] = Ontology.INTEGER;
                                } else {
                                    guessedValueTypes[index] = Ontology.REAL;
                                }
                            }
                        }
                    } catch (NumberFormatException e) {
                        guessedValueTypes[index] = Ontology.NOMINAL;
                        break;
                    }
                }
            }
        }
        index++;
    }

    // if we could not guess any type, use the default one
    for (int i = 0; i < size; i++) {
        if (guessedValueTypes[i] == 0) {
            guessedValueTypes[i] = inputValueTypes[i];
        }
    }

    progressCounter = 0;
    getProgress().setCompleted(50);

    // the example set contains at least one example and the guessing was performed
    if (exampleSet.size() > 0) {
        // new attributes
        List<AttributeRole> newAttributes = new LinkedList<AttributeRole>();
        index = 0;
        for (Attribute attribute : attributeSet) {
            if (!attribute.isNominal() && !attribute.isNumerical()) {
                index++;
                continue;
            }

            AttributeRole role = exampleSet.getAttributes().getRole(attribute);

            Attribute newAttribute = AttributeFactory.createAttribute(guessedValueTypes[index]);
            exampleSet.getExampleTable().addAttribute(newAttribute);
            AttributeRole newRole = new AttributeRole(newAttribute);
            newRole.setSpecial(role.getSpecialName());
            newAttributes.add(newRole);

            // copy data
            for (Example e : exampleSet) {
                double oldValue = e.getValue(attribute);
                if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(guessedValueTypes[index], Ontology.NUMERICAL)) {
                    if (!Double.isNaN(oldValue)) {
                        String valueString = e.getValueAsString(attribute);
                        if (Attribute.MISSING_NOMINAL_VALUE.equals(valueString)) {
                            e.setValue(newAttribute, Double.NaN);
                        } else {
                            if (groupingCharacter != null) {
                                valueString = valueString.replace(groupingCharacter.toString(), "");
                            }
                            valueString = valueString.replace(decimalPointCharacter, '.');
                            e.setValue(newAttribute, Double.parseDouble(valueString));
                        }
                    } else {
                        e.setValue(newAttribute, Double.NaN);
                    }
                } else {
                    if (!Double.isNaN(oldValue)) {
                        String value = e.getValueAsString(attribute);
                        e.setValue(newAttribute, newAttribute.getMapping().mapString(value));
                    } else {
                        e.setValue(newAttribute, Double.NaN);
                    }
                }

                // trigger progress
                if (++progressCounter % 500_000 == 0) {
                    getProgress().setCompleted((int) (50 * (progressCounter / totalProgress) + 50));
                }
            }

            exampleSet.getAttributes().remove(role);
            newAttribute.setName(attribute.getName());

            index++;
        }

        for (AttributeRole role : newAttributes) {
            if (role.isSpecial()) {
                exampleSet.getAttributes().setSpecialAttribute(role.getAttribute(), role.getSpecialName());
            } else {
                exampleSet.getAttributes().addRegular(role.getAttribute());
            }
        }

        // trigger progress
        getProgress().complete();
    }

    return exampleSet;
}