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:com.cloudera.oryx.common.math.OpenMapRealVector.java

@SuppressWarnings("deprecation")
@Deprecated/*w w  w  .j a  v a2 s.c o m*/
@Override
public OpenMapRealVector ebeMultiply(RealVector v) {
    checkVectorDimensions(v.getDimension());
    OpenMapRealVector res = new OpenMapRealVector(this);
    OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
    while (iter.hasNext()) {
        iter.advance();
        res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
    }
    /*
     * MATH-803: the above loop assumes that 0d * x  = 0d for any double x,
     * which allows to consider only the non-zero entries of this. However,
     * this fails if this[i] == 0d and (v[i] = NaN or v[i] = Infinity).
     *
     * These special cases are handled below.
     */
    if (v.isNaN() || v.isInfinite()) {
        int n = getDimension();
        for (int i = 0; i < n; i++) {
            double y = v.getEntry(i);
            if (Double.isNaN(y)) {
                res.setEntry(i, Double.NaN);
            } else if (Double.isInfinite(y)) {
                double x = this.getEntry(i);
                res.setEntry(i, x * y);
            }
        }
    }
    return res;
}

From source file:org.broadinstitute.gatk.utils.MathUtils.java

public static boolean wellFormedDouble(final double val) {
    return !Double.isInfinite(val) && !Double.isNaN(val);
}

From source file:ml.shifu.core.util.CommonUtils.java

public static boolean isValidNumber(Object raw) {
    if (raw == null) {
        return false;
    }//from w ww  . j  a  va 2s.  c o  m
    Double value;
    try {
        value = Double.parseDouble(raw.toString());
    } catch (NumberFormatException e) {
        return false;
    }

    return !(Double.isNaN(value) || Double.isInfinite(value));

}

From source file:com.opengamma.analytics.math.interpolation.MonotoneConvexSplineInterpolator.java

/**
 * Compute the value of f(t) = \frac{\partial r(t) t}{\partial t} at t=x
 * @param xValues Data r_i/*from   w  w  w .jav a2 s  .com*/
 * @param yValues Data r(t_i)
 * @param x Key larger than min{r_i}
 * @return  f(x)
 */
public double interpolateFwds(final double[] xValues, final double[] yValues, final double x) {
    final PiecewisePolynomialResult result = interpolateFwds(xValues, yValues);
    final DoubleMatrix2D coefsMatrix = result.getCoefMatrix();
    final int nKnots = coefsMatrix.getNumberOfRows() + 1;
    final double[] knots = result.getKnots().getData();

    int indicator = 0;
    if (x <= knots[1]) {
        indicator = 0;
    } else {
        for (int i = 1; i < nKnots - 1; ++i) {
            if (knots[i] < x) {
                indicator = i;
            }
        }
    }

    final double[] coefs = coefsMatrix.getRowVector(indicator).getData();

    final double res = getValue(coefs, x, knots[indicator]);
    ArgumentChecker.isFalse(Double.isInfinite(res), "Too large/small data values or xKey");
    ArgumentChecker.isFalse(Double.isNaN(res), "Too large/small data values or xKey");

    return res;
}

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

