Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

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

Usage

From source file:org.eclipse.january.dataset.CompoundLongDataset.java

@Override
public CompoundLongDataset ipower(final Object b) {
    setDirty();//from  ww  w . j av  a 2  s .co  m
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    final int is = bds.getElementsPerItem();
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        final double v = Math.pow(data[it.index + i], vr);
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        Complex zd = new Complex(data[it.index + i], 0);
                        final double v = zd.pow(zv).getReal();
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            }
        } else if (is == 1) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else if (is == isize) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {
            while (it.hasNext()) {
                double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    }
    return this;
}

From source file:org.eclipse.january.dataset.CompoundByteDataset.java

@Override
public CompoundByteDataset ipower(final Object b) {
    setDirty();//  w  w  w.j ava 2  s .  c  o m
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    final int is = bds.getElementsPerItem();
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        final double v = Math.pow(data[it.index + i], vr);
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        Complex zd = new Complex(data[it.index + i], 0);
                        final double v = zd.pow(zv).getReal();
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            }
        } else if (is == 1) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else if (is == isize) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {
            while (it.hasNext()) {
                double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    }
    return this;
}

From source file:org.eclipse.january.dataset.CompoundShortDataset.java

@Override
public CompoundShortDataset ipower(final Object b) {
    setDirty();//from w ww.ja  v  a 2  s  . c o  m
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    final int is = bds.getElementsPerItem();
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        final double v = Math.pow(data[it.index + i], vr);
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        Complex zd = new Complex(data[it.index + i], 0);
                        final double v = zd.pow(zv).getReal();
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            }
        } else if (is == 1) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else if (is == isize) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {
            while (it.hasNext()) {
                double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    }
    return this;
}

From source file:org.eclipse.january.dataset.CompoundIntegerDataset.java

@Override
public CompoundIntegerDataset ipower(final Object b) {
    setDirty();/*ww  w . j a va2 s.c o m*/
    Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    final int is = bds.getElementsPerItem();
    if (bds.getSize() == 1) {
        final double vr = bds.getElementDoubleAbs(0);
        final IndexIterator it = getIterator();
        if (bds.isComplex()) {
            final double vi = bds.getElementDoubleAbs(1);
            if (vi == 0) {
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        final double v = Math.pow(data[it.index + i], vr);
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            } else {
                final Complex zv = new Complex(vr, vi);
                while (it.hasNext()) {
                    for (int i = 0; i < isize; i++) {
                        Complex zd = new Complex(data[it.index + i], 0);
                        final double v = zd.pow(zv).getReal();
                        if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                            data[it.index + i] = 0; // INT_USE
                        } else { // INT_USE
                            data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                        } // INT_USE
                    }
                }
            }
        } else if (is == 1) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], vr);
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else if (is == isize) {
            while (it.hasNext()) {
                for (int i = 0; i < isize; i++) {
                    final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.index + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    } else {
        final BroadcastIterator it = BroadcastIterator.createIterator(this, bds);
        it.setOutputDouble(true);
        if (bds.isComplex()) {
            while (it.hasNext()) {
                final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1));
                double v = new Complex(it.aDouble, 0).pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal();
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        } else {
            while (it.hasNext()) {
                double v = Math.pow(it.aDouble, it.bDouble);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                    data[it.aIndex] = 0; // INT_USE
                } else { // INT_USE
                    data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_USE
                for (int i = 1; i < isize; i++) {
                    v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i));
                    if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE
                        data[it.aIndex + i] = 0; // INT_USE
                    } else { // INT_USE
                        data[it.aIndex + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                    } // INT_USE
                }
            }
        }
    }
    return this;
}

From source file:ffx.potential.ForceFieldEnergy.java

/**
 * <p>//from ww w .  j a  v  a2 s.c o m
 * getGradients</p>
 *
 * @param g an array of double.
 */
