Example usage for java.lang Double isNaN

List of usage examples for java.lang Double isNaN

Introduction

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

Prototype

public static boolean isNaN(double v) 

Source Link

Document

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

Usage

From source file:mase.mason.generic.systematic.SystematicStandardiser.java

@Override
public void processPopulation(EvolutionState state) {
    // TODO: needs different mechanisms for shared and individual archives

    // initialization
    if (archives == null) {
        PostEvaluator[] evals = ((MetaEvaluator) state.evaluator).getPostEvaluators();
        for (PostEvaluator pe : evals) {
            if (pe instanceof NoveltyEvaluation) {
                NoveltyEvaluation ne = (NoveltyEvaluation) pe;
                archives = ne.getArchives();
                behavIndex = ne.getBehaviourIndex();
            }//w w w  .  ja  v a  2 s .c om
        }
    }

    // join all behaviour results in one list
    // from archive
    ArrayList<SystematicResult> results = new ArrayList<>(2000);
    for (ArchiveEntry ar : archives[0]) {
        results.add((SystematicResult) ar.getBehaviour());
    }
    // from the population
    for (Subpopulation sub : state.population.subpops) {
        for (Individual ind : sub.individuals) {
            ExpandedFitness nf = (ExpandedFitness) ind.fitness;
            results.add((SystematicResult) nf.getCorrespondingEvaluation(behavIndex));
        }
    }

    // calculate mean and sd for each feature
    int size = results.get(0).getOriginalResult().length;
    DescriptiveStatistics[] ds = new DescriptiveStatistics[size];
    for (int i = 0; i < size; i++) {
        ds[i] = new DescriptiveStatistics();
        for (SystematicResult vbr : results) {
            ds[i].addValue(vbr.getOriginalResult()[i]);
        }
    }
    double[] means = new double[size];
    double[] sds = new double[size];
    for (int i = 0; i < size; i++) {
        means[i] = ds[i].getMean();
        double sd = ds[i].getStandardDeviation();
        sds[i] = sd == 0 || Double.isNaN(sd) || Double.isInfinite(sd) ? 1 : sd;
    }

    for (SystematicResult vbr : results) {
        for (int i = 0; i < size; i++) {
            double v = (vbr.getOriginalResult()[i] - means[i]) / sds[i];
            vbr.getBehaviour()[i] = (float) Math.max(-BOUND, Math.min(BOUND, v));
        }
    }
}

From source file:de.thkwalter.et.betriebspunkt.BetriebspunktTest.java

/**
 * Test des Konstruktors {@link Betriebspunkt#Betriebspunkt()}, der alle reellwertigen Gren mit {@link Double.NaN}
 * initialisiert./*w ww  .  j  a  v a2s  .  c  o m*/
 * 
 * @throws SecurityException 
 * @throws NoSuchFieldException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
@Test
public void testBetriebspunkt_NaN()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    // Es wird berprft, ob der effektive Leiterstrom (in A) korrekt initialisiert worden ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getI_L()));

    // Es wird berprft, ob die effektive Leiter-Leiterspannung (in A) korrekt initialisiert worden ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getU_LL()));

    // Es wird berprft, ob die elektrische Leistung (in kW) korrekt initialisiert worden ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getP_el()));

    // Es wird berprft, ob die Scheinleistung (in kVA) korrekt initialisiert worden ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getP_s()));

    // Es wird berprft, ob die Phasenverschiebung zwischen Strangstrom und Strangspannung korrekt initialisiert worden 
    // ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getCosPhi()));

    // Es wird berprft, ob der Schaltungstyp den Wert null besitzt.
    assertNull(this.betriebspunkt.getSchaltungstyp());

    // Es wird berprft, ob der komplexe Zeiger des Strangstroms (in A) den Wert null besitzt.
    assertTrue(Double.isNaN(this.betriebspunkt.getZ_i_s().getReal()));
    assertTrue(Double.isNaN(this.betriebspunkt.getZ_i_s().getImaginary()));
}

From source file:de.openali.odysseus.chart.factory.util.AxisUtils.java

/**
 * Searches all axes that are configured for autoscaling.
 *//*www  .ja  va 2 s .com*/
