Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

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

Prototype

double NaN

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

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type double .

Usage

From source file:edu.uci.ics.jung.algorithms.metrics.StructuralHoles.java

/**
 * Calculates the hierarchy value for a given vertex.  Returns <code>NaN</code> when
 * <code>v</code>'s degree is 0, and 1 when <code>v</code>'s degree is 1.
 * Formally://from   w  w  w .  j a  va  2s .c  om
 * <pre>
 * hierarchy(v) = (sum_{v in N(v), w != v} s(v,w) * log(s(v,w))}) / (v.degree() * Math.log(v.degree()) 
 * </pre>
 * where
 * <ul>
 * <li/><code>N(v) = v.getNeighbors()</code> 
 * <li/><code>s(v,w) = localConstraint(v,w) / (aggregateConstraint(v) / v.degree())</code>
 * </ul>
 * @see #localConstraint(Object, Object)
 * @see #aggregateConstraint(Object)
 */
public double hierarchy(V v) {
    double v_degree = g.degree(v);

    if (v_degree == 0)
        return Double.NaN;
    if (v_degree == 1)
        return 1;

    double v_constraint = aggregateConstraint(v);

    double numerator = 0;
    for (V w : g.getNeighbors(v)) {

        if (v != w) {
            double sl_constraint = localConstraint(v, w) / (v_constraint / v_degree);
            numerator += sl_constraint * Math.log(sl_constraint);
        }
    }

    return numerator / (v_degree * Math.log(v_degree));
}

From source file:egat.replicatordynamics.SymmetricConstrainedFeasibleAmoebaSearch.java

