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:uk.ac.diamond.scisoft.ncd.core.DegreeOfOrientation.java

public Object[] process(Serializable buffer, Serializable axis, final int[] dimensions) {

    double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class);
    float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class);

    int size = dimensions[dimensions.length - 1];
    double[] myaxis = new double[size];
    double[] mydata = new double[size];
    double[] cos2data = new double[size];
    double[] sin2data = new double[size];
    double[] sincosdata = new double[size];

    for (int i = 0; i < parentaxis.length; i++) {
        myaxis[i] = Math.toRadians(parentaxis[i]);
        mydata[i] = parentdata[i];//from   ww  w.  j  av a2s .c  om
        float cos2alpha = (float) Math.cos(2.0 * myaxis[i]);
        float sin2alpha = (float) Math.sin(2.0 * myaxis[i]);
        cos2data[i] = (1.0f + cos2alpha) * parentdata[i] / 2.0;
        sin2data[i] = (1.0f - cos2alpha) * parentdata[i] / 2.0;
        sincosdata[i] = sin2alpha * parentdata[i] / 2.0;
    }

    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(myaxis, mydata);
    UnivariateFunction cos2Function = interpolator.interpolate(myaxis, cos2data);
    UnivariateFunction sin2Function = interpolator.interpolate(myaxis, sin2data);
    UnivariateFunction sincosFunction = interpolator.interpolate(myaxis, sincosdata);

    UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15,
            BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY,
            BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY);

    try {
        float cos2mean = (float) integrator.integrate(INTEGRATION_POINTS, cos2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sin2mean = (float) integrator.integrate(INTEGRATION_POINTS, sin2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sincosmean = (float) integrator.integrate(INTEGRATION_POINTS, sincosFunction, myaxis[0],
                myaxis[myaxis.length - 1]);
        float norm = (float) integrator.integrate(INTEGRATION_POINTS, function, myaxis[0],
                myaxis[myaxis.length - 1]);

        cos2mean /= norm;
        sin2mean /= norm;
        sincosmean /= norm;

        float result = (float) Math.sqrt(Math.pow(cos2mean - sin2mean, 2) - 4.0 * sincosmean * sincosmean);
        double angle = MathUtils.normalizeAngle(Math.atan2(2.0 * sincosmean, cos2mean - sin2mean) / 2.0,
                Math.PI);

        Object[] output = new Object[] { new float[] { result }, new float[] { (float) Math.toDegrees(angle) },
                new float[] { (float) (result * Math.cos(angle)), (float) (result * Math.sin(angle)) }, };

        return output;

    } catch (TooManyEvaluationsException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    } catch (MaxCountExceededException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    }
}

From source file:uk.ac.diamond.scisoft.ncd.core.SaxsInvariant.java

public Object[] process(Serializable buffer, Serializable errors, Serializable axis, final int[] dimensions) {

    double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class);
    float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class);
    double[] parenterrors = (double[]) ConvertUtils.convert(errors, double[].class);

    int shift = (parentaxis[0] > 0 ? 1 : 0);
    int size = dimensions[dimensions.length - 1] + shift;
    double[] myaxis = new double[size];
    double[] mydata = new double[size];
    double[] myerrors = new double[size];

    if (shift > 0) {
        myaxis[0] = 0.0;/*from   ww  w.  java 2  s  . c  o  m*/
        mydata[0] = 0.0;
        myerrors[0] = 0.0;
    }

    for (int i = 0; i < parentaxis.length; i++) {
        myaxis[i + shift] = parentaxis[i];
        mydata[i + shift] = parentdata[i] * parentaxis[i] * parentaxis[i];
        myerrors[i + shift] = parenterrors[i] * Math.pow(parentaxis[i], 4);
    }

    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(myaxis, mydata);

    UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15,
            BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY,
            BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY);

    try {
        float result = (float) integrator.integrate(INTEGRATION_POINTS, function, 0.0,
                myaxis[myaxis.length - 1]);

        IDataset data = new FloatDataset(parentdata, dimensions);
        IDataset qaxis = new DoubleDataset(parentaxis, dimensions);
        PorodPlotData porodPlotData = (PorodPlotData) SaxsAnalysisPlotType.POROD_PLOT.getSaxsPlotDataObject();
        SimpleRegression regression = porodPlotData.getPorodPlotParameters(data.squeeze(), qaxis.squeeze());
        Amount<Dimensionless> c4 = porodPlotData.getC4(regression);

        result += (float) (c4.getEstimatedValue() / myaxis[myaxis.length - 1]);

        double error = 0.0;
        for (int i = 0; i < myaxis.length; i++) {
            int idx1 = Math.max(0, i - 1);
            int idx2 = Math.min(myaxis.length - 1, i + 1);
            error += Math.pow((myaxis[idx2] - myaxis[idx1]), 2) * myerrors[i] / 4.0;
        }
        error += Math.pow(c4.getAbsoluteError() / myaxis[myaxis.length - 1], 2);

        return new Object[] { new float[] { result }, new double[] { error } };
    } catch (TooManyEvaluationsException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    } catch (MaxCountExceededException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    }
}