@SuppressWarnings("deprecation")
@Test/*  w  ww . ja va 2  s. c  o  m*/
public void testMaxMin() {
    Dataset a = DatasetFactory.createRange(12, Dataset.FLOAT64);
    a.setShape(3, 4);
    assertEquals("Max", 11, a.max().doubleValue(), 1e-6);
    assertEquals("Max 0", DatasetFactory.createFromObject(new double[] { 8, 9, 10, 11 }), a.max(0));
    assertEquals("Max 1", DatasetFactory.createFromObject(new double[] { 3, 7, 11 }), a.max(1));
    assertEquals("Max arg", 11, a.argMax());
    assertEquals("Max arg 0 ", DatasetFactory.createFromObject(new int[] { 2, 2, 2, 2 }), a.argMax(0));
    assertEquals("Max arg 1 ", DatasetFactory.createFromObject(new int[] { 3, 3, 3 }), a.argMax(1));
    a.set(Double.NaN, 1, 0);
    System.out.println(a.toString(true));
    assertTrue("Max", Double.isNaN(a.max().doubleValue()));
    assertTrue("Max", !Double.isNaN(a.max(true).doubleValue()));
    assertTrue("Max 0",
            equalsWithNaNs(DatasetFactory.createFromObject(new double[] { Double.NaN, 9, 10, 11 }), a.max(0)));
    assertTrue("Max 1",
            equalsWithNaNs(DatasetFactory.createFromObject(new double[] { 3, Double.NaN, 11 }), a.max(1)));
    assertEquals("Max arg", 4, a.argMax());
    assertEquals("Max arg 0 ", DatasetFactory.createFromObject(new int[] { 1, 2, 2, 2 }), a.argMax(0));
    assertEquals("Max arg 1 ", DatasetFactory.createFromObject(new int[] { 3, 0, 3 }), a.argMax(1));
    assertEquals("Max", 11, a.max(true).doubleValue(), 1e-6);
    assertEquals("Max 0", DatasetFactory.createFromObject(new double[] { 8, 9, 10, 11 }), a.max(0, true));
    assertEquals("Max 1", DatasetFactory.createFromObject(new double[] { 3, 7, 11 }), a.max(1, true));
    assertEquals("Max arg", 11, a.argMax(true));
    assertEquals("Max arg 0 ", DatasetFactory.createFromObject(new int[] { 2, 2, 2, 2 }), a.argMax(0, true));
    assertEquals("Max arg 1 ", DatasetFactory.createFromObject(new int[] { 3, 3, 3 }), a.argMax(1, true));

    a.set(Double.NEGATIVE_INFINITY, 1, 1);
    System.out.println(a.toString(true));
    assertTrue("Max", Double.isNaN(a.max().doubleValue()));
    assertTrue("Max", !Double.isNaN(a.max(true).doubleValue()));
    assertTrue("Max", Double.isNaN(a.max(false, true).doubleValue()));
    assertTrue("Max", !Double.isNaN(a.max(true, false).doubleValue()));
    assertEquals("Max", 11, a.max(true).doubleValue(), 1e-6);
    assertTrue("Min", Double.isNaN(a.min().doubleValue()));
    assertTrue("Min", !Double.isNaN(a.min(true).doubleValue()));
    assertTrue("Min", Double.isNaN(a.min(false, true).doubleValue()));
    assertTrue("Min", !Double.isNaN(a.min(true, false).doubleValue()));
    assertTrue("Min", !Double.isInfinite(a.min().doubleValue()));
    assertTrue("Min", !Double.isInfinite(a.min(true).doubleValue()));
    assertTrue("Min", !Double.isInfinite(a.min(false, true).doubleValue()));
    assertTrue("Min", Double.isInfinite(a.min(true, false).doubleValue()));
    assertEquals("Min", 0, a.min(true).doubleValue(), 1e-6);

    // test other code path
    Dataset b = DatasetFactory.createRange(12, Dataset.FLOAT64);
    b.setShape(3, 4);
    b.mean(); // trigger summary stats calculation
    assertEquals("Max", 11, b.max().doubleValue(), 1e-6);
    assertEquals("Max arg", 11, b.argMax());
    b.set(Double.NaN, 1, 0);
    b.mean(); // trigger summary stats calculation
    assertTrue("Max", Double.isNaN(b.max().doubleValue()));
    assertEquals("Max arg", 4, b.argMax());
    b.mean(true);
    assertEquals("Max", 11, b.max(true).doubleValue(), 1e-6);
    assertEquals("Max arg", 11, b.argMax(true));

    // check strided datasets give same max/min positions
    a = DatasetFactory.createRange(12, Dataset.FLOAT64).reshape(3, 4);
    b = a.getSliceView(new Slice(1, null), new Slice(0, null, 2));
    Dataset c = a.getSlice(new Slice(1, null), new Slice(0, null, 2));

    Assert.assertEquals(c.argMax(), b.argMax());
    Assert.assertEquals(c.argMin(), b.argMin());
}

From source file:org.alfresco.repo.jscript.app.JSONConversionComponent.java