public static IAxis[] findAutoscaleAxes(final AxisType[] axes, final IAxisRegistry mapperRegistry) {
    final List<IAxis> autoscaledAxes = new ArrayList<>();

    for (final AxisType axisType : axes) {
        Object min = null;
        Object max = null;

        if (axisType.isSetDateRange()) {
            final AxisDateRangeType range = axisType.getDateRange();
            min = range.getMinValue();
            max = range.getMaxValue();
        } else if (axisType.isSetDurationRange()) {
            final AxisDurationRangeType range = axisType.getDurationRange();
            min = range.getMinValue();
            max = range.getMaxValue();
        } else if (axisType.isSetStringRange()) {
            final AxisStringRangeType range = axisType.getStringRange();
            min = range.getMinValue();
            max = range.getMaxValue();
        } else if (axisType.isSetNumberRange()) {
            final AxisNumberRangeType range = axisType.getNumberRange();
            min = range.getMinValue();
            max = range.getMaxValue();
            if (Double.isNaN((Double) min))
                min = null;
            if (Double.isNaN((Double) max))
                max = null;
        }

        if (min == null || max == null)
            autoscaledAxes.add(mapperRegistry.getAxis(axisType.getId()));
    }

    return autoscaledAxes.toArray(new IAxis[autoscaledAxes.size()]);
}

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

private void init() {
    double a, b;//from w  ww  . j  ava2 s .  com
    if (Double.isNaN(alpha) && Double.isNaN(beta) && !Double.isNaN(dof)) {
        if (Double.isNaN(scale)) {
            scale = 1;
        }
        a = dof / 2;
        b = scale * dof / 2;
    } else if (Double.isNaN(dof) && !Double.isNaN(alpha) && !Double.isNaN(beta)) {
        a = alpha;
        b = beta;
    } else {
        throw new IllegalArgumentException(
                "Must use either alpha,beta,rate (or defaults) or dof,scale to parametrize gamma");
    }
    if (seed != SEED_NOT_SET) {
        rand = new Gamma(a, b, new Random(seed));
    } else {
        rand = new Gamma(a, b, new Random());
    }
}

From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java

private void computeStats(RealMatrix m) {
    if (m.getColumnDimension() != this.cmdTypes.length) {
        LOG.error("Please fix the commands list in config file");
    }//from ww  w.j a va 2 s  .  c o  m

    statistics = new UserCommandStatistics[m.getColumnDimension()];

    for (int i = 0; i < m.getColumnDimension(); i++) {
        UserCommandStatistics stats = new UserCommandStatistics();
        stats.setCommandName(this.cmdTypes[i]);
        RealVector colData = m.getColumnVector(i);
        StandardDeviation deviation = new StandardDeviation();
        double stddev = deviation.evaluate(colData.toArray());

        if (LOG.isDebugEnabled())
            LOG.debug("Stddev is NAN ? " + (Double.isNaN(stddev) ? "yes" : "no"));
        if (stddev <= lowVarianceVal)
            stats.setLowVariant(true);
        else
            stats.setLowVariant(false);

        stats.setStddev(stddev);
        Mean mean = new Mean();
        double mu = mean.evaluate(colData.toArray());
        if (LOG.isDebugEnabled())
            LOG.debug("mu is NAN ? " + (Double.isNaN(mu) ? "yes" : "no"));

        stats.setMean(mu);
        statistics[i] = stats;
    }
}

From source file:com.opengamma.analytics.math.function.PiecewisePolynomialWithSensitivityFunction1D.java

/** 
 * @param pp {@link PiecewisePolynomialResultsWithSensitivity}
 * @param xKeys /*from   w w  w. j a  va2 s.c o m*/
 * @return Node sensitivity value at x=xKeys
 */
