Example usage for java.lang Double POSITIVE_INFINITY

List of usage examples for java.lang Double POSITIVE_INFINITY

Introduction

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

Prototype

double POSITIVE_INFINITY

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

Click Source Link

Document

A constant holding the positive infinity of type double .

Usage

From source file:edu.uci.ics.jung.algorithms.scoring.DistanceCentralityScorer.java

/**
 * Calculates the score for the specified vertex.  Returns {@code null} if 
 * there are missing distances and such are not ignored by this instance.
 *///from  w w  w  .j a  v a  2  s .  c o  m
public Double getVertexScore(V v) {
    Double value = output.get(v);
    if (value != null) {
        if (value < 0)
            return null;
        return value;
    }

    Map<V, Number> v_distances = new HashMap<V, Number>(distance.getDistanceMap(v));
    if (ignore_self_distances)
        v_distances.remove(v);

    // if we don't ignore missing distances and there aren't enough
    // distances, output null (shortcut)
    if (!ignore_missing) {
        int num_dests = graph.getVertexCount() - (ignore_self_distances ? 1 : 0);
        if (v_distances.size() != num_dests) {
            output.put(v, -1.0);
            return null;
        }
    }

    Double sum = 0.0;
    for (V w : graph.getVertices()) {
        if (w.equals(v) && ignore_self_distances)
            continue;
        Number w_distance = v_distances.get(w);
        if (w_distance == null)
            if (ignore_missing)
                continue;
            else {
                output.put(v, -1.0);
                return null;
            }
        else
            sum += w_distance.doubleValue();
    }
    value = sum;
    if (averaging)
        value /= v_distances.size();

    double score = value == 0 ? Double.POSITIVE_INFINITY : 1.0 / value;
    output.put(v, score);

    return score;
}

From source file:edu.cudenver.bios.distribution.NonCentralFDistribution.java

/**
 * For this non-central F distribution, F, this function returns the critical value, f,
 * such that P(F < f)./* w  w  w  .  j ava 2  s. c om*/
 *
 * @param probability desired value of P(F < f)
 * @return critical f such that P(F < f)
 */
public double inverseCDF(double probability) {
    if (probability <= 0)
        return Double.NaN;
    if (probability >= 1)
        return Double.POSITIVE_INFINITY;

    if (method == FMethod.CDF && nonCentrality == 0) {
        // inverseCdf throws an illegal argument exception when the
        // non-centrality parameter is non-zero.  So we just bisection solve
        // unless we're really dealing with a central F.  Ah, the hazards of
        // pulling code off of the interwebs.
        return nonCentralF.inverseCdf(probability);
    } else {
        BisectionSolver solver = new BisectionSolver();

        NonCentralFQuantileFunction quantFunc = new NonCentralFQuantileFunction(probability);

        int upperBound = getCDFUpperBound(probability);
        try {
            return solver.solve(MAX_ITERATIONS, quantFunc, 0, upperBound);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to determine F quantile: " + e.getMessage());
        }
    }
}

From source file:com.opengamma.analytics.financial.model.finitedifference.CrankNicolsonFiniteDifference2D.java