/**
 * Handles the work of converting values to JSON.
 * /* w w  w.j  a  v  a 2s  .c  o  m*/
 * @param nodeRef NodeRef
 * @param propertyName QName
 * @param key String
 * @param value Serializable
 * @return the JSON value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object propertyToJSON(final NodeRef nodeRef, final QName propertyName, final String key,
        final Serializable value) {
    if (value != null) {
        // Has a decorator has been registered for this property?
        if (propertyDecorators.containsKey(propertyName)) {
            JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
            if (jsonAware != null) {
                return jsonAware;
            }
        } else {
            // Built-in data type processing
            if (value instanceof Date) {
                JSONObject dateObj = new JSONObject();
                dateObj.put("value", JSONObject.escape(value.toString()));
                dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date) value)));
                return dateObj;
            } else if (value instanceof List) {
                // Convert the List to a JSON list by recursively calling propertyToJSON
                List<Object> jsonList = new ArrayList<Object>(((List<Serializable>) value).size());
                for (Serializable listItem : (List<Serializable>) value) {
                    jsonList.add(propertyToJSON(nodeRef, propertyName, key, listItem));
                }
                return jsonList;
            } else if (value instanceof Double) {
                return (Double.isInfinite((Double) value) || Double.isNaN((Double) value) ? null
                        : value.toString());
            } else if (value instanceof Float) {
                return (Float.isInfinite((Float) value) || Float.isNaN((Float) value) ? null
                        : value.toString());
            } else {
                return value.toString();
            }
        }
    }
    return null;
}

From source file:org.apache.carbondata.core.scan.executor.util.RestructureUtil.java

/**
 * Method for computing measure default value based on the data type
 *
 * @param columnSchema/* ww w. ja  va2s  .  c o m*/
 * @param defaultValue
 * @return
 */
public static Object getMeasureDefaultValue(ColumnSchema columnSchema, byte[] defaultValue) {
    Object measureDefaultValue = null;
    if (!isDefaultValueNull(defaultValue)) {
        String value = null;
        switch (columnSchema.getDataType()) {
        case SHORT:
        case INT:
        case LONG:
            value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
            measureDefaultValue = Long.parseLong(value);
            break;
        case DECIMAL:
            BigDecimal decimal = DataTypeUtil.byteToBigDecimal(defaultValue);
            if (columnSchema.getScale() > decimal.scale()) {
                decimal = decimal.setScale(columnSchema.getScale(), RoundingMode.HALF_UP);
            }
            measureDefaultValue = decimal;
            break;
        default:
            value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET));
            Double parsedValue = Double.valueOf(value);
            if (!Double.isInfinite(parsedValue) && !Double.isNaN(parsedValue)) {
                measureDefaultValue = parsedValue;
            }
        }
    }
    return measureDefaultValue;
}

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

/**
 * Calculate minimum and maximum for a dataset
 *///from  w  w w  . jav  a  2s .c  om
protected void calculateHash() {
    IndexIterator iter = getIterator();
    double hash = 0;
    while (iter.hasNext()) {
        for (int j = 0; j < isize; j++) {
            final double val = getElementDoubleAbs(iter.index + j);
            if (Double.isInfinite(val) || Double.isNaN(val)) {
                hash = (hash * 19) % Integer.MAX_VALUE;
            } else {
                hash = (hash * 19 + val) % Integer.MAX_VALUE;
            }
        }
    }

    int ihash = ((int) hash) * 19 + getDType() * 17 + getElementsPerItem();
    setStoredValue(STORE_SHAPELESS_HASH, ihash);
}

From source file:net.sf.javaml.clustering.AQBC.java