public Strategy run(Strategy initialStrategy, Set<Action> restrictedActions, boolean randomize,
        Action[] actions, PayoffMatrix pm) {

    boolean[] mask = new boolean[actions.length];

    int restrictedCount = 0;

    for (int i = 0; i < actions.length; i++) {

        mask[i] = restrictedActions.contains(actions[i]);

        if (mask[i]) {

            restrictedCount++;//  w w w  .ja v a 2s .  co  m

        }

    }

    int[] restricted = new int[restrictedCount];

    for (int i = 0, restrictedIndex = 0; i < actions.length; i++) {

        if (mask[i]) {

            restricted[restrictedIndex++] = i;

        }
    }

    // Normalize to a uniform distribution
    double[] distribution = new double[actions.length];

    double[] bestDist = new double[actions.length];

    if (initialStrategy == null) {
        double sum = 0.0;
        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] = Math.random();
                sum += bestDist[i];
            }
        }

        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] /= sum;
            }
        }

    } else {
        for (int i = 0; i < actions.length; i++) {
            if (mask[i]) {
                bestDist[i] = initialStrategy.getProbability(actions[i]).doubleValue();
            }
        }
    }

    double bestRegret = pm.regret(bestDist);

    // Initialize current strategy
    Strategy currentStrategy = buildStrategy(actions, bestDist, restricted);

    fireUpdatedStrategy(currentStrategy, 0, Double.NaN);

    int SIMPLICES = restricted.length;
    double[][] X = new double[SIMPLICES][SIMPLICES - 1];
    double[] centroid = new double[SIMPLICES - 1];
    double[] reflect = new double[SIMPLICES - 1];
    double[] expand = new double[SIMPLICES - 1];
    double[] contract = new double[SIMPLICES - 1];
    double[] V = new double[SIMPLICES];
    double[] cur = distribution.clone();

    if (!randomize) {
        for (int r = 0, n = SIMPLICES - 1; r < n; r++) {
            X[0][r] = 0.0;
        }

        V[0] = calculateObjective(pm, X[0], restricted, distribution);

        for (int s = 1; s < SIMPLICES; s++) {
            System.arraycopy(X[0], 0, X[s], 0, SIMPLICES - 1);

            X[s][s - 1] = 1.0;

            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    } else {

        for (int s = 0; s < SIMPLICES; s++) {
            generateSimplex(X[s]);
            V[s] = calculateObjective(pm, X[s], restricted, distribution);
        }
    }

    int highest = -1;
    int lowest = -1;
    int second = -1;

    for (int s = 0; s < SIMPLICES; s++) {
        if (lowest < 0 || V[s] < V[lowest]) {
            lowest = s;
        }

        if (second < 0 || V[s] > V[second]) {

            if (highest < 0 || V[s] > V[highest]) {
                second = highest;
                highest = s;
            } else {
                second = s;
            }

        }
    }

    double curRegret = Double.POSITIVE_INFINITY;

    loop: for (int iteration = 1; SIMPLICES > 1; iteration++) {

        generateCentroid(centroid, X, SIMPLICES, highest);

        generateFeasibleTowards(reflect, centroid, X[highest], 1.0, pm, restricted, distribution);

        double reflectV = calculateObjective(pm, reflect, restricted, distribution);

        // Reflect
        if (V[lowest] <= reflectV && reflectV < V[second]) {
            replaceHighest(reflect, reflectV, X, V, highest);

            // Expand
        } else if (reflectV < V[lowest]) {

            generateFeasibleTowards(expand, centroid, X[highest], 2.0, pm, restricted, distribution);

            double expandV = calculateObjective(pm, expand, restricted, distribution);

            if (expandV < reflectV) {
                replaceHighest(expand, expandV, X, V, highest);
            } else {
                replaceHighest(reflect, reflectV, X, V, highest);
            }

            // Contract
        } else {

            generateAway(contract, X[highest], centroid, 0.5);

            double contractV = calculateObjective(pm, contract, restricted, distribution);

            if (contractV < V[highest]) {
                replaceHighest(contract, contractV, X, V, highest);

                // Reduction
            } else {
                for (int s = 0; s < SIMPLICES; s++) {
                    if (s != lowest) {

                        generateAway(X[s], X[lowest], X[s], 0.5);

                        V[s] = calculateObjective(pm, X[s], restricted, distribution);
                    }
                }
            }
        }

        highest = -1;
        lowest = -1;
        second = -1;

        for (int s = 0; s < SIMPLICES; s++) {
            if (lowest < 0 || V[s] < V[lowest]) {
                lowest = s;
            }

            if (second < 0 || V[s] > V[second]) {

                if (highest < 0 || V[s] > V[highest]) {
                    second = highest;
                    highest = s;
                } else {
                    second = s;
                }

            }
        }

        Arrays.fill(cur, 0.0);
        double sum = 0.0;
        for (int r = 0; r < restricted.length - 1; r++) {
            cur[restricted[r]] = Math.max(0, X[lowest][r]);
            sum += cur[restricted[r]];
        }

        cur[restricted[restricted.length - 1]] = Math.max(0.0, 1 - sum);
        sum += cur[restricted[restricted.length - 1]];

        for (int r = 0; r < restricted.length; r++) {
            cur[restricted[r]] /= sum;
        }

        curRegret = pm.regret(cur);

        if (curRegret < bestRegret) {
            System.arraycopy(cur, 0, bestDist, 0, cur.length);
            bestRegret = curRegret;
        }

        // Build the new strategy
        currentStrategy = buildStrategy(actions, bestDist, restricted);

        fireUpdatedStrategy(currentStrategy, iteration, bestRegret);

        // Calculate the norm
        double norm = V[highest] - V[lowest];

        // Check termination condition
        if (terminate(norm, iteration))
            break;
    }

    return currentStrategy;
}

From source file:com.esri.geoevent.solutions.processor.geometry.PolygonProcessor.java

private com.esri.ges.spatial.Geometry constructCAPGeometry(String geoString) throws GeometryException {
    try {//  w ww  . j  a va 2s. c o m
        String[] pairs = geoString.split(" ");

        Polygon polygon = new Polygon();
        Boolean firstit = true;
        for (String coords : pairs) {

            String[] tuple = coords.split(",");
            Double x = Double.parseDouble(tuple[0]);
            Double y = Double.parseDouble(tuple[1]);
            Point p = new Point(x, y);
            Double z = Double.NaN;
            if (tuple.length > 2) {
                z = Double.parseDouble(tuple[2]);
                p.setZ(z);
            }
            if (firstit) {
                polygon.startPath(p);
                firstit = false;
            } else {
                polygon.lineTo(p);
            }
        }
        polygon.closeAllPaths();
        String json = GeometryEngine.geometryToJson(srIn, polygon);
        return spatial.fromJson(json);
    } catch (GeometryException ex) {
        LOG.error(ex.getMessage());
        LOG.error(ex.getStackTrace());
        return null;
    }
}

From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset.java

/**
 * Creates a new dataset./*from ww w.  jav  a2s.  c om*/
 */