@Override
public double[][] solve(final ConvectionDiffusion2DPDEDataBundle pdeData, final int tSteps, final int xSteps,
        final int ySteps, final double tMax, final BoundaryCondition2D xLowerBoundary,
        final BoundaryCondition2D xUpperBoundary, final BoundaryCondition2D yLowerBoundary,
        final BoundaryCondition2D yUpperBoundary, final Cube<Double, Double, Double, Double> freeBoundary) {

    final double dt = tMax / (tSteps);
    final double dx = (xUpperBoundary.getLevel() - xLowerBoundary.getLevel()) / (xSteps);
    final double dy = (yUpperBoundary.getLevel() - yLowerBoundary.getLevel()) / (ySteps);
    final double dtdx2 = dt / dx / dx;
    final double dtdx = dt / dx;
    final double dtdy2 = dt / dy / dy;
    final double dtdy = dt / dy;
    final double dtdxdy = dt / dy / dx;
    final int size = (xSteps + 1) * (ySteps + 1);

    final double[][] v = new double[xSteps + 1][ySteps + 1];
    final double[] u = new double[size];
    final double[] x = new double[xSteps + 1];
    final double[] y = new double[ySteps + 1];
    final double[] q = new double[size];

    double currentX = 0;
    double currentY = 0;
    int index;/*from ww w  .j a  va 2  s .  c  om*/

    for (int i = 0; i <= xSteps; i++) {
        currentX = xLowerBoundary.getLevel() + i * dx;
        x[i] = currentX;
    }
    for (int j = 0; j <= ySteps; j++) {
        currentY = yLowerBoundary.getLevel() + j * dy;
        y[j] = currentY;
        final int offset = j * (xSteps + 1);
        for (int i = 0; i <= xSteps; i++) {
            u[offset + i] = pdeData.getInitialValue(x[i], currentY);
        }
    }

    double t = 0.0;
    double a, b, c, d, e, f;
    final double[][] w = new double[size][9];

    for (int n = 0; n < tSteps; n++) {
        t += dt;

        for (int i = 1; i < xSteps; i++) {
            for (int j = 1; j < ySteps; j++) {
                index = j * (xSteps + 1) + i;
                a = pdeData.getA(t, x[i], y[j]);
                b = pdeData.getB(t, x[i], y[j]);
                c = pdeData.getC(t, x[i], y[j]);
                d = pdeData.getD(t, x[i], y[j]);
                e = pdeData.getE(t, x[i], y[j]);
                f = pdeData.getF(t, x[i], y[j]);

                double sum = 0;
                if (_theta != 1.0) {
                    sum -= a * dtdx2 * (u[index + 1] - 2 * u[index] + u[index - 1]);
                    sum -= b * dtdx / 2 * (u[index + 1] - u[index - 1]);
                    sum -= c * dt * u[index];
                    sum -= d * dtdy2 * (u[index + xSteps + 1] - 2 * u[index] + u[index - xSteps - 1]);
                    sum -= e * dtdxdy / 4 * (u[index + xSteps + 2] + u[index - xSteps - 2] - u[index - xSteps]
                            - u[index + xSteps]);
                    sum -= f * dtdy / 2 * (u[index + xSteps + 1] - u[index - xSteps - 1]);

                    // sum += dtdxdy * e / 4.0 * u[index - xSteps - 2];
                    // sum += (dtdy2 * d - 0.5 * dtdy * f) * u[index - xSteps - 1];
                    // sum += -dtdxdy * e / 4.0 * u[index - xSteps];
                    // sum += (dtdx2 * a - 0.5 * dtdx * b) * u[index - 1];
                    // sum += -(2 * dtdx2 * a - dt * c) - (2 * dtdy2 * d) * u[index];
                    // sum += (dtdx2 * a + 0.5 * dtdx * b) * u[index + 1];
                    // sum += -dtdxdy * e / 4.0 * u[index + xSteps];
                    // sum += (dtdy2 * d + 0.5 * dtdy * f) * u[index + xSteps + 1];
                    // sum += dtdxdy * e / 4.0 * u[index + xSteps + 2];
                    sum *= (1 - _theta);
                }
                sum += u[index];

                // sum = v[i][j];

                q[index] = sum;

                w[index][0] = _theta * dtdxdy * e / 4.0;
                w[index][1] = _theta * (dtdy2 * d - 0.5 * dtdy * f);
                w[index][2] = -_theta * dtdxdy * e / 4.0;

                w[index][3] = _theta * (dtdx2 * a - 0.5 * dtdx * b);
                w[index][4] = 1 - _theta * ((2 * dtdx2 * a - dt * c) + (2 * dtdy2 * d));
                w[index][5] = _theta * (dtdx2 * a + 0.5 * dtdx * b);

                w[index][6] = -_theta * dtdxdy * e / 4.0;
                w[index][7] = _theta * (dtdy2 * d + 0.5 * dtdy * f);
                w[index][8] = _theta * dtdxdy * e / 4.0;

            }
        }

        // The y boundary conditions
        final double[][][] yBoundary = new double[2][xSteps + 1][];

        for (int i = 0; i <= xSteps; i++) {
            yBoundary[0][i] = yLowerBoundary.getLeftMatrixCondition(t, x[i]);
            yBoundary[1][i] = yUpperBoundary.getLeftMatrixCondition(t, x[i]);

            double[] temp = yLowerBoundary.getRightMatrixCondition(t, x[i]);
            double sum = 0;
            for (int k = 0; k < temp.length; k++) {
                final int offset = k * (xSteps + 1);
                sum += temp[k] * u[offset + i];
            }
            q[i] = sum + yLowerBoundary.getConstant(t, x[i], dy);

            temp = yUpperBoundary.getRightMatrixCondition(t, x[i]);
            sum = 0;
            for (int k = 0; k < temp.length; k++) {
                final int offset = (ySteps - k) * (xSteps + 1);
                sum += temp[k] * u[offset + i];
            }
            q[i + ySteps * (xSteps + 1)] = sum + yUpperBoundary.getConstant(t, x[i], dy);
        }

        // The x boundary conditions
        final double[][][] xBoundary = new double[2][ySteps - 1][];

        for (int j = 1; j < ySteps; j++) {
            xBoundary[0][j - 1] = xLowerBoundary.getLeftMatrixCondition(t, y[j]);
            xBoundary[1][j - 1] = xUpperBoundary.getLeftMatrixCondition(t, y[j]);

            double[] temp = xLowerBoundary.getRightMatrixCondition(t, y[j]);
            int offset = j * (xSteps + 1);
            double sum = 0;
            for (int k = 0; k < temp.length; k++) {
                sum += temp[k] * u[offset + k];
            }
            q[offset] = sum + xLowerBoundary.getConstant(t, y[j], dx);

            temp = xUpperBoundary.getRightMatrixCondition(t, y[j]);
            offset = (j + 1) * (xSteps + 1) - 1;
            sum = 0;
            for (int k = 0; k < temp.length; k++) {
                sum += temp[k] * u[offset - k];
            }
            q[offset] = sum + xUpperBoundary.getConstant(t, y[j], dx);
        }

        // SOR
        final double omega = 1.0;
        double scale = 1.0;
        double errorSqr = Double.POSITIVE_INFINITY;
        double sum;
        int l;
        while (errorSqr / (scale + 1e-10) > 1e-18) {
            errorSqr = 0.0;
            scale = 0.0;
            // solve for the innards first
            for (int i = 1; i < xSteps; i++) {
                for (int j = 1; j < ySteps; j++) {
                    l = j * (xSteps + 1) + i;
                    sum = 0;
                    sum += w[l][0] * u[l - xSteps - 2];
                    sum += w[l][1] * u[l - xSteps - 1];
                    sum += w[l][2] * u[l - xSteps];
                    sum += w[l][3] * u[l - 1];
                    sum += w[l][4] * u[l];
                    sum += w[l][5] * u[l + 1];
                    sum += w[l][6] * u[l + xSteps];
                    sum += w[l][7] * u[l + xSteps + 1];
                    sum += w[l][8] * u[l + xSteps + 2];

                    final double correction = omega / w[l][4] * (q[l] - sum);
                    // if (freeBoundary != null) {
                    // correction = Math.max(correction, freeBoundary.getZValue(t, x[j]) - f[j]);
                    // }
                    errorSqr += correction * correction;
                    u[l] += correction;
                    scale += u[l] * u[l];
                }
            }

            // the lower y boundary
            for (int i = 0; i <= xSteps; i++) {
                sum = 0;
                l = i;
                final double[] temp = yBoundary[0][i];
                for (int k = 0; k < temp.length; k++) {
                    final int offset = k * (xSteps + 1);
                    sum += temp[k] * u[offset + i];
                }
                final double correction = omega / temp[0] * (q[l] - sum);
                errorSqr += correction * correction;
                u[l] += correction;
                scale += u[l] * u[l];
            }

            // the upper y boundary
            for (int i = 0; i <= xSteps; i++) {
                sum = 0;
                l = (xSteps + 1) * ySteps + i;
                final double[] temp = yBoundary[1][i];
                for (int k = 0; k < temp.length; k++) {
                    final int offset = (ySteps - k) * (xSteps + 1);
                    sum += temp[k] * u[offset + i];
                }
                final double correction = omega / temp[0] * (q[l] - sum);
                errorSqr += correction * correction;
                u[l] += correction;
                scale += u[l] * u[l];
            }

            // the lower x boundary
            for (int j = 1; j < ySteps; j++) {
                sum = 0;
                l = j * (xSteps + 1);
                final double[] temp = xBoundary[0][j - 1];
                for (int k = 0; k < temp.length; k++) {
                    sum += temp[k] * u[l + k];
                }
                final double correction = omega / temp[0] * (q[l] - sum);
                errorSqr += correction * correction;
                u[l] += correction;
                scale += u[l] * u[l];
            }

            // the upper x boundary
            for (int j = 1; j < ySteps; j++) {
                sum = 0;
                l = (j + 1) * (xSteps + 1) - 1;
                final double[] temp = xBoundary[1][j - 1];
                for (int k = 0; k < temp.length; k++) {
                    sum += temp[k] * u[l - k];
                }
                final double correction = omega / temp[0] * (q[l] - sum);
                errorSqr += correction * correction;
                u[l] += correction;
                scale += u[l] * u[l];
            }

        } // end of SOR

    } // time loop

    // unpack vector to matrix
    for (int j = 0; j <= ySteps; j++) {
        final int offset = j * (xSteps + 1);
        for (int i = 0; i <= xSteps; i++) {
            v[i][j] = u[offset + i];
        }
    }
    return v;

}

