Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

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

Usage

From source file:com.cloudera.oryx.als.computation.merge.MergeNewOldValuesFn.java

@Override
public void process(Pair<Pair<Long, Integer>, Iterable<NumericIDValue>> input,
        Emitter<Pair<Long, NumericIDValue>> emitter) {
    Pair<Long, Integer> key = input.first();
    long currentUserID = key.first();

    if (key.second() == BEFORE) {

        // Last old data had no match, just output it
        if (previousUserPrefs != null) {
            Preconditions.checkNotNull(previousUserID);
            output(previousUserID, previousUserPrefs, null, null, emitter);
            previousUserPrefs = null;/*from w w  w  .j a  va  2 s . c o  m*/
            previousUserID = null;
        }

        LongFloatMap oldPrefs = new LongFloatMap();
        for (NumericIDValue itemPref : input.second()) {
            float oldPrefValue = itemPref.getValue();
            Preconditions.checkState(!Float.isNaN(oldPrefValue), "No prior pref value?");
            // Apply decay factor here, if applicable:
            oldPrefs.increment(itemPref.getID(), doDecay ? oldPrefValue * decayFactor : oldPrefValue);
        }

        previousUserPrefs = oldPrefs;
        previousUserID = currentUserID;

    } else {
        // Last old data had no match, just output it
        if (previousUserPrefs != null && currentUserID != previousUserID) {
            Preconditions.checkNotNull(previousUserID);
            output(previousUserID, previousUserPrefs, null, null, emitter);
            previousUserPrefs = null;
            previousUserID = null;
        }

        LongFloatMap newPrefs = new LongFloatMap();
        LongSet removedItemIDs = new LongSet();
        for (NumericIDValue itemPref : input.second()) {
            long itemID = itemPref.getID();
            float newPrefValue = itemPref.getValue();
            if (Float.isNaN(newPrefValue)) {
                removedItemIDs.add(itemID);
            } else {
                newPrefs.increment(itemID, newPrefValue);
            }
        }

        output(currentUserID, previousUserPrefs, newPrefs, removedItemIDs, emitter);

        previousUserPrefs = null;
        previousUserID = null;
    }
}

From source file:juicebox.matrix.InMemoryMatrix.java

private void computeBounds() {
    DoubleArrayList tmpList = new DoubleArrayList(data.length);
    for (float datum : data) {
        if (!Float.isNaN(datum))
            tmpList.add(datum);/*from   w ww . j  a  v a 2s  .  c  om*/
    }
    double[] tmp = tmpList.toArray();
    lowerValue = (float) StatUtils.percentile(tmp, 5);
    upperValue = (float) StatUtils.percentile(tmp, 95);
}

From source file:model.experiments.WhenDoesAveragingMatters.java