public DefaultBoxAndWhiskerCategoryDataset() {
    this.data = new KeyedObjects2D();
    this.minimumRangeValue = Double.NaN;
    this.minimumRangeValueRow = -1;
    this.minimumRangeValueColumn = -1;
    this.maximumRangeValue = Double.NaN;
    this.maximumRangeValueRow = -1;
    this.maximumRangeValueColumn = -1;
}

From source file:it.unibo.alchemist.model.implementations.actions.LsaRandomNeighborAction.java

/**
 * Sets the synthetic variables.//w  w  w . j  a  v  a  2  s  .  co  m
 * 
 * @param node
 *            the node to use as reference (e.g. for computing the distance)
 */
protected void setSynthectics(final ILsaNode node) {
    /*
     * #D and #ROUTE
     */
    double d = initD || initRoute ? computeDistance(node) : Double.NaN;
    if (initD) {
        d = computeDistance(node);
        setSyntheticD(d);
    }
    if (initRoute) {
        if (mapEnv) {
            final Route<?> route = menv.computeRoute(getNode(), node);
            if (route != null) {
                final double dist = route.length();
                d = Math.max(d, dist);
            }
        }
        setSyntheticRoute(d);
    }
    /*
     * #NEIGH
     */
    if (initNeigh) {
        setSyntheticNeigh(env.getNeighborhood(node).getNeighbors());
    }
    /*
     * #O
     */
    if (initO) {
        setSyntheticO();
    }
}

From source file:com.itemanalysis.jmetrik.graph.density.DensityAnalysis.java

public XYSeriesCollection summarize() throws SQLException, IllegalArgumentException {
    Statement stmt = null;// w  w w  . j a  v a  2s  .c o  m
    ResultSet rs = null;
    TreeMap<String, ResizableDoubleArray> data = new TreeMap<String, ResizableDoubleArray>();

    //set progress bar information
    int nrow = 0;
    JmetrikPreferencesManager pref = new JmetrikPreferencesManager();
    String dbType = pref.getDatabaseType();
    if (DatabaseType.APACHE_DERBY.toString().equals(dbType)) {
        JmetrikDatabaseFactory dbFactory = new JmetrikDatabaseFactory(DatabaseType.APACHE_DERBY);
        nrow = dao.getRowCount(conn, tableName);
    } else {
        //add other databases here when functionality is added
    }
    maxProgress = (double) nrow;

    Table sqlTable = new Table(tableName.getNameForDatabase());
    SelectQuery select = new SelectQuery();
    select.addColumn(sqlTable, variable.getName().nameForDatabase());
    if (hasGroupingVariable)
        select.addColumn(sqlTable, groupVar.getName().nameForDatabase());
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs = stmt.executeQuery(select.toString());

    String conditionalName = "";
    ResizableDoubleArray cData = null;
    double value = Double.NaN;

    while (rs.next()) {
        if (groupVar != null) {
            String groupName = rs.getString(groupVar.getName().nameForDatabase());
            if (rs.wasNull()) {
                groupName = "";
            }
            conditionalName = groupName;
        } else {
            conditionalName = "Series 1";
        }

        cData = data.get(conditionalName);
        if (cData == null) {
            cData = new ResizableDoubleArray((int) maxProgress);
            data.put(conditionalName, cData);
        }
        value = rs.getDouble(variable.getName().nameForDatabase());
        if (!rs.wasNull()) {
            cData.addElement(value);
        }
        updateProgress();
    }
    rs.close();
    stmt.close();

    String kType = command.getSelectOneOption("kernel").getSelectedArgument();
    double adjustment = command.getFreeOption("adjust").getDouble();
    KernelFactory kernelFactory = new KernelFactory(kType);

    KernelFunction kernelFunction = kernelFactory.getKernelFunction();
    Bandwidth bandwidth = null;
    KernelDensity density = null;
    UniformDistributionApproximation uniform = null;
    Min min = new Min();
    Max max = new Max();
    double[] x = null;

    this.firePropertyChange("progress-ind-on", null, null);

    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    XYSeries series = null;
    for (String s : data.keySet()) {
        series = new XYSeries(s);
        x = data.get(s).getElements();
        bandwidth = new ScottsBandwidth(x, adjustment);
        uniform = new UniformDistributionApproximation(min.evaluate(x), max.evaluate(x), KERNEL_POINTS);
        density = new KernelDensity(kernelFunction, bandwidth, uniform);

        double[] dens = density.evaluate(x);
        double[] points = density.getPoints();
        for (int i = 0; i < dens.length; i++) {
            series.add(points[i], dens[i]);
        }
        seriesCollection.addSeries(series);
    }
    return seriesCollection;

}