From source file:ml.shifu.shifu.core.pmml.builder.impl.ModelStatsCreator.java

/**
 * Create @ConStats for numerical variable
 * /*from  ww w.j av a  2s. com*/
 * @param columnConfig
 *            - ColumnConfig to generate ConStats
 * @return ConStats for variable
 */
private ContStats createConStats(ColumnConfig columnConfig) {
    ContStats conStats = new ContStats();

    List<Interval> intervals = new ArrayList<Interval>();
    for (int i = 0; i < columnConfig.getBinBoundary().size(); i++) {
        Interval interval = new Interval();
        interval.setClosure(Interval.Closure.OPEN_CLOSED);
        interval.setLeftMargin(columnConfig.getBinBoundary().get(i));

        if (i == columnConfig.getBinBoundary().size() - 1) {
            interval.setRightMargin(Double.POSITIVE_INFINITY);
        } else {
            interval.setRightMargin(columnConfig.getBinBoundary().get(i + 1));
        }

        intervals.add(interval);
    }
    conStats.addIntervals(intervals.toArray(new Interval[intervals.size()]));

    Map<String, String> extensionMap = new HashMap<String, String>();

    extensionMap.put("BinCountPos", columnConfig.getBinCountPos().toString());
    extensionMap.put("BinCountNeg", columnConfig.getBinCountNeg().toString());
    extensionMap.put("BinWeightedCountPos", columnConfig.getBinWeightedPos().toString());
    extensionMap.put("BinWeightedCountNeg", columnConfig.getBinWeightedNeg().toString());
    extensionMap.put("BinPosRate", columnConfig.getBinPosRate().toString());
    extensionMap.put("BinWOE",
            calculateWoe(columnConfig.getBinCountPos(), columnConfig.getBinCountNeg()).toString());
    extensionMap.put("KS", Double.toString(columnConfig.getKs()));
    extensionMap.put("IV", Double.toString(columnConfig.getIv()));
    List<Extension> extensions = createExtensions(extensionMap);
    conStats.addExtensions(extensions.toArray(new Extension[extensions.size()]));
    return conStats;
}