public double[] getGradients(double g[]) {
    assert (g != null);
    double grad[] = new double[3];
    int n = getNumberOfVariables();
    if (g.length < n) {
        g = new double[n];
    }
    int index = 0;
    for (int i = 0; i < nAtoms; i++) {
        Atom a = atoms[i];
        if (a.isActive()) {
            a.getXYZGradient(grad);
            double gx = grad[0];
            double gy = grad[1];
            double gz = grad[2];
            if (Double.isNaN(gx) || Double.isInfinite(gx) || Double.isNaN(gy) || Double.isInfinite(gy)
                    || Double.isNaN(gz) || Double.isInfinite(gz)) {
                String message = format("The gradient of atom %s is (%8.3f,%8.3f,%8.3f).", a.toString(), gx, gy,
                        gz);
                //logger.severe(message);
                throw new EnergyException(message);
            }
            g[index++] = gx;
            g[index++] = gy;
            g[index++] = gz;
        }
    }
    return g;
}

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * Calculate minimum and maximum for a dataset
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 *///from  w  w w.j ava 2s.co  m
protected void calculateMaxMin(final boolean ignoreNaNs, final boolean ignoreInfs) {
    IndexIterator iter = getIterator();
    double amax = Double.NEGATIVE_INFINITY;
    double amin = Double.POSITIVE_INFINITY;
    double pmax = Double.MIN_VALUE;
    double pmin = Double.POSITIVE_INFINITY;
    double hash = 0;
    boolean hasNaNs = false;

    while (iter.hasNext()) {
        final double val = getElementDoubleAbs(iter.index);
        if (Double.isNaN(val)) {
            hash = (hash * 19) % Integer.MAX_VALUE;
            if (ignoreNaNs)
                continue;
            hasNaNs = true;
        } else if (Double.isInfinite(val)) {
            hash = (hash * 19) % Integer.MAX_VALUE;
            if (ignoreInfs)
                continue;
        } else {
            hash = (hash * 19 + val) % Integer.MAX_VALUE;
        }

        if (val > amax) {
            amax = val;
        }
        if (val < amin) {
            amin = val;
        }
        if (val > 0) {
            if (val < pmin) {
                pmin = val;
            }
            if (val > pmax) {
                pmax = val;
            }
        }
    }

    int ihash = ((int) hash) * 19 + getDtype() * 17 + getElementsPerItem();
    setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_SHAPELESS_HASH), ihash);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX),
            hasNaNs ? Double.NaN : fromDoubleToNumber(amax));
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN),
            hasNaNs ? Double.NaN : fromDoubleToNumber(amin));
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_POS_MAX),
            hasNaNs ? Double.NaN : fromDoubleToNumber(pmax));
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_POS_MIN),
            hasNaNs ? Double.NaN : fromDoubleToNumber(pmin));
}

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 * @param name//from  ww w  .j a v a 2  s . c om
 */
protected void calculateSummaryStats(final boolean ignoreNaNs, final boolean ignoreInfs, final String name) {
    final IndexIterator iter = getIterator();
    final SummaryStatistics stats = new SummaryStatistics();

    if (storedValues == null || !storedValues.containsKey(STORE_HASH)) {
        boolean hasNaNs = false;
        double hash = 0;
        double pmax = Double.MIN_VALUE;
        double pmin = Double.POSITIVE_INFINITY;

        while (iter.hasNext()) {
            final double val = getElementDoubleAbs(iter.index);
            if (Double.isNaN(val)) {
                hash = (hash * 19) % Integer.MAX_VALUE;
                if (ignoreNaNs)
                    continue;
                hasNaNs = true;
            } else if (Double.isInfinite(val)) {
                hash = (hash * 19) % Integer.MAX_VALUE;
                if (ignoreInfs)
                    continue;
            } else {
                hash = (hash * 19 + val) % Integer.MAX_VALUE;
            }
            if (val > 0) {
                if (val < pmin) {
                    pmin = val;
                }
                if (val > pmax) {
                    pmax = val;
                }
            }
            stats.addValue(val);
        }

        int ihash = ((int) hash) * 19 + getDtype() * 17 + getElementsPerItem();
        setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_SHAPELESS_HASH), ihash);
        storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX),
                hasNaNs ? Double.NaN : fromDoubleToNumber(stats.getMax()));
        storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN),
                hasNaNs ? Double.NaN : fromDoubleToNumber(stats.getMin()));
        storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_POS_MAX),
                hasNaNs ? Double.NaN : fromDoubleToNumber(pmax));
        storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_POS_MIN),
                hasNaNs ? Double.NaN : fromDoubleToNumber(pmin));
        storedValues.put(name, stats);
    } else {
        while (iter.hasNext()) {
            final double val = getElementDoubleAbs(iter.index);
            if (ignoreNaNs && Double.isNaN(val)) {
                continue;
            }
            if (ignoreInfs && Double.isInfinite(val)) {
                continue;
            }

            stats.addValue(val);
        }

        storedValues.put(name, stats);
    }
}

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * Calculate summary statistics for a dataset along an axis
 * @param ignoreNaNs if true, ignore NaNs
 * @param ignoreInfs if true, ignore infinities
 * @param axis// w  w  w.j  a  va  2 s  .  c om
 */
