Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

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

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:byps.test.TestSerializePrimitiveTypes.java

@Test
public void testSerializeDouble() throws BException {
    log.info("testSerializeDouble(");
    internalTestSerializeDouble(Double.NaN);
    internalTestSerializeDouble(Double.NEGATIVE_INFINITY);
    internalTestSerializeDouble(Double.POSITIVE_INFINITY);
    internalTestSerializeDouble(0.0);/*from w w  w  . j  a  v  a2s.  c  om*/
    internalTestSerializeDouble(1.0);
    internalTestSerializeDouble(-1.0);
    internalTestSerializeDouble(1.0e7);
    internalTestSerializeDouble(1.0e-7);
    internalTestSerializeDouble(2.0E5);
    log.info(")testSerializeDouble");
}

From source file:Armadillo.Analytics.Base.Precision.java

/**
 * Rounds the given non-negative value to the "nearest" integer. Nearest is
 * determined by the rounding method specified. Rounding methods are defined
 * in {@link BigDecimal}.//from ww w .j ava 2  s.co  m
 *
 * @param unscaled Value to round.
 * @param sign Sign of the original, scaled value.
 * @param roundingMethod Rounding method, as defined in {@link BigDecimal}.
 * @return the rounded value.
 * @throws MathArithmeticException if an exact operation is required but result is not exact
 * @throws MathIllegalArgumentException if {@code roundingMethod} is not a valid rounding method.
 * @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
 */
private static double roundUnscaled(double unscaled, double sign, int roundingMethod)
        throws MathArithmeticException, MathIllegalArgumentException {
    switch (roundingMethod) {
    case BigDecimal.ROUND_CEILING:
        if (sign == -1) {
            unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
        } else {
            unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
        }
        break;
    case BigDecimal.ROUND_DOWN:
        unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
        break;
    case BigDecimal.ROUND_FLOOR:
        if (sign == -1) {
            unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
        } else {
            unscaled = FastMath.floor(FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY));
        }
        break;
    case BigDecimal.ROUND_HALF_DOWN: {
        unscaled = FastMath.nextAfter(unscaled, Double.NEGATIVE_INFINITY);
        double fraction = unscaled - FastMath.floor(unscaled);
        if (fraction > 0.5) {
            unscaled = FastMath.ceil(unscaled);
        } else {
            unscaled = FastMath.floor(unscaled);
        }
        break;
    }
    case BigDecimal.ROUND_HALF_EVEN: {
        double fraction = unscaled - FastMath.floor(unscaled);
        if (fraction > 0.5) {
            unscaled = FastMath.ceil(unscaled);
        } else if (fraction < 0.5) {
            unscaled = FastMath.floor(unscaled);
        } else {
            // The following equality test is intentional and needed for rounding purposes
            if (FastMath.floor(unscaled) / 2.0 == FastMath.floor(Math.floor(unscaled) / 2.0)) { // even
                unscaled = FastMath.floor(unscaled);
            } else { // odd
                unscaled = FastMath.ceil(unscaled);
            }
        }
        break;
    }
    case BigDecimal.ROUND_HALF_UP: {
        unscaled = FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY);
        double fraction = unscaled - FastMath.floor(unscaled);
        if (fraction >= 0.5) {
            unscaled = FastMath.ceil(unscaled);
        } else {
            unscaled = FastMath.floor(unscaled);
        }
        break;
    }
    case BigDecimal.ROUND_UNNECESSARY:
        if (unscaled != FastMath.floor(unscaled)) {
            throw new MathArithmeticException();
        }
        break;
    case BigDecimal.ROUND_UP:
        unscaled = FastMath.ceil(FastMath.nextAfter(unscaled, Double.POSITIVE_INFINITY));
        break;
    default:
        throw new MathIllegalArgumentException(LocalizedFormats.INVALID_ROUNDING_METHOD, roundingMethod,
                "ROUND_CEILING", BigDecimal.ROUND_CEILING, "ROUND_DOWN", BigDecimal.ROUND_DOWN, "ROUND_FLOOR",
                BigDecimal.ROUND_FLOOR, "ROUND_HALF_DOWN", BigDecimal.ROUND_HALF_DOWN, "ROUND_HALF_EVEN",
                BigDecimal.ROUND_HALF_EVEN, "ROUND_HALF_UP", BigDecimal.ROUND_HALF_UP, "ROUND_UNNECESSARY",
                BigDecimal.ROUND_UNNECESSARY, "ROUND_UP", BigDecimal.ROUND_UP);
    }
    return unscaled;
}