From source file:it.unibo.alchemist.model.ProtelisIncarnation.java

@Override
public TimeDistribution<Object> createTimeDistribution(final RandomGenerator rand,
        final Environment<Object> env, final Node<Object> node, final String param) {
    if (param == null) {
        return new ExponentialTime<>(Double.POSITIVE_INFINITY, rand);
    }//from   w w w  .j  av  a  2s  .c om
    double frequency;
    try {
        frequency = Double.parseDouble(param);
    } catch (final NumberFormatException e) {
        frequency = 1;
    }
    return new DiracComb<>(new DoubleTime(rand.nextDouble() / frequency), frequency);
}

From source file:com.clust4j.utils.MatTests.java

@Test
public void testPosInf() {
    final double[][] data = new double[][] { new double[] { 0.000, 0.000, 0.000 },
            new double[] { 1.000, Double.POSITIVE_INFINITY, 1.000 }, new double[] { 3.000, 3.000, 3.000 } };

    assertTrue(MatUtils.containsInf(data));
}

From source file:fr.cs.examples.bodies.Phasing.java

private void run(final File input)
        throws IOException, IllegalArgumentException, ParseException, OrekitException {

    // read input parameters
    KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
    parser.parseInput(new FileInputStream(input));
    TimeScale utc = TimeScalesFactory.getUTC();

    // simulation properties
    AbsoluteDate date = parser.getDate(ParameterKey.ORBIT_DATE, utc);
    int nbOrbits = parser.getInt(ParameterKey.PHASING_ORBITS_NUMBER);
    int nbDays = parser.getInt(ParameterKey.PHASING_DAYS_NUMBER);
    double latitude = parser.getAngle(ParameterKey.SUN_SYNCHRONOUS_REFERENCE_LATITUDE);
    boolean ascending = parser.getBoolean(ParameterKey.SUN_SYNCHRONOUS_REFERENCE_ASCENDING);
    double mst = parser.getTime(ParameterKey.SUN_SYNCHRONOUS_MEAN_SOLAR_TIME).getSecondsInDay() / 3600;
    int degree = parser.getInt(ParameterKey.GRAVITY_FIELD_DEGREE);
    int order = parser.getInt(ParameterKey.GRAVITY_FIELD_ORDER);
    String gridOutput = parser.getString(ParameterKey.GRID_OUTPUT);
    double[] gridLatitudes = new double[] { parser.getAngle(ParameterKey.GRID_LATITUDE_1),
            parser.getAngle(ParameterKey.GRID_LATITUDE_2), parser.getAngle(ParameterKey.GRID_LATITUDE_3),
            parser.getAngle(ParameterKey.GRID_LATITUDE_4), parser.getAngle(ParameterKey.GRID_LATITUDE_5) };
    boolean[] gridAscending = new boolean[] { parser.getBoolean(ParameterKey.GRID_ASCENDING_1),
            parser.getBoolean(ParameterKey.GRID_ASCENDING_2), parser.getBoolean(ParameterKey.GRID_ASCENDING_3),
            parser.getBoolean(ParameterKey.GRID_ASCENDING_4),
            parser.getBoolean(ParameterKey.GRID_ASCENDING_5) };

    gravityField = GravityFieldFactory.getNormalizedProvider(degree, order);

    // initial guess for orbit
    CircularOrbit orbit = guessOrbit(date, FramesFactory.getEME2000(), nbOrbits, nbDays, latitude, ascending,
            mst);//w  w  w.  j a  v  a 2 s. c o m
    System.out.println("initial orbit: " + orbit);
    System.out.println("please wait while orbit is adjusted...");
    System.out.println();

    // numerical model for improving orbit
    double[][] tolerances = NumericalPropagator.tolerances(0.1, orbit, OrbitType.CIRCULAR);
    DormandPrince853Integrator integrator = new DormandPrince853Integrator(1.0e-4 * orbit.getKeplerianPeriod(),
            1.0e-1 * orbit.getKeplerianPeriod(), tolerances[0], tolerances[1]);
    integrator.setInitialStepSize(1.0e-2 * orbit.getKeplerianPeriod());
    NumericalPropagator propagator = new NumericalPropagator(integrator);
    propagator.addForceModel(new HolmesFeatherstoneAttractionModel(
            FramesFactory.getGTOD(IERSConventions.IERS_2010, true), gravityField));
    propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getSun()));
    propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getMoon()));

    double deltaP = Double.POSITIVE_INFINITY;
    double deltaV = Double.POSITIVE_INFINITY;

    int counter = 0;
    DecimalFormat f = new DecimalFormat("0.000E00", new DecimalFormatSymbols(Locale.US));
    while (deltaP > 3.0e-1 || deltaV > 3.0e-4) {

        CircularOrbit previous = orbit;

        CircularOrbit tmp1 = improveEarthPhasing(previous, nbOrbits, nbDays, propagator);
        CircularOrbit tmp2 = improveSunSynchronization(tmp1, nbOrbits * tmp1.getKeplerianPeriod(), latitude,
                ascending, mst, propagator);
        orbit = improveFrozenEccentricity(tmp2, nbOrbits * tmp2.getKeplerianPeriod(), propagator);
        double da = orbit.getA() - previous.getA();
        double dex = orbit.getCircularEx() - previous.getCircularEx();
        double dey = orbit.getCircularEy() - previous.getCircularEy();
        double di = FastMath.toDegrees(orbit.getI() - previous.getI());
        double dr = FastMath.toDegrees(
                orbit.getRightAscensionOfAscendingNode() - previous.getRightAscensionOfAscendingNode());
        System.out.println(" iteration " + (++counter) + ": deltaA = " + f.format(da) + " m, deltaEx = "
                + f.format(dex) + ", deltaEy = " + f.format(dey) + ", deltaI = " + f.format(di)
                + " deg, deltaRAAN = " + f.format(dr) + " deg");

        PVCoordinates delta = new PVCoordinates(previous.getPVCoordinates(), orbit.getPVCoordinates());
        deltaP = delta.getPosition().getNorm();
        deltaV = delta.getVelocity().getNorm();

    }

    // final orbit
    System.out.println();
    System.out.println("final orbit (osculating): " + orbit);

    // generate the ground track grid file
    PrintStream output = new PrintStream(new File(input.getParent(), gridOutput));
    for (int i = 0; i < gridLatitudes.length; ++i) {
        printGridPoints(output, gridLatitudes[i], gridAscending[i], orbit, propagator, nbOrbits);
    }
    output.close();

}