From source file:com.tussle.collision.Rectangle.java

public double getAspectRatio() {
    return (height == 0) ? Float.NaN : width / height;
}

From source file:com.choicemaker.cm.modelmaker.gui.panels.AsymmetricThresholdVsAccuracyPlotPanel.java

private void display() {
    dirty = false;// w ww .ja  v a 2s.co m
    if (parent.isEvaluated()) {
        reset();
        float[][] ta = parent.getModelMaker().getStatistics().getThresholdVsAccuracy();
        int len = ta.length;
        float lastThr = Float.NaN;
        for (int i = 0; i < len; ++i) {
            float[] p = ta[i];
            float thr = p[0] * 100;
            if (thr != lastThr) {
                lastThr = thr;
                if (thr < 50f) {
                    differPrecision.add(thr, 100 - p[1] * 100);
                    differRecall.add(thr, p[2] * 100);
                } else {
                    matchPrecision.add(thr, 100 - p[3] * 100);
                    matchRecall.add(thr, p[4] * 100);
                }
            }
        }
    }
}

From source file:uk.ac.diamond.scisoft.analysis.io.SRSLoaderTest.java

@Test
public void testLoaderFactory() throws Exception {
    // clear state left over from any previous tests
    LoaderFactory.clear();/*  w w  w  .  j  a v a  2s  .  co m*/
    IDataHolder dh = LoaderFactory.getData("testfiles/gda/analysis/io/SRSLoaderTest/96356.dat", null);
    if (dh == null || dh.getNames().length < 1)
        throw new Exception();
    assertEquals("There is not the correct number of axis in the file", 7, dh.size());
    int dt = AbstractDataset.getDType(dh.getDataset(6));
    if (dt == Dataset.FLOAT32)
        assertEquals("The file does not contain NANs", Float.NaN, dh.getDataset(6).getDouble(1), 10.);
    if (dt == Dataset.FLOAT64)
        assertEquals("The file does not contain NANs", Double.NaN, dh.getDataset(6).getDouble(1), 10.);
    assertEquals("The file does not contain data as well", 0.1, dh.getDataset(0).getDouble(1), 1.);
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPager.java

private void initView(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.UltraViewPager);
    setAutoScroll(ta.getInt(R.styleable.UltraViewPager_upv_autoscroll, 0));
    setInfiniteLoop(ta.getBoolean(R.styleable.UltraViewPager_upv_infiniteloop, false));
    setRatio(ta.getFloat(R.styleable.UltraViewPager_upv_ratio, Float.NaN));
    setScrollMode(ScrollMode.getScrollMode(ta.getInt(R.styleable.UltraViewPager_upv_scrollmode, 0)));
    disableScrollDirection(/*  w w  w  .jav a  2s. c  o m*/
            ScrollDirection.getScrollDirection(ta.getInt(R.styleable.UltraViewPager_upv_disablescroll, 0)));
    setMultiScreen(ta.getFloat(R.styleable.UltraViewPager_upv_multiscreen, 1f));
    setAutoMeasureHeight(ta.getBoolean(R.styleable.UltraViewPager_upv_automeasure, false));
    setItemRatio(ta.getFloat(R.styleable.UltraViewPager_upv_itemratio, Float.NaN));
    ta.recycle();
}

From source file:nz.co.jsrsolutions.tideservice.geocoding.GoogleTideDataGeoCoder.java

@Override
public GeoLocation getGeoLocation(Port port) throws TideDataGeoCoderException {

    URI uri;/* www  .  j ava  2s  .  c  o m*/
    try {

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(port.getName());
        stringBuffer.append(", ");
        stringBuffer.append(port.getSubArea().getName());
        uri = mUriBuilder.buildGetGeoLocUri(stringBuffer.toString());
        HttpUriRequest request = new GoogleGeoCoderHttpGet(uri);
        HttpResponse response = mHttpClient.execute(request);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new TideDataGeoCoderException(
                    "HTTP GET returned: " + response.getStatusLine().getStatusCode());
        }

        // read result and parse into XML Document
        HttpEntity entity = response.getEntity();

        Document geocoderResultDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(entity.getContent());

        // prepare XPath
        XPath xpath = XPathFactory.newInstance().newXPath();

        // extract the result
        NodeList resultNodeList = null;

        // a) Examine the status
        resultNodeList = (NodeList) xpath.evaluate("/GeocodeResponse/status", geocoderResultDocument,
                XPathConstants.NODESET);
        if (resultNodeList.getLength() != 1) {
            throw new TideDataGeoCoderException("Couldn't parse result document.");
        }
        GoogleGeoCoderResultStatus resultStatus = GoogleGeoCoderResultStatus
                .valueOf(resultNodeList.item(0).getTextContent());

        switch (resultStatus) {
        case OK:
            break;
        case ZERO_RESULTS:
            throw new TideDataGeoCoderException("No results found for: " + stringBuffer.toString());
        case OVER_QUERY_LIMIT:
            throw new TideDataGeoCoderException("Over query limit (was 2500 requests per day)");
        case REQUEST_DENIED:
            throw new TideDataGeoCoderException("Request denied (using sensor=true|false ?)");
        case INVALID_REQUEST:
            throw new TideDataGeoCoderException("Invalid request - badly formed query");
        }

        // c) extract the coordinates of the first result
        resultNodeList = (NodeList) xpath.evaluate("/GeocodeResponse/result[1]/geometry/location/*",
                geocoderResultDocument, XPathConstants.NODESET);
        float lat = Float.NaN;
        float lng = Float.NaN;
        for (int i = 0; i < resultNodeList.getLength(); ++i) {
            Node node = resultNodeList.item(i);
            if ("lat".equals(node.getNodeName())) {
                lat = Float.parseFloat(node.getTextContent());
            }
            if ("lng".equals(node.getNodeName())) {
                lng = Float.parseFloat(node.getTextContent());
            }
        }

        GeoLocation geoLocation = new GeoLocation();
        geoLocation.setLatitude((long) (lat * 1e6));
        geoLocation.setLongitude((long) (lng * 1e6));

        return geoLocation;

    } catch (URISyntaxException e) {
        throw new TideDataGeoCoderException(e);
    } catch (ClientProtocolException e) {
        throw new TideDataGeoCoderException(e);
    } catch (IOException e) {
        throw new TideDataGeoCoderException(e);
    } catch (IllegalStateException e) {
        throw new TideDataGeoCoderException(e);
    } catch (SAXException e) {
        throw new TideDataGeoCoderException(e);
    } catch (ParserConfigurationException e) {
        throw new TideDataGeoCoderException(e);
    } catch (XPathExpressionException e) {
        throw new TideDataGeoCoderException(e);
    }

}