protected void calculateSummaryStats(final boolean ignoreNaNs, final boolean ignoreInfs, final int axis) {
    int rank = getRank();

    int[] oshape = getShape();
    int alen = oshape[axis];
    oshape[axis] = 1;

    int[] nshape = new int[rank - 1];
    for (int i = 0; i < axis; i++) {
        nshape[i] = oshape[i];
    }
    for (int i = axis + 1; i < rank; i++) {
        nshape[i - 1] = oshape[i];
    }

    final int dtype = getDtype();
    IntegerDataset count = new IntegerDataset(nshape);
    Dataset max = DatasetFactory.zeros(nshape, dtype);
    Dataset min = DatasetFactory.zeros(nshape, dtype);
    IntegerDataset maxIndex = new IntegerDataset(nshape);
    IntegerDataset minIndex = new IntegerDataset(nshape);
    Dataset sum = DatasetFactory.zeros(nshape, getLargestDType(dtype));
    DoubleDataset mean = new DoubleDataset(nshape);
    DoubleDataset var = new DoubleDataset(nshape);

    IndexIterator qiter = max.getIterator(true);
    int[] qpos = qiter.getPos();
    int[] spos = oshape.clone();

    while (qiter.hasNext()) {
        int i = 0;
        for (; i < axis; i++) {
            spos[i] = qpos[i];
        }
        spos[i++] = 0;
        for (; i < rank; i++) {
            spos[i] = qpos[i - 1];
        }

        final SummaryStatistics stats = new SummaryStatistics();
        double amax = Double.NEGATIVE_INFINITY;
        double amin = Double.POSITIVE_INFINITY;
        boolean hasNaNs = false;
        if (ignoreNaNs) {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);

                if (Double.isNaN(val)) {
                    hasNaNs = true;
                    continue;
                } else if (ignoreInfs && Double.isInfinite(val)) {
                    continue;
                }

                if (val > amax) {
                    amax = val;
                }
                if (val < amin) {
                    amin = val;
                }

                stats.addValue(val);
            }
        } else {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);

                if (hasNaNs) {
                    if (!Double.isNaN(val))
                        stats.addValue(0);
                    continue;
                }

                if (Double.isNaN(val)) {
                    amax = Double.NaN;
                    amin = Double.NaN;
                    hasNaNs = true;
                } else if (ignoreInfs && Double.isInfinite(val)) {
                    continue;
                } else {
                    if (val > amax) {
                        amax = val;
                    }
                    if (val < amin) {
                        amin = val;
                    }
                }
                stats.addValue(val);
            }
        }

        count.setAbs(qiter.index, (int) stats.getN());

        max.setObjectAbs(qiter.index, amax);
        min.setObjectAbs(qiter.index, amin);
        boolean fmax = false;
        boolean fmin = false;
        if (hasNaNs) {
            if (ignoreNaNs) {
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double val = getDouble(spos);
                    if (Double.isNaN(val))
                        continue;

                    if (!fmax && val == amax) {
                        maxIndex.setAbs(qiter.index, j);
                        fmax = true;
                        if (fmin)
                            break;
                    }
                    if (!fmin && val == amin) {
                        minIndex.setAbs(qiter.index, j);
                        fmin = true;
                        if (fmax)
                            break;
                    }
                }
            } else {
                for (int j = 0; j < alen; j++) {
                    spos[axis] = j;
                    final double val = getDouble(spos);
                    if (Double.isNaN(val)) {
                        maxIndex.setAbs(qiter.index, j);
                        minIndex.setAbs(qiter.index, j);
                        break;
                    }
                }
            }
        } else {
            for (int j = 0; j < alen; j++) {
                spos[axis] = j;
                final double val = getDouble(spos);
                if (!fmax && val == amax) {
                    maxIndex.setAbs(qiter.index, j);
                    fmax = true;
                    if (fmin)
                        break;
                }
                if (!fmin && val == amin) {
                    minIndex.setAbs(qiter.index, j);
                    fmin = true;
                    if (fmax)
                        break;
                }
            }
        }
        sum.setObjectAbs(qiter.index, stats.getSum());
        mean.setAbs(qiter.index, stats.getMean());
        var.setAbs(qiter.index, stats.getVariance());
    }
    setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_COUNT + "-" + axis), count);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX + "-" + axis), max);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN + "-" + axis), min);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_SUM + "-" + axis), sum);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MEAN + "-" + axis), mean);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_VAR + "-" + axis), var);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MAX + STORE_INDEX + "-" + axis), maxIndex);
    storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MIN + STORE_INDEX + "-" + axis), minIndex);
}