From source file:com.kenshoo.freemarker.util.DataModelParser.java

private static Object parseValue(String value, TimeZone timeZone) throws DataModelParsingException {
    // Note: Because we fall back to interpret the input as a literal string value when it doesn't look like
    // anything else (like a number, boolean, etc.), it's important to avoid misunderstandings, and throw exception
    // in suspicious situations. The user can always quote the string value if we are "too smart". But he will
    // be confused about the rules of FreeMarker if what he believes to be a non-string is misinterpreted by this
    // parser as a string. Getting sometimes an error and then quoting the string is better than that.

    if (value.endsWith(";")) { // Tolerate this habit of Java and JavaScript programmers
        value = value.substring(value.length() - 1).trim();
    }/*from w w w  .jav a2s  . com*/

    if (NUMBER_LIKE.matcher(value).matches()) {
        try {
            return new BigDecimal(value);
        } catch (NumberFormatException e) {
            // Maybe it's a ISO 8601 Date/time/datetime
            CalendarFieldsToDateConverter calToDateConverter = new TrivialCalendarFieldsToDateConverter();

            DateParseException attemptedTemportalPExc = null;
            String attemptedTemporalType = null;
            final int dashIdx = value.indexOf('-');
            final int colonIdx = value.indexOf(':');
            if (value.indexOf('T') > 1 || (dashIdx > 1 && colonIdx > dashIdx)) {
                try {
                    return new Timestamp(
                            DateUtil.parseISO8601DateTime(value, timeZone, calToDateConverter).getTime());
                } catch (DateParseException pExc) {
                    attemptedTemporalType = "date-time";
                    attemptedTemportalPExc = pExc;
                }
            } else if (dashIdx > 1) {
                try {
                    return new java.sql.Date(
                            DateUtil.parseISO8601Date(value, timeZone, calToDateConverter).getTime());
                } catch (DateParseException pExc) {
                    attemptedTemporalType = "date";
                    attemptedTemportalPExc = pExc;
                }
            } else if (colonIdx > 1) {
                try {
                    return new Time(DateUtil.parseISO8601Time(value, timeZone, calToDateConverter).getTime());
                } catch (DateParseException pExc) {
                    attemptedTemporalType = "time";
                    attemptedTemportalPExc = pExc;
                }
            }
            if (attemptedTemportalPExc == null) {
                throw new DataModelParsingException("Malformed number: " + value, e);
            } else {
                throw new DataModelParsingException("Malformed ISO 8601 " + attemptedTemporalType
                        + " (or malformed number): " + attemptedTemportalPExc.getMessage(), e.getCause());
            }
        }
    } else if (value.startsWith("\"")) {
        try {
            return JSON_MAPPER.readValue(value, String.class);
        } catch (IOException e) {
            throw new DataModelParsingException(
                    "Malformed quoted string (using JSON syntax): " + getMessageWithoutLocation(e), e);
        }
    } else if (value.startsWith("\'")) {
        throw new DataModelParsingException(
                "Malformed quoted string (using JSON syntax): Use \" character for quotation, not \' character.");
    } else if (value.startsWith("[")) {
        try {
            return JSON_MAPPER.readValue(value, List.class);
        } catch (IOException e) {
            throw new DataModelParsingException(
                    "Malformed list (using JSON syntax): " + getMessageWithoutLocation(e), e);
        }
    } else if (value.startsWith("{")) {
        try {
            return JSON_MAPPER.readValue(value, LinkedHashMap.class);
        } catch (IOException e) {
            throw new DataModelParsingException(
                    "Malformed list (using JSON syntax): " + getMessageWithoutLocation(e), e);
        }
    } else if (value.startsWith("<")) {
        try {
            DocumentBuilder builder = NodeModel.getDocumentBuilderFactory().newDocumentBuilder();
            ErrorHandler errorHandler = NodeModel.getErrorHandler();
            if (errorHandler != null)
                builder.setErrorHandler(errorHandler);
            final Document doc = builder.parse(new InputSource(new StringReader(value)));
            NodeModel.simplify(doc);
            return doc;
        } catch (SAXException e) {
            final String saxMsg = e.getMessage();
            throw new DataModelParsingException("Malformed XML: " + (saxMsg != null ? saxMsg : e), e);
        } catch (Exception e) {
            throw new DataModelParsingException("XML parsing has failed with internal error: " + e, e);
        }
    } else if (value.equalsIgnoreCase(KEYWORD_TRUE)) {
        checkKeywordCase(value, KEYWORD_TRUE);
        return Boolean.TRUE;
    } else if (value.equalsIgnoreCase(KEYWORD_FALSE)) {
        checkKeywordCase(value, KEYWORD_FALSE);
        return Boolean.FALSE;
    } else if (value.equalsIgnoreCase(KEYWORD_NULL)) {
        checkKeywordCase(value, KEYWORD_NULL);
        return null;
    } else if (value.equalsIgnoreCase(KEYWORD_NAN)) {
        checkKeywordCase(value, KEYWORD_NAN);
        return Double.NaN;
    } else if (value.equalsIgnoreCase(KEYWORD_INFINITY)) {
        checkKeywordCase(value, KEYWORD_INFINITY);
        return Double.POSITIVE_INFINITY;
    } else if (value.equalsIgnoreCase(KEYWORD_POSITIVE_INFINITY)) {
        checkKeywordCase(value, KEYWORD_POSITIVE_INFINITY);
        return Double.POSITIVE_INFINITY;
    } else if (value.equalsIgnoreCase(KEYWORD_NEGATIVE_INFINITY)) {
        checkKeywordCase(value, KEYWORD_NEGATIVE_INFINITY);
        return Double.NEGATIVE_INFINITY;
    } else if (value.length() == 0) {
        throw new DataModelParsingException(
                "Empty value. (If you indeed wanted a 0 length string, quote it, like \"\".)");
    } else {
        return value;
    }
}