From source file:org.caleydo.core.view.opengl.layout2.manage.GLElementFactoryContext.java

public float getFloat(String key) {
    return getFloat(key, Float.NaN);
}

From source file:ec.nbdemetra.ui.chart3d.functions.Functions2DChart.java

/**
 * Generates the data and displays it in the chart. Calculates the points
 * ("steps" total points) and the optimum of the function
 */// w w w . ja v a  2  s .  c  o  m
public void generateData() {
    if (function == null || maxFunction == null) {
        throw new IllegalArgumentException("The given functions can't be null !");
    }

    BasicXYDataset dataset = new BasicXYDataset();
    BasicXYDataset optimumDataset = new BasicXYDataset();
    double[] dataX = new double[steps];
    double[] dataY = new double[steps];

    final IReadDataBlock parameters = maxFunction.getParameters();
    DataBlock p = new DataBlock(parameters);
    final IParametersDomain d = function.getDomain();

    float xMin = ((float) p.get(0) - epsilon);
    double dMin = d.lbound(0);
    if (DescriptiveStatistics.isFinite(dMin) && xMin < dMin)
        xMin = (float) dMin;
    float xMax = ((float) p.get(0) + epsilon);
    double dMax = d.ubound(0);
    if (DescriptiveStatistics.isFinite(dMax) && xMax > dMax)
        xMax = (float) dMax;
    float stepX = (xMax - xMin) / (steps - 1); // Calculates the "distance" between each point

    // Optimum point of the max likelihood function
    double optiX = parameters.get(0);
    double optiY = maxFunction.getValue();

    for (int i = 0; i < steps; i++) {
        // Value on the x axis (min X value + index* (distance between points)
        float x = xMin + i * stepX;
        float y = Float.NaN;
        p.set(0, x); // Setting new value of the 1st param (X)

        // Calculating the Y value
        try {
            if (d.checkBoundaries(p)) {
                y = (float) function.evaluate(p).getValue();
            }
        } catch (Exception err) {
            y = Float.NaN;
        }

        if (Float.isInfinite(y)) {
            y = Float.NaN;
        }

        dataX[i] = x;
        dataY[i] = y;
    }

    // Creates the 2 datasets (function + optimum point)
    BasicXYDataset.Series serie = BasicXYDataset.Series.of("f(" + d.getDescription(0) + ")", dataX, dataY);
    BasicXYDataset.Series optimum = BasicXYDataset.Series.of("Optimum", new double[] { optiX },
            new double[] { optiY });
    dataset.addSeries(serie);
    optimumDataset.addSeries(optimum);

    XYPlot plot = chart.getXYPlot();
    configureAxis(plot);
    plot.setDataset(0, dataset);
    plot.setDataset(1, optimumDataset);

    panel.setChart(chart);
    add(panel, BorderLayout.CENTER);

    onColorSchemeChange();
}

From source file:org.fhcrc.cpl.viewer.mrm.Utils.java

public static float[][] PDStoArray(PlotDataSupplier pds) {
    float retval[][] = null;
    if (pds == null)
        return retval;
    XYSeries xys = pds.getGraphData();// w  w  w  .  jav  a 2s. c o m
    int itemCount = xys.getItemCount();
    retval = new float[2][itemCount];
    for (int i = 0; i < itemCount; i++) {
        retval[0][i] = xys.getX(i).floatValue();
        Number y = xys.getY(i);
        if (y != null) {
            retval[1][i] = y.floatValue();
        } else {
            retval[1][i] = Float.NaN;
        }
    }
    return retval;
}