List of usage examples for java.lang Double NaN
double NaN
To view the source code for java.lang Double NaN.
Click Source Link
From source file:jasima.core.statistics.SummaryStat.java
/** * Returns the sum of all {@link #value(double)}s (taking into account * potential weights if {@link #value(double, double)} is used). * // w ww . ja v a2 s . c o m * @return The sum of all values. */ public double sum() { if (numObs < 1) return Double.NaN; return meanEst * weightSum; }
From source file:edu.brown.utils.MathUtil.java
/** * Compute standard deviation Derived from * http://nscraps.com/Java/720-java-calculate-standard-deviation.htm * @param data/* w w w.jav a 2 s.c o m*/ * @return */ public static final double stdev(double... data) { if (data.length < 2) { return Double.NaN; } double mean = MathUtil.arithmeticMean(data); double sum = 0; for (double d : data) { sum += Math.pow((d - mean), 2); } // FOR return Math.sqrt(sum / (data.length - 1)); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.VehicleStatusTestCase.java
@Test public void testCase04() throws ParseException { String status = "{\"vehicle.id\":\"532d463b-6836-487c-989d-47c59285c17d\",\"state\":\"completed\",\"latitude\":57.8226984,\"longitude\":15.04211393,\"altitude\":5.0," + "\"tolerance\":52.0,\"actions\":\"temperature,photo\"}"; JSONParser parser = new JSONParser(); VehicleStatus s = new VehicleStatus((JSONObject) parser.parse(status)); Assert.assertEquals("532d463b-6836-487c-989d-47c59285c17d", s.getId()); Assert.assertEquals("completed", s.getState().toString().toLowerCase()); // Assert.assertEquals(57.8226984, s.getPosition().getLatitude(), 1E-9); // Assert.assertEquals(15.04211393, s.getPosition().getLongitude(), 1E-9); // Assert.assertEquals(5.0, s.getPosition().getAltitude(), 1E-9); Assert.assertEquals(Double.NaN, s.getTolerance(), 1E-9); Assert.assertNull(s.getPosition());//from w ww. ja v a2s . co m // Assert.assertNull(s.getTolerance()); // Assert.assertArrayEquals(new String[]{"temperature","photo"}, s.getActions()); Assert.assertNull(s.getActions()); s = new VehicleStatus((JSONObject) parser.parse(s.toJSONString())); Assert.assertEquals("532d463b-6836-487c-989d-47c59285c17d", s.getId()); Assert.assertEquals("completed", s.getState().toString().toLowerCase()); // Assert.assertEquals(57.8226984, s.getPosition().getLatitude(), 1E-9); // Assert.assertEquals(15.04211393, s.getPosition().getLongitude(), 1E-9); // Assert.assertEquals(5.0, s.getPosition().getAltitude(), 1E-9); // Assert.assertEquals(52.0, s.getTolerance(), 1E-9); // Assert.assertArrayEquals(new String[]{"temperature","photo"}, s.getActions()); Assert.assertEquals(Double.NaN, s.getTolerance(), 1E-9); Assert.assertNull(s.getPosition()); Assert.assertNull(s.getActions()); }
From source file:org.jfree.data.jdbc.JDBCPieDataset.java
/** * ExecuteQuery will attempt execute the query passed to it against the * existing database connection. If no connection exists then no action * is taken.//from w ww . j a v a 2 s.c o m * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed * @param con the connection the query is to be executed against * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { Statement statement = null; ResultSet resultSet = null; try { statement = con.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != 2) { throw new SQLException("Invalid sql generated. PieDataSet requires 2 columns only"); } int columnType = metaData.getColumnType(2); double value = Double.NaN; while (resultSet.next()) { Comparable key = resultSet.getString(1); switch (columnType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: value = resultSet.getDouble(2); setValue(key, value); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Timestamp date = resultSet.getTimestamp(2); value = date.getTime(); setValue(key, value); break; default: System.err.println("JDBCPieDataset - unknown data type"); break; } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } if (statement != null) { try { statement.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } } }
From source file:knop.psfj.FovDataSet.java
/** * Adds the value./*from w ww .j a v a 2s .c o m*/ * * @param column the column * @param value the value */ public synchronized void addValue(String column, double value) { if (value == Double.NaN) getList(column).add(Double.NaN); else getList(column).add(new Double(value)); // getColumnStatistics(column).addValue(value); }
From source file:fantail.algorithms.BinaryART.java
private void makeTree(Instances data, java.util.Random r, int depth) throws Exception { if (m_K > data.numAttributes()) { m_K = data.numAttributes() - 1;//from w w w .j av a2 s .c o m } if (m_K < 1) { m_K = (int) weka.core.Utils.log2(data.numAttributes()) + 1; } int[] randAtts = new int[data.numAttributes() - 1]; //TODO: handle class target att for (int i = 0; i < randAtts.length; i++) { randAtts[i] = i; } for (int i = 0; i < randAtts.length; i++) { int randomPosition = r.nextInt(randAtts.length); int temp = randAtts[i]; randAtts[i] = randAtts[randomPosition]; randAtts[randomPosition] = temp; } int bestAttIndex = -1; BinaryART.AttScorePair[] attScorePair = new BinaryART.AttScorePair[m_K]; for (int i = 0; i < m_K; i++) { int attIndex = randAtts[i]; double splitPoint = Double.NaN; if (!m_UseMedian) { splitPoint = data.meanOrMode(attIndex); } else { splitPoint = getMedian(data, attIndex); } double r2 = estimateR2(data, attIndex, splitPoint); attScorePair[i] = new BinaryART.AttScorePair(attIndex, r2); } Arrays.sort(attScorePair); bestAttIndex = attScorePair[0].index; double maxR2 = attScorePair[0].score; boolean stop1 = false; if (attScorePair[0].score <= attScorePair[m_K - 1].score) { stop1 = true; } if (data.numInstances() <= m_MiniLeaf || (depth >= m_MaxDepth && m_MaxDepth != 0) //|| maxR2 <= 0.01 // removed 10/01/2013 || maxR2 >= 0.95 || stop1 // 11/01/13 the paper version doesn't have this || data.variance(bestAttIndex) <= 0) { m_Attribute = null; m_Prototype = AbstractRanker.getAvgRanking(data); //m_Prototype = AbstractRanker.getCenterRanking(data, m_ApproxCenterMethod); return; } m_Attribute = data.attribute(bestAttIndex); if (!m_UseMedian) { m_SplitPoint = data.meanOrMode(bestAttIndex); } else { m_SplitPoint = getMedian(data, bestAttIndex); } Instances[] splitData = splitData(data, bestAttIndex, m_SplitPoint); m_Successors = new BinaryART[2]; for (int j = 0; j < 2; j++) { m_Successors[j] = new BinaryART(); m_Successors[j].setMiniLeaf(m_MiniLeaf); m_Successors[j].setK(m_K); m_Successors[j].setUseMedian(m_UseMedian); m_Successors[j].setNumObjects(m_NumObjects); m_Successors[j].makeTree(splitData[j], r, depth + 1); } }
From source file:MathFunc.java
/** * Converts rectangular coordinates (x, y) to polar (r, <i>theta</i>). This method * computes the phase <i>theta</i> by computing an arc tangent of y/x in the range * of <i>-pi</i> to <i>pi</i>. Special cases: * <ul>//from w ww .ja v a2 s . c o m * <li>If either argument is <code>NaN</code>, then the result is <code>NaN</code>. * <li>If the first argument is positive zero and the second argument is * positive, or the first argument is positive and finite and the second * argument is positive infinity, then the result is positive zero. * <li>If the first argument is negative zero and the second argument is * positive, or the first argument is negative and finite and the second * argument is positive infinity, then the result is negative zero. * <li>If the first argument is positive zero and the second argument is * negative, or the first argument is positive and finite and the second * argument is negative infinity, then the result is the <code>double</code> value * closest to <i>pi</i>. * <li>If the first argument is negative zero and the second argument is * negative, or the first argument is negative and finite and the second * argument is negative infinity, then the result is the <code>double</code> value * closest to <i>-pi</i>. * <li>If the first argument is positive and the second argument is positive * zero or negative zero, or the first argument is positive infinity and * the second argument is finite, then the result is the <code>double</code> value * closest to <i>pi</i>/2. * <li>If the first argument is negative and the second argument is positive * zero or negative zero, or the first argument is negative infinity and * the second argument is finite, then the result is the <code>double</code> value * closest to <i>-pi</i>/2. * <li>If both arguments are positive infinity, then the result is the double * value closest to <i>pi</i>/4. * <li>If the first argument is positive infinity and the second argument is * negative infinity, then the result is the double value closest to 3*<i>pi</i>/4. * <li>If the first argument is negative infinity and the second argument is * positive infinity, then the result is the double value closest to -<i>pi</i>/4. * <li>If both arguments are negative infinity, then the result is the double * value closest to -3*<i>pi</i>/4. * </ul> * <p> * A result must be within 2 ulps of the correctly rounded result. Results * must be semi-monotonic. * * @param y - the ordinate coordinate * @param x - the abscissa coordinate * @return the <i>theta</i> component of the point (r, <i>theta</i>) in polar * coordinates that corresponds to the point (x, y) in Cartesian coordinates. */ public static double atan2(double y, double x) { // Special cases. if (Double.isNaN(y) || Double.isNaN(x)) { return Double.NaN; } else if (Double.isInfinite(y)) { if (y > 0.0) // Positive infinity { if (Double.isInfinite(x)) { if (x > 0.0) { return PIover4; } else { return 3.0 * PIover4; } } else if (x != 0.0) { return PIover2; } } else // Negative infinity { if (Double.isInfinite(x)) { if (x > 0.0) { return -PIover4; } else { return -3.0 * PIover4; } } else if (x != 0.0) { return -PIover2; } } } else if (y == 0.0) { if (x > 0.0) { return y; } else if (x < 0.0) { return Math.PI; } } else if (Double.isInfinite(x)) { if (x > 0.0) // Positive infinity { if (y > 0.0) { return 0.0; } else if (y < 0.0) { return -0.0; } } else // Negative infinity { if (y > 0.0) { return Math.PI; } else if (y < 0.0) { return -Math.PI; } } } else if (x == 0.0) { if (y > 0.0) { return PIover2; } else if (y < 0.0) { return -PIover2; } } // Implementation a simple version ported from a PASCAL implementation: // http://everything2.com/index.pl?node_id=1008481 double arcTangent; // Use arctan() avoiding division by zero. if (Math.abs(x) > Math.abs(y)) { arcTangent = atan(y / x); } else { arcTangent = atan(x / y); // -PI/4 <= a <= PI/4 if (arcTangent < 0) { arcTangent = -PIover2 - arcTangent; // a is negative, so we're adding } else { arcTangent = PIover2 - arcTangent; } } // Adjust result to be from [-PI, PI] if (x < 0) { if (y < 0) { arcTangent = arcTangent - Math.PI; } else { arcTangent = arcTangent + Math.PI; } } return arcTangent; }
From source file:com.itemanalysis.psychometrics.rasch.ScoreTable.java
public void computePersonStandardErrors() { double sum = 0.0; RatingScaleItem rsi = null;//from w w w . jav a 2 s . c o m for (int i = 0; i < scoreTable.length; i++) { sum = 0.0; if (extremeScore[i]) stdError[i] = Double.NaN;//FIXME change to actual computation for (VariableName v : items.keySet()) { rsi = items.get(v); if (!rsi.extremeItem()) { sum += rsm.denomInf(scoreTable[i][1], rsi.getDifficulty(), rsi.getThresholds()); } } if (sum == 0.0) { stdError[i] = Double.NaN; } else { stdError[i] = 1 / Math.sqrt(sum); } } }
From source file:eu.eubrazilcc.lvl.service.cache.SequenceGeolocationCache.java
private static String key(final double value) { return value != Double.NaN ? DECIMAL_FORMAT.format(value) : "nan"; }