From source file:com.linkedin.pinot.query.aggregation.DefaultAggregationExecutorTest.java

/**
 * Helper method to compute min of a given array of values.
 * @param values/*w w w .ja  v a  2  s.com*/
 * @return
 */
private double computeMin(double[] values) {
    double min = Double.POSITIVE_INFINITY;
    for (int i = 0; i < values.length; i++) {
        min = Math.min(min, values[i]);
    }
    return min;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.algorithm.DBEA.java

/**
 * Initializes the ideal point and intercepts based on the bounds of the
 * initial population./*ww  w.  ja  va2 s. c  om*/
 */
void initializeIdealPointAndIntercepts() {
    idealPoint = new double[problem.getNumberOfObjectives()];
    intercepts = new double[problem.getNumberOfObjectives()];

    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
        idealPoint[i] = Double.POSITIVE_INFINITY;
        intercepts[i] = Double.NEGATIVE_INFINITY;
    }

    Population feasibleSolutions = getFeasibleSolutions(population);

    if (!feasibleSolutions.isEmpty()) {
        for (int i = 0; i < feasibleSolutions.size(); i++) {
            for (int j = 0; j < problem.getNumberOfObjectives(); j++) {
                idealPoint[j] = Math.min(idealPoint[j], feasibleSolutions.get(i).getObjective(j));
                intercepts[j] = Math.max(intercepts[j], feasibleSolutions.get(i).getObjective(j));
            }
        }
    }
}