public static void learnedRun(int competitors, Class<? extends AskPricingStrategy> pricing,
        int weightedAverageSize) {

    final MacroII macroII = new MacroII(System.currentTimeMillis());
    final TripolistScenario scenario1 = new TripolistScenario(macroII);
    scenario1.setSalesDepartmentType(SalesDepartmentOneAtATime.class);
    scenario1.setAskPricingStrategy(pricing);
    scenario1.setControlType(MonopolistScenario.MonopolistScenarioIntegratedControlEnum.MARGINAL_PLANT_CONTROL);
    scenario1.setAdditionalCompetitors(competitors);
    scenario1.setWorkersToBeRehiredEveryDay(true);
    scenario1.setDemandIntercept(102);//from  w w w  . ja  v  a  2  s  .c  om

    scenario1.setSalesPricePreditorStrategy(FixedDecreaseSalesPredictor.class);

    //assign scenario
    macroII.setScenario(scenario1);

    macroII.start();

    macroII.schedule.step(macroII);
    for (Firm firm : scenario1.getCompetitors()) {
        for (HumanResources hr : firm.getHRs())
            hr.setPredictor(new FixedIncreasePurchasesPredictor(0));

        final SalesDepartment salesDepartment = firm.getSalesDepartment(UndifferentiatedGoodType.GENERIC);
        salesDepartment.setPriceAverager(new WeightedPriceAverager(weightedAverageSize));
        salesDepartment.setPredictorStrategy(new FixedDecreaseSalesPredictor(0));
    }

    while (macroII.schedule.getTime() < 5000) {
        macroII.schedule.step(macroII);

    }

    SummaryStatistics prices = new SummaryStatistics();
    SummaryStatistics quantities = new SummaryStatistics();
    for (int j = 0; j < 500; j++) {
        macroII.schedule.step(macroII);
        assert !Float.isNaN(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice());
        prices.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayAveragePrice());
        quantities.addValue(macroII.getMarket(UndifferentiatedGoodType.GENERIC).getTodayVolume());

    }

    System.out.println(prices.getMean() + " - " + quantities.getMean() + "----" + macroII.seed() + " | "
            + macroII.getMarket(UndifferentiatedGoodType.GENERIC).getLastDaysAveragePrice());
    System.out.println("standard deviations: price : " + prices.getStandardDeviation() + " , quantity: "
            + quantities.getStandardDeviation());

}

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

public void finish() {

    if (isFinished) {
        return;
    }

    mean = Float.isNaN(sum) ? Float.NaN : sum / nPts;
    isFinished = true;

}

From source file:org.kordamp.ezmorph.primitive.BooleanMorpher.java

/**
 * Morphs the input object into an output object of the supported type.
 *
 * @param value The input value to be morphed
 * @throws MorphException if conversion cannot be performed successfully
 *///from  w w  w  . jav  a 2 s  .c  om
public boolean morph(Object value) {
    if (value == null) {
        if (isUseDefault()) {
            return defaultValue;
        } else {
            throw new MorphException("value is null");
        }
    }

    if (value instanceof Boolean) {
        return ((Boolean) value).booleanValue();
    } else if (value instanceof Number) {
        if (value instanceof Double && (Double.isInfinite(((Number) value).doubleValue())
                || Double.isNaN(((Number) value).doubleValue()))) {
            return true;
        }
        if (value instanceof Float && (Float.isInfinite(((Number) value).floatValue())
                || Float.isNaN(((Number) value).floatValue()))) {
            return true;
        }
        long l = ((Number) value).longValue();
        return l != 0;
    } else {
        String s = String.valueOf(value);

        if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("on")) {
            return true;
        } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("off")) {
            return false;
        } else if (isUseDefault()) {
            return defaultValue;
        }
    }

    throw new MorphException("Can't morph value: " + value);
}

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

public void add(int nBases, float v, String probe) {

    // Some older TDF files created in previous versions of igvtools from wig files were improperly coded,
    // with start=end, resulting in an nBases value of zero.  This is not a possible value, so threshold it
    if (nBases < 1)
        nBases = 1;// w w  w  .  j  a v  a2s  . co  m

    if (!Float.isNaN(v)) {
        if (data != null && nPts < data.length) {
            data[nPts] = v;
            probes[nPts] = probe;
        }
        switch (windowFunction) {
        case min:
            value = Float.isNaN(value) ? v : Math.min(value, v);
            break;
        case max:
            value = Float.isNaN(value) ? v : Math.max(value, v);
            break;
        case mean:
            sum += nBases * v;
            break;
        default:
            if (values != null) {
                values.add(v);
                if (values.size() > MAX_VALUE_COUNT) {
                    computePercentiles();
                    values.clear();
                }
            }
        }
        nPts++;
        basesCovered += nBases;
    }
}

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

public void add(int w, float v) {
    if (!Float.isNaN(v)) {
        min = Float.isNaN(min) ? v : Math.min(min, v);
        max = Float.isNaN(max) ? v : Math.max(max, v);
        sum += w * v;//from w w  w.  j  av  a 2s .  com
        basesCovered += w;
        nPts++;
        if (values != null) {
            values.add(v);
            if (values.size() > MAX_VALUE_COUNT) {
                computePercentiles();
                values.clear();
            }
        }
    }
}