public DoubleMatrix1D[] nodeSensitivity(final PiecewisePolynomialResultsWithSensitivity pp,
        final double[] xKeys) {
    ArgumentChecker.notNull(pp, "null pp");
    ArgumentChecker.notNull(xKeys, "null xKeys");
    final int nKeys = xKeys.length;
    final DoubleMatrix1D[] res = new DoubleMatrix1D[nKeys];

    for (int i = 0; i < nKeys; ++i) {
        ArgumentChecker.isFalse(Double.isNaN(xKeys[i]), "xKey containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(xKeys[i]), "xKey containing Infinity");
    }
    if (pp.getDimensions() > 1) {
        throw new NotImplementedException();
    }

    final double[] knots = pp.getKnots().getData();
    final int nKnots = knots.length;

    for (int j = 0; j < nKeys; ++j) {
        final double xKey = xKeys[j];
        int interval = FunctionUtils.getLowerBoundIndex(knots, xKey);
        if (interval == nKnots - 1) {
            interval--; // there is 1 less interval that knots
        }

        final double s = xKey - knots[interval];
        final DoubleMatrix2D a = pp.getCoefficientSensitivity(interval);
        final int nCoefs = a.getNumberOfRows();

        res[j] = a.getRowVector(0);
        for (int i = 1; i < nCoefs; i++) {
            res[j] = (DoubleMatrix1D) MA.scale(res[j], s);
            res[j] = (DoubleMatrix1D) MA.add(res[j], a.getRowVector(i));
        }
    }

    return res;
}

From source file:bb.mcmc.analysis.ESSConvergeStat.java

@Override
protected double calculateEachProgress(Double stat, Deque<Double> record) {

    if (!Double.isNaN(stat)) {
        if (record.size() > 0) {
            record.pop();/*ww w. j  a  v  a  2 s .  c om*/
        }
        record.add(stat);
    }
    stat = record.peekFirst();
    double progress = stat / essThreshold;
    return progress;
}

From source file:eu.crisis_economics.abm.algorithms.optimization.NonLinearExtremizer.java

protected final ImmutableExtremumResult createImmutableExtremumResult(double[] startingCoordinate,
        double[] extremalCoordinate, double[] derivativeAtExtremum, double extremalEvalutation) {
    if (startingCoordinate == null || extremalCoordinate == null || derivativeAtExtremum == null)
        throw new NullArgumentException();
    if (Double.isNaN(extremalEvalutation))
        throw new IllegalArgumentException();
    final int n = startingCoordinate.length;
    if (n == 0 || extremalCoordinate.length != n || derivativeAtExtremum.length != n)
        throw new IllegalArgumentException();
    ImmutableExtremumResult result = new ImmutableExtremumResult();
    result.startingCoordinate = startingCoordinate.clone();
    result.extremalCoordinate = extremalCoordinate.clone();
    result.derivativeAtExtremum = derivativeAtExtremum.clone();
    result.extremalEvalutation = extremalEvalutation;
    result.normOfDerivativeAtExtremum = (new ArrayRealVector(derivativeAtExtremum)).getNorm();
    return result;
}

From source file:edu.jhuapl.bsp.detector.OpenMath.java

public static double sum(int[] in) {
    if (in != null) {
        double sum = 0;
        for (int i = 0; i < in.length; i++) {
            sum += in[i];/*ww  w . j a  v  a  2 s . co m*/
        }
        if (Double.isNaN(sum) || Double.isInfinite(sum)) {
            return 0;
        } else {
            return sum;
        }
    }
    return 0;
}

From source file:edu.tum.cs.vis.model.util.HandleComparator.java

/**
 * Calculates the weight for a handle. If no min/max radius is given (=-1) then the weight is
 * proportional to the radius. If only radius is given, the length is ignored. If both are
 * given, the weight is calculated as a combination of radius and length.
 * /*  w  ww.  ja va 2s .c  om*/
 * @param h
 *            Handle annotation
 * @param model
 *            parent model of annotation (needed to get unscaled value)
 * @param minRadius
 *            minimum desired handle radius
 * @param maxRadius
 *            maximum desired handle radius
 * @param minLength
 *            minimum desired handle length
 * @param maxLength
 *            maximum desired handle length
 * @return weight for the handle. The bigger the weight, the more probable it is a handle
 */
public static double getHandleWeight(HandleAnnotation h, Model model, double minRadius, double maxRadius,
        double minLength, double maxLength) {

    double w = getMinMaxWeight(model.getUnscaled(h.getCone().getRadiusAvg()), minRadius, maxRadius,
            WEIGHT_RADIUS, model.getUnscaled(h.getCone().getRadiusAvg()))
            * getMinMaxWeight(model.getUnscaled(h.getCone().getHeight()), minLength, maxLength, WEIGHT_LENGTH,
                    1)
            * getAreaCoverageWeight(h.getAreaCoverage());

    // it may be that the cone wasn't fit correctly and is therefore NAN
    if (Double.isNaN(w))
        w = 0;
    return w;
}