From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Adds the particular time-metrics for the highlevelactivity of a transition to
 * the simulation model.//www.  java  2  s .c  o m
 * @param kindTimingInfo String <code>"waiting"</code> when the provided time-metrics deal about waiting time.
 * <code>execution</code> when the provided time-metrics deal about execution time and <code>"sojourn"</code> when
 * the provided time-metrics deal about sojourn time
 * @param activity HLActivity the highlevelactivity of a transition
 * @param mean double the mean
 * @param min double the minimum
 * @param max double the maximum
 * @param stDev double the standard deviation
 * @param constVal double the constant value
 * @param arrivalRate double the arrival rate
 */
private void addTimingInfoForTransition(String kindTimingInfo, HLActivity activity, double mean, double min,
        double max, double stDev, double constVal, double arrivalRate) {
    // in case that NaN is provided for either mean, min, max or stDev the default value needs to be used
    double constFinal = 0.0;
    double meanFinal = 0.0;
    double varianceFinal = 0.0;
    double minFinal = 0.0;
    double maxFinal = 0.0;
    double intensityFinal = 0.0;
    if (!(Double.isNaN(mean) || Double.isInfinite(mean))) {
        meanFinal = mean;
    }
    if (!(Double.isNaN(min) || Double.isInfinite(min))) {
        minFinal = min;
    }
    if (!(Double.isNaN(max) || Double.isInfinite(max))) {
        maxFinal = max;
    }
    if (!(Double.isNaN(stDev) || Double.isInfinite(stDev))) {
        varianceFinal = stDev * stDev;
    }
    if (!(Double.isNaN(constVal) || Double.isInfinite(constVal))) {
        constFinal = constVal;
    }
    if (!(Double.isNaN(arrivalRate) || Double.isInfinite(arrivalRate))) {
        intensityFinal = arrivalRate;
    }

    HLGeneralDistribution dist = new HLGeneralDistribution(constFinal, meanFinal, varianceFinal, minFinal,
            maxFinal, intensityFinal, HLDistribution.DistributionEnum.NORMAL_DISTRIBUTION);

    if (kindTimingInfo.equals("waiting")) {
        activity.setWaitingTime(dist);
    } else if (kindTimingInfo.equals("execution")) {
        activity.setExecutionTime(dist);
    } else if (kindTimingInfo.equals("sojourn")) {
        activity.setSojournTime(dist);
    }
}

From source file:com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.java

protected double getDataAverage(final Node dataNode, final int col, final int numRows) {
    double value = 0;
    final double dummy = 0;
    int numRowsUsed = 0;
    for (int row = 0; row < numRows; row++) {
        final Node data = dataNode.getChildNodes().item(numRows - 1 - row).getChildNodes().item(col + 1);
        final Double currentDataAsDouble = Double.valueOf(getXMLNodeValue(data));
        if (!currentDataAsDouble.equals(Double.NaN)) {
            numRowsUsed += 1;/* w w w.  j av  a  2s .co  m*/
            value += currentDataAsDouble;
        }
    }

    if (numRowsUsed == 0) {
        if (!Double.isInfinite(value) && !Double.isNaN(value)) {
            return value;
        } else {
            s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows=0");
            return dummy;
        }
    } else {
        if (!Double.isInfinite(value / numRowsUsed) && !Double.isNaN(value / numRowsUsed)) {
            return value / numRowsUsed;
        } else {
            s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows>0");
            return dummy;
        }
    }

}