From source file:egat.replicatordynamics.SymmetricConstrainedTransformedAmoebaSearch.java

public Strategy run(SymmetricGame game, Strategy initialStrategy, Set<Action> restrictedActions,
        boolean randomize) {

    Action[] actions = game.getActions().toArray(new Action[0]);

    boolean[] mask = new boolean[actions.length];

    int restrictedCount = 0;

    for (int i = 0; i < actions.length; i++) {

        mask[i] = restrictedActions.contains(actions[i]);

        if (mask[i]) {

            restrictedCount++;/*from   ww  w . ja  v a  2 s .com*/

        }

    }

    int[] restricted = new int[restrictedCount];

    for (int i = 0, restrictedIndex = 0; i < actions.length; i++) {

        if (mask[i]) {

            restricted[restrictedIndex++] = i;

        }
    }

    Player[] players = game.players().toArray(new Player[0]);

    PayoffMatrix pm = createPayoffMatrix(game, players, actions);

    // Normalize to a uniform distribution
    double[] distribution = new double[actions.length];

    double[] bestDist = new double[actions.length];

    if (initialStrategy == null) {
        double sum = 0.0;
        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] = Math.random();
                sum += bestDist[i];
            }
        }

        for (int i = 0; i < bestDist.length; i++) {
            if (mask[i]) {
                bestDist[i] /= sum;
            }
        }

    } else {
        for (int i = 0; i < actions.length; i++) {
            if (mask[i]) {
                bestDist[i] = initialStrategy.getProbability(actions[i]).doubleValue();
            }
        }
    }

    double bestRegret = pm.regret(bestDist);

    // Initialize current strategy
    Strategy currentStrategy = buildStrategy(actions, bestDist, restricted);

    fireUpdatedStrategy(currentStrategy, 0, Double.NaN);

    int SIMPLICES = restricted.length;
    double[][] X = new double[SIMPLICES][SIMPLICES];
    double[] centroid = new double[SIMPLICES];
    double[] reflect = new double[SIMPLICES];
    double[] expand = new double[SIMPLICES];
    double[] contract = new double[SIMPLICES];
    double[] V = new double[SIMPLICES];
    double[] cur = distribution.clone();

    if (!randomize) {
        for (int s = 0; s < SIMPLICES; s++) {
            X[s][s] = 1.0;
            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
        }
    } else {
        for (int s = 0; s < SIMPLICES; s++) {
            generateSimplex(X[s]);
            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
        }
    }

    int highest = -1;
    int lowest = -1;
    int second = -1;

    for (int s = 0; s < SIMPLICES; s++) {
        if (highest < 0 || V[s] > V[highest]) {
            highest = s;
        }

        if (second < 0 || V[s] < V[second]) {

            if (lowest < 0 || V[s] < V[lowest]) {
                second = lowest;
                lowest = s;
            } else {
                second = s;
            }
        }
    }

    double curRegret = Double.POSITIVE_INFINITY;

    loop: for (int iteration = 1; SIMPLICES > 1; iteration++) {

        for (int r = 0; r < SIMPLICES - 1; r++) {
            centroid[r] = 0.0;

            for (int s = 0; s < SIMPLICES; s++) {
                if (s != highest) {
                    centroid[r] += X[s][r];
                }
            }

            centroid[r] /= SIMPLICES - 1.0;
        }

        for (int r = 0; r < SIMPLICES - 1; r++) {
            reflect[r] = 2 * centroid[r] - X[highest][r];
        }

        double reflectV = calculateLagrangian(pm, reflect, restricted, distribution);

        // Reflect
        if (V[lowest] <= reflectV && reflectV < V[second]) {
            System.arraycopy(reflect, 0, X[highest], 0, SIMPLICES - 1);
            V[highest] = reflectV;
        } else {

            boolean shrink = false;

            // Expand
            if (reflectV < V[lowest]) {
                for (int r = 0; r < SIMPLICES - 1; r++) {
                    expand[r] = centroid[r] + 2.0 * (reflect[r] - centroid[r]);
                }

                double expandV = calculateLagrangian(pm, expand, restricted, distribution);

                if (expandV < reflectV) {
                    System.arraycopy(expand, 0, X[highest], 0, SIMPLICES - 1);
                    V[highest] = expandV;
                } else {
                    System.arraycopy(reflect, 0, X[highest], 0, SIMPLICES - 1);
                    V[highest] = reflectV;
                }

                // Contract
            } else if (reflectV >= V[second]) {

                //Outside
                if (V[highest] > reflectV) {
                    for (int r = 0; r < SIMPLICES - 1; r++) {
                        contract[r] = centroid[r] + 0.5 * (reflect[r] - centroid[r]);
                    }
                    double contractV = calculateLagrangian(pm, contract, restricted, distribution);

                    if (contractV < reflectV) {
                        System.arraycopy(contract, 0, X[highest], 0, SIMPLICES - 1);
                        V[highest] = contractV;
                    } else {
                        shrink = true;
                    }

                    //Inside
                } else {
                    for (int r = 0; r < SIMPLICES - 1; r++) {
                        contract[r] = centroid[r] + 0.5 * (X[highest][r] - centroid[r]);
                    }

                    double contractV = calculateLagrangian(pm, contract, restricted, distribution);

                    if (contractV < V[highest]) {
                        System.arraycopy(contract, 0, X[highest], 0, SIMPLICES - 1);
                        V[highest] = contractV;
                    } else {
                        shrink = true;
                    }
                }

                // Shrink
                if (shrink) {
                    for (int s = 0; s < SIMPLICES; s++) {
                        if (s != lowest) {
                            for (int r = 0; r < SIMPLICES - 1; r++) {
                                X[s][r] = X[lowest][r] + 0.5 * (X[s][r] - X[lowest][r]);
                            }

                            V[s] = calculateLagrangian(pm, X[s], restricted, distribution);
                        }
                    }
                }
            }
        }

        highest = -1;
        lowest = -1;
        second = -1;

        for (int s = 0; s < SIMPLICES; s++) {
            if (highest < 0 || V[s] > V[highest]) {
                highest = s;
            }

            if (second < 0 || V[s] < V[second]) {

                if (lowest < 0 || V[s] < V[lowest]) {
                    second = lowest;
                    lowest = s;
                } else {
                    second = s;
                }
            }
        }

        Arrays.fill(cur, 0.0);
        double sum = 0.0;
        for (int r = 0; r < restricted.length - 1; r++) {
            cur[restricted[r]] = Math.max(0, X[lowest][r]);
            sum += cur[restricted[r]];
        }

        cur[restricted[restricted.length - 1]] = Math.max(0.0, 1 - sum);
        sum += cur[restricted[restricted.length - 1]];

        for (int r = 0; r < restricted.length; r++) {
            cur[restricted[r]] /= sum;
        }

        curRegret = pm.regret(cur);

        if (curRegret < bestRegret) {
            System.arraycopy(cur, 0, bestDist, 0, cur.length);
            bestRegret = curRegret;
        }

        // Build the new strategy
        currentStrategy = buildStrategy(actions, bestDist, restricted);

        fireUpdatedStrategy(currentStrategy, iteration, bestRegret);

        // Calculate the norm
        double norm = V[highest] - V[lowest];

        // Check termination condition
        if (terminate(norm, iteration))
            break;
    }

    return currentStrategy;
}

