Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

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

Prototype

double NaN

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

Click Source Link

Document

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

Usage

From source file:com.clust4j.algo.preprocess.ImputationTests.java

@Test
public void testMedianImputation() {
    final double[][] d = new double[][] { new double[] { Double.NaN, 1, 2 }, new double[] { 1, Double.NaN, 3 },
            new double[] { 2, 2, 1 } };

    final MedianImputation median = new MedianImputation(
            new MedianImputationPlanner().setSeed(GlobalState.DEFAULT_RANDOM_STATE));

    final double[][] imputed = median.transform(d);
    final double[][] res = new double[][] { new double[] { 1.5, 1, 2 }, new double[] { 1, 1.5, 3 },
            new double[] { 2, 2, 1 } };

    assertTrue(MatUtils.equalsExactly(res, imputed));
    assertTrue(MatUtils.equalsExactly(res, median.copy().transform(d)));
    assertTrue(MatUtils.equalsExactly(res, median.transform(new Array2DRowRealMatrix(d)).getData()));
}

From source file:com.mapr.synth.samplers.GammaSampler.java

@SuppressWarnings("UnusedDeclaration")
public void setScale(double scale) {
    alpha = Double.NaN;
    beta = Double.NaN;/*  w  w w  .  j a  v  a  2s. c o  m*/

    this.scale = scale;
    init();
}

From source file:IBDMUT.Tools.java

public static double[] simpleRegression(double[][] x, double[] y, double[] w) {
    if (useApacheRegression) {
        Tools.exit("Apache Regression should be removed.");
        return Tools.ApacheRegression(x, y);
    } else {//from   w  ww .  ja  v a2  s .co  m
        double[][] transp = new double[x[0].length + 1][x.length];
        for (int i = 0; i < x.length; i++) {
            transp[0][i] = 1.;
        }
        for (int i = 0; i < x.length; i++) {
            //                w[i] = 1.   ;
            for (int j = 0; j < x[0].length; j++) {
                transp[j + 1][i] = x[i][j];
            }
        }
        LinearRegression linReg = new LinearRegression();
        if (linReg.regress(y, transp, w)) {
            double res[] = new double[3];
            res[0] = linReg.getCoefficients()[0];
            res[1] = linReg.getCoefficients()[1];
            res[2] = linReg.getCorrelationCoefficient();
            return res;
        } else {
            Tools.warning("Linear regression failed due to too few data points or non-invertible matrix");
            return new double[] { Double.NaN, Double.NaN, Double.NaN };
        }
    }
}

From source file:com.intuit.tank.persistence.databases.BucketDataItemTest.java

/**
 * Run the DescriptiveStatistics getStats() method test.
 * // w  w  w .  j  a  v  a  2s  .c om
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/10/14 10:32 AM
 */
@Test
public void testGetStats_1() throws Exception {
    BucketDataItem fixture = new BucketDataItem(1, new Date(), new DescriptiveStatistics());

    DescriptiveStatistics result = fixture.getStats();

    assertNotNull(result);
    assertEquals(
            "DescriptiveStatistics:\nn: 0\nmin: NaN\nmax: NaN\nmean: NaN\nstd dev: NaN\nmedian: NaN\nskewness: NaN\nkurtosis: NaN\n",
            result.toString());
    assertEquals(Double.NaN, result.getMax(), 1.0);
    assertEquals(Double.NaN, result.getVariance(), 1.0);
    assertEquals(Double.NaN, result.getMean(), 1.0);
    assertEquals(-1, result.getWindowSize());
    assertEquals(0.0, result.getSumsq(), 1.0);
    assertEquals(Double.NaN, result.getKurtosis(), 1.0);
    assertEquals(0.0, result.getSum(), 1.0);
    assertEquals(Double.NaN, result.getSkewness(), 1.0);
    assertEquals(Double.NaN, result.getPopulationVariance(), 1.0);
    assertEquals(Double.NaN, result.getStandardDeviation(), 1.0);
    assertEquals(Double.NaN, result.getGeometricMean(), 1.0);
    assertEquals(0L, result.getN());
    assertEquals(Double.NaN, result.getMin(), 1.0);
}

From source file:MathFunc.java

/**
 * Returns the arc tangent of an angle, in the range of <code>-Math.PI/2</code>
 * through <code>Math.PI/2</code>.  Special cases:
 * <ul>/*www  . j  a  v  a2 s  .c o m*/
 *  <li>If the argument is <code>NaN</code>, then the result is <code>NaN</code>.
 *  <li>If the argument is zero, then the result is a zero with the same 
 *      sign as the argument.
 * </ul>
 * <p>
 * A result must be within 1 ulp of the correctly rounded result.  Results
 * must be semi-monotonic.
 * 
 * @param a - the value whose arc tangent is to be returned. 
 * @return the arc tangent of the argument.
 */