From source file:test.uk.co.modularaudio.util.audio.gui.buffervis.BufferVisualiser.java

private void computeMinMax(final float[] buffer, final int numSamples) {
    minVal = Float.MAX_VALUE;//w w w  .j  a v  a2s .  c  o m
    maxVal = Float.MIN_VALUE;

    for (int i = 0; i < numSamples; i++) {
        final float v = buffer[i];
        if (Float.isNaN(v) || Float.isInfinite(v)) {
            continue;
        }
        if (v < minVal)
            minVal = v;
        if (v > maxVal)
            maxVal = v;
    }
    diff = maxVal - minVal;
}

From source file:model.utilities.pid.decorator.AutotunerTest.java

private PIDAutotuner runLearningExperimentWithUnknownDeadTime(MersenneTwisterFast random,
        float proportionalParameter, float integrativeParameter, Supplier<Double> noiseMaker,
        DynamicProcess systemDynamic) throws FileNotFoundException {
    PIDAutotuner controller = new PIDAutotuner(
            new PIDController(proportionalParameter, integrativeParameter, 0));
    controller.setAfterHowManyDaysShouldTune(1001);
    int target = 10;
    if (noiseMaker != null)
        systemDynamic.setRandomNoise(noiseMaker);

    //create the regression too

    //output starts at intercept
    float output = 0;
    //delayed input, useful for learning

    SummaryStatistics errorBeforeTuning = new SummaryStatistics();

    SummaryStatistics errorAfterTuning = new SummaryStatistics();
    SummaryStatistics finalError = new SummaryStatistics();

    for (int step = 0; step < 2000; step++) {

        //PID step
        controller.adjust(new ControllerInput(target, output), true, mock(MacroII.class), null,
                ActionOrder.DAWN);/*from   ww w .java  2  s . c  o  m*/

        //process reacts
        float input = controller.getCurrentMV();
        assert !Float.isNaN(input);
        assert !Float.isInfinite(input);
        output = (float) systemDynamic.newStep(input);

        if (step <= 1000)
            errorBeforeTuning.addValue(Math.pow(target - output, 2));
        else
            errorAfterTuning.addValue(Math.pow(target - output, 2));
        if (step > 1900)
            finalError.addValue(Math.pow(target - output, 2));

        //shock target with 10%
        if (random.nextBoolean(.10)) {
            if (random.nextBoolean())
                target++;
            else
                target = Math.max(target - 1, 0);
        }

    }
    System.out.println("errors: " + errorBeforeTuning.getMean() + " --- " + errorAfterTuning.getMean());
    System.out.println("final error: " + finalError.getMean());
    System.out.println("regression: " + controller.getRegression());

    RegressionStatics.tracksAcceptably(controller.getRegression(), systemDynamic,
            RegressionStatics.MAXIMUM_ABS_ERROR, 100,
            Math.max(controller.getCurrentMV(), RegressionStatics.FIXED_INPUT));
    Assert.assertTrue(errorAfterTuning.getMean() < errorBeforeTuning.getMean());
    //either have a very low error, or at least have improved by a factor of over 100
    Assert.assertTrue(finalError.getMean() < 10 || finalError.getMean() < errorBeforeTuning.getMean() / 100);

    return controller;

}

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

public void add(float v) {
    if (!Float.isNaN(v)) {
        min = Float.isNaN(min) ? v : Math.min(min, v);
        max = Float.isNaN(max) ? v : Math.max(max, v);
        sum += v;// w  ww .  ja v  a2 s.co  m
        nPts++;
        if (values != null) {
            values.add(v);
            if (values.size() > MAX_VALUE_COUNT) {
                computePercentiles();
                values.clear();
            }
        }
    }
}