From source file:com.nascent.android.glass.glasshackto.greenpfinder.model.GreenPSpots.java

/**
 * Converts a JSON object that represents a place into a {@link Place} object.
 *//*from  w ww  .ja  va 2  s.  c om*/
private ParkingLot jsonObjectToParkingLot(JSONObject object) {
    int id = object.optInt("id");
    String name = object.optString("address");
    String rate = object.optString("rate");
    double latitude = object.optDouble("lat", Double.NaN);
    double longitude = object.optDouble("lng", Double.NaN);

    if (!name.isEmpty() && !Double.isNaN(latitude) && !Double.isNaN(longitude)) {
        return new ParkingLot(id, latitude, longitude, name, rate);
    } else {
        return null;
    }
}

From source file:com.spotify.ffwd.json.JsonObjectMapperDecoder.java

private double decodeDouble(JsonNode tree, String name) {
    final JsonNode n = tree.get(name);

    if (n == null)
        return Double.NaN;

    return n.asDouble();
}

From source file:com.itemanalysis.psychometrics.measurement.ClassicalItemStatistics.java

public double getDIndex() {
    if (dIndex) {
        return upper.getResult() / -lower.getResult();
    } else {//from w  w w . j a v  a  2  s. c o  m
        return Double.NaN;
    }
}