Example usage for java.lang Float isInfinite

List of usage examples for java.lang Float isInfinite

Introduction

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

Prototype

public static boolean isInfinite(float v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.ranking.MutualInformationBased.java

@Override
public List<Split> rank(List<Split> splits) {
    for (Split split : splits) {
        split.setWeight(this.calcRank(split));
    }//from   ww w  .  j a v  a 2s .  co  m

    List<Split> filtered = new ArrayList<Split>();
    for (Split split : splits) {
        if (!(Float.isInfinite(split.getWeight()) || Float.isNaN(split.getWeight()))) {
            filtered.add(split);
        }
    }

    if (filtered.size() == 0) {
        filtered = splits;
    }

    Collections.sort(filtered);
    return filtered;
}

From source file:FloatSpring.java

/**
 * Update the position of the spring. This updates the "position" as if there
 * were a damped spring stretched between the current position and the target
 * position. That is, the spring will tend to pull the position towards the
 * target, and if the spring is damped the position will eventually settle
 * onto the target./*from   w ww. j  av  a  2 s .  c om*/
 * 
 * @param target
 *          The target towards which the spring is pulling the position
 * @param time
 *          The elapsed time in seconds
 */
public void update(float target, float time) {

    // Set v to target - position, this is the required movement
    float v = position - target;

    // Multiply displacement by spring constant to get spring force,
    // then subtract damping force
    v = v * -springK - velocity * dampingK;

    // v is now a force, so assuming unit mass is is also acceleration.
    // multiply by elapsed time to get velocity change
    velocity += v * time;

    // If velocity isn't valid, zero it
    if (Float.isNaN(velocity) || Float.isInfinite(velocity)) {
        velocity = 0;
    }

    // Change the position at the new velocity, for elapsed time
    position += velocity * time;
}

From source file:hivemall.regression.PassiveAggressiveRegressionUDTF.java

@Override
protected void train(@Nonnull final FeatureValue[] features, float target) {
    preTrain(target);//from  w  w  w. jav a2s  . c  o m

    PredictionResult margin = calcScoreAndNorm(features);
    float predicted = margin.getScore();
    float loss = loss(target, predicted);

    if (loss > 0.f) {
        int sign = (target - predicted) > 0.f ? 1 : -1; // sign(y - (W^t)x)
        float eta = eta(loss, margin); // min(C, loss / |x|^2)
        float coeff = sign * eta;
        if (!Float.isInfinite(coeff)) {
            onlineUpdate(features, coeff);
        }
    }
}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
    try {//from  ww  w.  j  a v a 2s. co m
        final Picture picture = new Picture();
        handler.setPicture(picture);

        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(handler);
        xr.setFeature("http://xml.org/sax/features/validation", false);
        if (DISALLOW_DOCTYPE_DECL) {
            try {
                xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                DISALLOW_DOCTYPE_DECL = false;
            }
        }
        xr.parse(data);

        SVG result = new SVG(picture, handler.bounds);
        // Skip bounds if it was an empty pic
        if (!Float.isInfinite(handler.limits.top)) {
            result.setLimits(handler.limits);
        }
        return result;
    } catch (Exception e) {
        Log.e(TAG, "Failed to parse SVG.", e);
        throw new SVGParseException(e);
    }
}

From source file:Main.java

/**
 * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>, ignoring any instances of <tt>noDataValue</tt>
 * ./*from w ww . j ava2s .c o  m*/
 * 
 * @param multi
 * @param noDataValue
 * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
 */
public static float[] minMax(float[][] multi, float noDataValue) {
    float[] ret = null;
    float min = Float.POSITIVE_INFINITY, max = Float.NEGATIVE_INFINITY;
    float val;
    for (int i = 0; i < multi.length; i++) {
        for (int j = 0; j < multi[i].length; j++) {
            val = multi[i][j];
            if (val != noDataValue) {
                min = (val < min) ? val : min;
                max = (val > max) ? val : max;
            }
        }
    }
    if (!Float.isInfinite(min) & !Float.isInfinite(max)) {
        ret = new float[] { min, max };
    }

    return ret;
}

From source file:io.github.dsheirer.spectrum.SpectrumPanel.java

/**
 * DFTResultsListener interface for receiving the processed data
 * to display//from  w w w  .  j a  v a 2 s .  c  om
 */
public void receive(float[] currentFFTBins) {
    //Prevent arrays of NaN values from being rendered.  The first few
    //DFT result sets on startup will contain NaN values
    if (Float.isInfinite(currentFFTBins[0]) || Float.isNaN(currentFFTBins[0])) {
        currentFFTBins = new float[currentFFTBins.length];
    }

    //Construct and/or resize our DFT results variables
    if (mDisplayFFTBins == null || mDisplayFFTBins.length != currentFFTBins.length) {
        mDisplayFFTBins = currentFFTBins;
    }

    //Apply smoothing across the bins of the DFT results
    float[] smoothedBins = mSmoothingFilter.filter(currentFFTBins);

    //Apply averaging over multiple DFT output frames
    if (mAveraging > 1) {
        float gain = 1.0f / (float) mAveraging;

        for (int x = 0; x < mDisplayFFTBins.length; x++) {
            mDisplayFFTBins[x] += (smoothedBins[x] - mDisplayFFTBins[x]) * gain;
        }
    } else {
        mDisplayFFTBins = smoothedBins;
    }

    repaint();
}

From source file:org.broad.igv.tools.ListAccumulator.java

private void computePercentiles() {
    if (values != null) {
        double[] valueArray = values.toArray();
        for (WindowFunction wf : quantileFunctions) {
            double p = this.getPercentile(wf);
            if (p > 0) {
                float v = (float) StatUtils.percentile(valueArray, p);
                if (Float.isInfinite(v)) {
                    log.error("Infinite percentile (" + wf + ")");
                } else {
                    List<PercentileValue> pList = percentiles.get(wf);
                    if (pList == null) {
                        pList = new ArrayList();
                        percentiles.put(wf, pList);
                    }/*from   w  w  w  .  j  a v a 2s  .c  o m*/
                    pList.add(new PercentileValue(valueArray.length, v));
                }
            }
        }
    }

}

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
 *///from   w  w  w. java2s  . 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.broad.igv.tdf.Accumulator.java

private void computePercentiles() {
    if (values != null) {
        double[] valueArray = values.toArray();
        double p = this.getPercentile(windowFunction);
        if (p > 0) {
            float v = (float) StatUtils.percentile(valueArray, p);
            if (Float.isInfinite(v)) {
                log.error("Infinite percentile (" + windowFunction + ")");
            } else {
                percentiles.add(new PercentileValue(valueArray.length, v));
            }/*  www  . jav  a2  s.c  o  m*/
        }
    }

}

From source file:org.broad.igv.Accumulator.java

private void computePercentiles() {
    if (values != null) {
        double[] valueArray = values.toArray();
        for (WindowFunction wf : quantileFunctions) {
            double p = this.getPercentile(wf);
            if (p > 0) {
                float v = (float) percentile.evaluate(valueArray, p);
                //                    float v = (float) StatUtils.percentile(valueArray, p);
                if (Float.isInfinite(v)) {
                    log.log(Level.SEVERE, "Infinite percentile (" + wf + ")");
                } else {
                    List<PercentileValue> pList = percentiles.get(wf);
                    if (pList == null) {
                        pList = new ArrayList();
                        percentiles.put(wf, pList);
                    }/*from w w  w  . j a  v  a  2 s.  com*/
                    pList.add(new PercentileValue(valueArray.length, v));
                }
            }
        }
    }

}