public static double atan(double a) {
    // Special cases.
    if (Double.isNaN(a)) {
        return Double.NaN;
    }

    if (a == 0.0) {
        return a;
    }

    // Compute the arc tangent.
    boolean negative = false;
    boolean greaterThanOne = false;
    int i = 0;

    if (a < 0.0) {
        a = -a;
        negative = true;
    }

    if (a > 1.0) {
        a = 1.0 / a;
        greaterThanOne = true;
    }

    double t;

    for (; a > PIover12; a *= t) {
        i++;
        t = a + ATAN_CONSTANT;
        t = 1.0 / t;
        a *= ATAN_CONSTANT;
        a--;
    }

    double aSquared = a * a;

    double arcTangent = aSquared + 1.4087812;
    arcTangent = 0.55913709 / arcTangent;
    arcTangent += 0.60310578999999997;
    arcTangent -= 0.051604539999999997 * aSquared;
    arcTangent *= a;

    for (; i > 0; i--) {
        arcTangent += PIover6;
    }

    if (greaterThanOne) {
        arcTangent = PIover2 - arcTangent;
    }

    if (negative) {
        arcTangent = -arcTangent;
    }

    return arcTangent;
}

From source file:net.aksingh.owmjapis.AbstractForecast.java

/**
 * @return <code>true</code> if message is available, otherwise <code>false</code>.
 *//*ww  w. ja  v  a 2 s . c  om*/
public boolean hasMessage() {
    return (this.message != Double.NaN);
}

From source file:org.envirocar.tools.TrackToCSV.java

public InputStream convert(InputStream in) throws IOException {
    FeatureCollection fc = new ObjectMapper().readValue(in, FeatureCollection.class);

    List<String> properties = new ArrayList<String>();

    for (Feature feature : fc.getFeatures()) {
        for (String key : feature.getProperties().getPhenomenons().keySet()) {
            if (!properties.contains(key)) {
                properties.add(key);//  www .  ja v a  2  s.c o m
            }
        }
    }

    List<String> spaceTimeProperties = new ArrayList<String>();
    spaceTimeProperties.add("longitude");
    spaceTimeProperties.add("latitude");
    spaceTimeProperties.add("time");

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

    bw.append(createCSVHeader(properties, spaceTimeProperties));
    bw.newLine();

    for (Feature feature : fc.getFeatures()) {
        for (int i = 0; i < properties.size(); i++) {
            String key = properties.get(i);
            Map<?, ?> value = (Map<?, ?>) feature.getProperties().getPhenomenons().get(key);
            bw.append(value != null ? value.get("value").toString() : Double.toString(Double.NaN));
            bw.append(delimiter);
        }

        Point coord = (Point) feature.getGeometry();
        bw.append(Double.toString(coord.getCoordinates().getLongitude()));
        bw.append(delimiter);
        bw.append(Double.toString(coord.getCoordinates().getLatitude()));
        bw.append(delimiter);
        bw.append(feature.getProperties().getTime());

        bw.newLine();
    }

    bw.flush();
    bw.close();

    return new ByteArrayInputStream(out.toByteArray());
}

From source file:cfa.vo.sherpa.SherpaClient.java

public FitResults fit(Data dataset, CompositeModel model, Stat stat, Method method) throws Exception {

    String sherpaPublicId = findSherpa();

    //        if (sherpaPublicId == null) {
    //            findSherpa();
    if (sherpaPublicId == null) {
        throw new Exception("Sherpa is not connected to the hub?");
    }//from w  w w .j  av  a  2  s.  c o  m
    //        }

    FitConfiguration fc = (FitConfiguration) SAMPFactory.get(FitConfiguration.class);

    if (dataset.getStaterror() == null) {
        int len = dataset.getX().length;
        double[] staterr = new double[len];
        for (int i = 0; i < dataset.getX().length; i++) {
            staterr[i] = Double.NaN;
        }
        dataset.setStaterror(staterr);
    }

    if (dataset.getSyserror() == null) {
        int len = dataset.getX().length;
        double[] syserr = new double[len];
        for (int i = 0; i < dataset.getX().length; i++) {
            syserr[i] = Double.NaN;
        }
        dataset.setSyserror(syserr);
    }

    fc.addDataset(dataset);
    fc.addModel(model);
    fc.setStat(stat);
    fc.setMethod(method);

    SAMPMessage message = SAMPFactory.createMessage("spectrum.fit.fit", fc, FitConfiguration.class);
    Response response = sampController.callAndWait(sherpaPublicId, message.get(), 10);

    return (FitResults) SAMPFactory.get(response.getResult(), FitResults.class);
}

From source file:com.streamsets.pipeline.stage.it.AvroToParquetHiveIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] {
            // Primitive types
            { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" },
            { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" },
            { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" },
            // From some reason type is FLOAT, but returned object is double
            { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" },
            { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" },
            { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }),
                    new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" },
            { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" },

            // Complex types are skipped for now

            // Logical types
            { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL",
                    Types.DECIMAL, "0" },
            { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, });
}

From source file:fr.ens.transcriptome.teolenn.util.MathUtils.java

/**
 * Calc the median of an array of double
 * @param data Data/*from  w w w .  ja v  a  2 s .  c  om*/
 * @param noNaN true if NaN value must be removed from the computation
 * @return the median or NaN if the data is null
 */
public static double median(final double[] data, final boolean noNaN) {

    if (data == null)
        return Double.NaN;

    Median median = new Median();
    return median.evaluate(noNaN ? removeNaN(data) : data);
}