From source file:eu.cassandra.utils.Utils.java

/**
 * This function is used in order to find the maximum value from an array.
 * /* www  .  j av  a 2 s  .  c  o  m*/
 * @param matrix
 * @return
 */
public static double findMax(ArrayList<Double> matrix) {

    double result = Double.NEGATIVE_INFINITY;

    for (int i = 0; i < matrix.size(); i++)
        if (result < matrix.get(i))
            result = matrix.get(i);

    return result;
}

From source file:gedi.riboseq.inference.codon.ReadsXCodonMatrix.java

public double regularize3(Codon codon) {

    double deltaLL = 0;
    HashMap<Read, double[]> rs = M.get(codon);
    HashMap<Codon, MutableDouble> ntotal = new HashMap<Codon, MutableDouble>();

    for (Read r : rs.keySet()) {
        double[] d = rs.get(r);
        if (d[1] == 0)
            continue;

        // try to redistribute d[1] to other codons
        HashMap<Codon, double[]> cs = I.get(r);
        double s = 0;
        for (Codon c : cs.keySet()) {
            double[] d2 = cs.get(c);
            if (d2 != d)
                s += d2[1];/*from  w ww . ja  v  a 2  s  .  com*/
        }
        if (s == 0)
            return Double.NEGATIVE_INFINITY; // cannot distribute read to another codon!

        double beforesum = 0;
        for (Codon c : cs.keySet()) {
            double[] d2 = cs.get(c);
            beforesum += c.totalActivity * d2[0];
            if (d2 != d) {
                ntotal.computeIfAbsent(c, x -> new MutableDouble(c.totalActivity)).N += d[1] * d2[1] / s;
                d2[1] += d[1] * d2[1] / s;
            }
        } //JN555585:112387-112922
        deltaLL += r.totalCount * (-Math.log(beforesum));
    }
    for (Read r : rs.keySet()) {
        double[] d = rs.get(r);
        if (d[1] == 0)
            continue;

        HashMap<Codon, double[]> cs = I.get(r);
        double aftersum = 0;
        for (Codon c : cs.keySet()) {
            double[] d2 = cs.get(c);
            if (d2 != d) {
                aftersum += ntotal.get(c).N * d2[0];
            }
        }
        deltaLL += r.totalCount * (Math.log(aftersum));

        d[1] = 0;
    }

    //      double deltaparam = -total; 
    //      return 2*deltaparam-2*deltaLL; // == AIC_after - AIC_before, i.e. regularization is successful if this is negative
    return deltaLL;//codon.totalActivity;
}

From source file:org.apache.drill.exec.fn.impl.TestMathFunctionsWithNanInf.java

@Test
public void testNegativeFunction() throws Exception {
    String table_name = "nan_test.json";
    String json = "{\"nan_col\":NaN, \"inf_col\":Infinity}";
    String query = String.format(
            "select negative(nan_col) as nan_col, negative(inf_col) as inf_col from dfs.`%s`", table_name);
    String[] columns = { "nan_col", "inf_col" };
    Object[] values = { Double.NaN, Double.NEGATIVE_INFINITY };
    evalTest(table_name, json, query, columns, values);
}

From source file:edu.cudenver.bios.matrix.MatrixUtils.java

/**
 * Find the maximum value in the matrix/*  w ww .  jav a  2s .  c o m*/
 * @param matrix
 */
public static double getMaxValue(RealMatrix matrix) {
    double max;
    if (matrix == null) {
        max = Double.NaN;
    } else {
        max = Double.NEGATIVE_INFINITY;
        for (int r = 0; r < matrix.getRowDimension(); r++) {
            for (int c = 0; c < matrix.getColumnDimension(); c++) {
                double value = matrix.getEntry(r, c);
                if (value > max) {
                    max = value;
                }
            }
        }
    }
    return max;
}

From source file:nars.concept.util.BeliefClusterer.java

/**
 * Get a random point from the {@link Cluster} with the largest distance variance.
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 *//*from   www.j  a v  a  2s.  c om*/
@NotNull
private ArrayRealVector getPointFromLargestVarianceCluster(@NotNull final Collection<Cluster> clusters)
        throws ConvergenceException {

    double maxVariance = Double.NEGATIVE_INFINITY;
    Cluster selected = null;
    for (final Cluster cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            // compute the distance variance of the current cluster
            final ArrayRealVector center = cluster.pos;
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center.getDataRef()));
            }
            final double variance = stat.getResult();

            // select the cluster with the largest variance
            if (variance > maxVariance) {
                maxVariance = variance;
                selected = cluster;
            }

        }
    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return p(selectedPoints.remove(random.nextInt(selectedPoints.size())));

}