private boolean exp_max(Vector<TaggedInstance> AS, double[] CK, double QUAL, double S) {

    double D = E - 2;
    double R = Math.sqrt(E - 1);
    // System.out.println("CK= "+Arrays.toString(CK));
    double[] RD = calculateDistances(AS, CK);
    // System.out.println("RD = "+Arrays.toString(RD));
    int samples = RD.length;
    int MAXITER = 500;
    double CDIF = 0.001;

    double count = 0;// float sum = 0;
    for (int i = 0; i < RD.length; i++) {
        if (RD[i] < QUAL) {
            count++;//from   ww  w  . j a v a  2 s. c o m
            // sum += RD[i];
        }
    }
    // System.out.println("count = "+count);
    // System.out.println("RD.length = "+RD.length);
    double PC = count / RD.length;// sum / RD.length;
    double PB = 1 - PC;
    // System.out.println("PC = "+PC);
    // System.out.println("PB = "+PB);
    double tmpVAR = 0;
    // double sum=0;
    for (int i = 0; i < RD.length; i++) {
        if (RD[i] < QUAL) {
            // sum += RD[i];
            tmpVAR += RD[i] * RD[i];
        }
    }

    // System.out.println("sum = "+sum);
    // System.out.println("tmpVAR = "+tmpVAR);
    double VAR = (1 / D) * tmpVAR / count;

    boolean CONV = false;
    for (int i = 0; i < MAXITER && !CONV; i++) {
        // System.out.println("\tEM iteration: "+i);
        // System.out.println("\tVAR = "+VAR);
        double[] prc = clusterdistrib(RD, VAR, D, R);
        // System.out.println("PRC = "+Arrays.toString(prc));
        double[] prb = background(RD, D, R);
        double[] prcpc = new double[prc.length];
        for (int j = 0; j < prc.length; j++) {
            prcpc[j] = prc[j] * PC;
        }
        double[] prbpb = new double[prb.length];
        for (int j = 0; j < prb.length; j++) {
            prbpb[j] = prb[j] * PB;
        }
        double[] pr = new double[prcpc.length];
        for (int j = 0; j < prc.length; j++) {
            pr[j] = prcpc[j] + prbpb[j];
        }
        double[] pcr = new double[prcpc.length];
        for (int j = 0; j < prc.length; j++) {
            pcr[j] = prcpc[j] / pr[j];
        }
        double SM = 0;
        for (int j = 0; j < prc.length; j++) {
            SM += pcr[j];
        }
        // System.out.println("\tSM = "+SM);
        if (MathUtils.eq(SM, 0) || Double.isInfinite(SM)) {
            i = MAXITER;// will return from loop
        }
        float tmpVAR_new = 0;
        for (int j = 0; j < prc.length; j++) {
            tmpVAR_new += RD[j] * RD[j] * pcr[j];
        }
        // System.out.println("tmpVAR_new = "+tmpVAR_new);
        double VAR_new = (1 / D) * tmpVAR_new / SM;
        // System.out.println("PCR = "+Arrays.toString(pcr));
        // System.out.println("\tVAR_new = "+VAR_new);
        // System.out.println("\tPC = "+PC);

        double PC_new = SM / samples;
        // System.out.println("\tPC_new = "+PC_new);
        double PB_new = 1 - PC_new;
        if (Math.abs(VAR_new - VAR) < CDIF && Math.abs(PC_new - PC) < CDIF) {
            CONV = true;
        }
        PC = PC_new;
        PB = PB_new;
        VAR = VAR_new;
    }

    if (CONV) {
        if (MathUtils.eq(PC, 0) || MathUtils.eq(PB, 0)) {
            System.out.println("EM: No or incorrect convergence! - PC==0 || PB==0");
            CONV = false;
            RADNW = 0;
            return false;
        }
        double SD = (2 * Math.pow(Math.PI, D / 2)) / (GammaFunction.gamma(D / 2));
        double SD1 = (2 * Math.pow(Math.PI, (D + 1) / 2)) / (GammaFunction.gamma((D + 1) / 2));
        // System.out.println("SD = "+SD);
        // System.out.println("SD1 = "+SD1);
        double CC = SD * (1 / (Math.pow(2 * Math.PI * VAR, D / 2)));
        double CB = (SD / (SD1 * Math.pow(Math.sqrt(D + 1), D)));
        double LO = (S / (1 - S)) * ((PB * CB) / (PC * CC));
        // System.out.println("PB = "+PB);
        // System.out.println("PC = "+PC);
        // System.out.println("S = "+S);
        // System.out.println("CC = "+CC);
        // System.out.println("CB = "+CB);
        // System.out.println("LO = "+LO);
        if (LO <= 0) {
            System.out.println("EM: Impossible to calculate radius - LO<0!");
            return false;
        }

        double DIS = -2 * VAR * Math.log(LO);
        // System.out.println("DIS = "+DIS);
        if (DIS <= 0) {
            System.out.println("EM: Impossible to calculate radius - DIS<0!");
            System.out.println();
            return false;
        }
        RADNW = (float) Math.sqrt(DIS);
        return true;
    } else {
        System.out.println("EM: No or incorrect convergence! Probably not enough iterations for EM");
        return false;
    }
}

From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

static boolean isDefined(double d) {
    return !(Double.isInfinite(d) || Double.isNaN(d)) && d > 0;
}