From source file:edu.uc.rphash.tests.kmeanspp.KMeansPlusPlus.java

/**
 * Get the point farthest to its cluster center
 *
 * @param clusters the {@link Cluster}s to search
 * @return point farthest to its cluster center
 * @throws ConvergenceException if clusters are all empty
 *//*  w ww.  ja  v a2 s  . c o  m*/
private T getFarthestPoint(final Collection<Cluster<T>> clusters) throws Exception {

    double maxDistance = Double.NEGATIVE_INFINITY;
    Cluster<T> selectedCluster = null;
    int selectedPoint = -1;
    for (final Cluster<T> cluster : clusters) {

        // get the farthest point
        final T center = cluster.getCenter();
        final List<T> points = cluster.getPoints();
        for (int i = 0; i < points.size(); ++i) {
            final double distance = points.get(i).distanceFrom(center);
            if (distance > maxDistance) {
                maxDistance = distance;
                selectedCluster = cluster;
                selectedPoint = i;
            }
        }

    }

    // did we find at least one non-empty cluster ?
    if (selectedCluster == null) {
        throw new Exception();
    }

    return selectedCluster.getPoints().remove(selectedPoint);

}

From source file:it.units.malelab.ege.util.Utils.java

public static <T> Set<T> maximallySparseSubset(Map<T, MultiObjectiveFitness<Double>> points, int n) {
    Set<T> remainingPoints = new LinkedHashSet<>(points.keySet());
    Set<T> selectedPoints = new LinkedHashSet<>();
    Distance<MultiObjectiveFitness<Double>> d = new Distance<MultiObjectiveFitness<Double>>() {
        @Override//  ww  w  .  j  av  a2s. c  o  m
        public double d(MultiObjectiveFitness<Double> mof1, MultiObjectiveFitness<Double> mof2) {
            double d = 0;
            for (int i = 0; i < Math.min(mof1.getValue().length, mof2.getValue().length); i++) {
                d = d + Math.pow(mof1.getValue()[i] - mof2.getValue()[i], 2d);
            }
            return Math.sqrt(d);
        }
    };
    while (!remainingPoints.isEmpty() && (selectedPoints.size() < n)) {
        T selected = remainingPoints.iterator().next();
        ;
        if (!selectedPoints.isEmpty()) {
            //add point with max distance from closest point
            double maxMinD = Double.NEGATIVE_INFINITY;
            for (T t : remainingPoints) {
                double minD = Double.POSITIVE_INFINITY;
                for (T otherT : selectedPoints) {
                    minD = Math.min(minD, d.d(points.get(t), points.get(otherT)));
                }
                if (minD > maxMinD) {
                    maxMinD = minD;
                    selected = t;
                }
            }
            //sort
        }
        remainingPoints.remove(selected);
        selectedPoints.add(selected);
    }
    return selectedPoints;
}

From source file:edu.cudenver.bios.power.glmm.GLMMTestUnivariateRepeatedMeasures.java

/**
 * Ensure that the within subject contrast is orthonormal for all
 * UNIREP tests/* w w w. j av  a 2s  .  c  o  m*/
 */
protected void createOrthonormalU() {
    RealMatrix UtU = U.transpose().multiply(U);
    double upperLeft = UtU.getEntry(0, 0);
    if (upperLeft != 0)
        UtU = UtU.scalarMultiply(1 / upperLeft);

    RealMatrix diffFromIdentity = UtU.subtract(
            org.apache.commons.math3.linear.MatrixUtils.createRealIdentityMatrix(UtU.getRowDimension()));

    // get maximum absolute value in U'U
    double maxValue = Double.NEGATIVE_INFINITY;
    for (int r = 0; r < diffFromIdentity.getRowDimension(); r++) {
        for (int c = 0; c < diffFromIdentity.getColumnDimension(); c++) {
            double entryVal = Math.abs(diffFromIdentity.getEntry(r, c));
            if (entryVal > maxValue)
                maxValue = entryVal;
        }
    }

    if (maxValue > Precision.SAFE_MIN) {
        // U'U matrix deviates from identity, so create a U matrix that is orthonormal
        // TODO: thus UNIREP tests may use a different U matrix than HLT/PBT/WLR tests???
        // TODO: displayed matrix results are incorrect now?
        U = new GramSchmidtOrthonormalization(U).getQ();
        debug("U replaced by orthonormal", U);
    }
}