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:com.analog.lyric.dimple.solvers.core.parameterizedMessages.GammaParameters.java

@Override
public double evalEnergy(Value value) {
    final double x = value.getDouble();
    if (x < 0) {
        return Double.POSITIVE_INFINITY;
    }//  ww w  . j  a  va2  s  .  com

    if (_alphaMinusOne == 0.0) {
        return x * _beta;
    } else {
        return x * _beta - Math.log(x) * _alphaMinusOne;
    }
}

From source file:eu.amidst.core.utils.Utils.java

/**
 * Returns the index of the minimum element in a given vector.
 * @param vector a {@link Vector} object.
 * @return an {@code int} that represents the index of the minimum element in the vector.
 *//*ww  w . j  a va  2  s . co  m*/
public static int minIndex(Vector vector) {
    double min = Double.POSITIVE_INFINITY;
    int index = -1;
    for (int i = 0; i < vector.size(); i++) {
        if (vector.get(i) < min) {
            min = vector.get(i);
            index = i;
        }
    }
    if (index == -1)
        throw new IllegalStateException("There is no maximum. Probably a NaN value.");

    return index;
}

From source file:zipkin.autoconfigure.metrics.PrometheusMetricsAutoConfiguration.java

private String prometheusDouble(double value) {
    if (value == Double.POSITIVE_INFINITY) {
        return "+Inf";
    } else if (value == Double.NEGATIVE_INFINITY) {
        return "-Inf";
    } else {//  w  w w. j  av a  2  s.  co  m
        return String.valueOf(value);
    }
}

From source file:mase.evorbc.KdTreeRepertoire.java

@Override
public void load(File repo, File coordinates) throws IOException {
    repFile = repo;//from   ww w . jav a 2 s .c o m
    repFileHash = FileUtils.checksumCRC32(repFile);
    if (coordinates != null) {
        coordsFile = coordinates;
        coordsFileHash = FileUtils.checksumCRC32(coordsFile);
    }

    List<PersistentSolution> solutions;
    try {
        solutions = SolutionPersistence.readSolutionsFromTar(repo);
    } catch (Exception ex) {
        Logger.getLogger(ArbitratorFactory.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }

    Map<Integer, double[]> coords = null;
    if (coordinates != null) {
        coords = fileCoordinates(coordinates);
        if (coords.size() != solutions.size()) {
            throw new IOException("Number of solutions in repertoire does not match number of coordinates");
        }
    } else {
        coords = encodedCoordinates(solutions);
    }

    int n = coords.get(solutions.get(0).getIndex()).length;

    bounds = new Pair[n];
    for (int i = 0; i < n; i++) {
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        for (double[] c : coords.values()) {
            min = Math.min(min, c[i]);
            max = Math.max(max, c[i]);
        }
        bounds[i] = Pair.of(min, max);
    }

    tree = new KdTree.Euclidean<>(n);
    for (int i = 0; i < solutions.size(); i++) {
        PersistentSolution sol = solutions.get(i);
        AgentController ac = sol.getController().getAgentControllers(1)[0];
        double[] c = coords.get(sol.getIndex());
        if (c == null) {
            throw new IOException("Coordinate not found for index " + sol.getIndex());
        }
        tree.addPoint(c, ac);
    }
}

From source file:com.analog.lyric.dimple.factorfunctions.NegativeExpGamma.java

@Override
public final double evalEnergy(Value[] arguments) {
    int index = 0;
    if (!_parametersConstant) {
        _alpha = arguments[index++].getDouble(); // First input is alpha parameter (must be non-negative)
        if (_alpha <= 0)
            return Double.POSITIVE_INFINITY;
        _beta = arguments[index++].getDouble(); // Second input is beta parameter (must be non-negative)
        if (_beta <= 0)
            return Double.POSITIVE_INFINITY;
        _alphaMinusOne = _alpha - 1;/* w w w .  j  ava2 s. c  o m*/
        _logGammaAlphaMinusAlphaLogBeta = org.apache.commons.math3.special.Gamma.logGamma(_alpha)
                - _alpha * Math.log(_beta);
    }
    final int length = arguments.length;
    final int N = length - index; // Number of non-parameter variables
    double sum = 0;
    for (; index < length; index++) {
        final double x = arguments[index].getDouble(); // Remaining inputs are NegativeExpGamma variables
        sum += x * _alphaMinusOne + Math.exp(-x) * _beta;
    }
    return sum + N * _logGammaAlphaMinusAlphaLogBeta;
}

From source file:at.pcgamingfreaks.Utils.java

/**
 * This function calculates the distance between two players.
 * Unlike Bukkit's built in function this will not cause an exception if the players aren't in the same world but return {@link Double#POSITIVE_INFINITY}.
 *
 * @param player1 The first player.//from ww w.j  a v  a 2 s. c o  m
 * @param player2 The second player.
 * @return The distance between the players. {@link Double#POSITIVE_INFINITY} if the players aren't in the same world.
 */
public static double getDistance(@NotNull Player player1, @NotNull Player player2) {
    if (player1.equals(player2)) {
        return 0;
    }
    if (player1.getWorld().getName().equalsIgnoreCase(player2.getWorld().getName())) {
        return player1.getLocation().distance(player2.getLocation());
    }
    return Double.POSITIVE_INFINITY;
}

From source file:statistic.graph.gui.Charts.java

private static void initXAxis(XYPlot plot, XYDataset dataset) {
    plot.setDomainAxis(new NumberAxis(plot.getDomainAxis().getLabel()));
    XYSeriesCollection collection = (XYSeriesCollection) dataset;
    double max = Double.NEGATIVE_INFINITY;
    double min = Double.POSITIVE_INFINITY;
    if (collection != null) {
        for (int s = 0; s < collection.getSeriesCount(); s++) {
            for (int d = 0; d < collection.getItemCount(s); d++) {
                XYDataItem data = collection.getSeries(s).getDataItem(d);
                if (data.getX().longValue() == Integer.MAX_VALUE
                        || data.getX().longValue() == Integer.MIN_VALUE) {
                    continue;
                }/*from   w ww .  j a v a 2s. c o m*/
                if (data.getX().doubleValue() > max) {
                    max = data.getX().doubleValue();
                }
                if (data.getX().doubleValue() < min) {
                    min = data.getX().doubleValue();
                }
            }
        }
        if (min < max) {
            plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            plot.getDomainAxis().setRange(min - 0.5, max + 0.5);
            for (int s = 0; s < collection.getSeriesCount(); s++) {
                XYSeries series = collection.getSeries(s);
                if (series.indexOf(Integer.MIN_VALUE) >= 0) {
                    XYDataItem item = series.remove((Number) Integer.MIN_VALUE);
                    if (series.indexOf(min) < 0) {
                        series.add(min, item.getY());
                    }
                }
                if (series.indexOf(Integer.MAX_VALUE) >= 0) {
                    XYDataItem item = series.remove((Number) Integer.MAX_VALUE);
                    if (series.indexOf(max) < 0) {
                        series.add(max, item.getY());
                    }
                }
            }
        } else {
            plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5);
    }
}

From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.BetaParameters.java

@Override
public double evalEnergy(Value value) {
    final double x = value.getDouble();

    if (x < 0 | x > 1) {
        return Double.POSITIVE_INFINITY;
    }// w  w  w.  j a va 2  s .  c  o m

    double y;

    if (_alphaMinusOne == 0.0) {
        if (_betaMinusOne == 0.0) {
            return 0.0;
        } else {
            y = Math.log(1 - x) * _betaMinusOne;
        }
    } else if (_betaMinusOne == 0.0) {
        y = Math.log(x) * _alphaMinusOne;
    } else {
        y = _alphaMinusOne * Math.log(x) + _betaMinusOne * Math.log(1 - x);
    }

    return -y;
}

From source file:edu.cmu.tetrad.sem.SemOptimizerPowell.java

public void optimize(SemIm semIm) {
    double min = Double.POSITIVE_INFINITY;
    double[] point = null;

    for (int count = 0; count < numRestarts + 1; count++) {
        System.out.println("Trial " + (count + 1));
        SemIm _sem2 = new SemIm(semIm);

        List<Parameter> freeParameters = _sem2.getFreeParameters();

        double[] p = new double[freeParameters.size()];

        for (int i = 0; i < freeParameters.size(); i++) {
            if (freeParameters.get(i).getType() == ParamType.VAR) {
                p[i] = RandomUtil.getInstance().nextUniform(0, 1);
            } else {
                p[i] = RandomUtil.getInstance().nextUniform(-1, 1);
            }/*from  w  w  w.  ja  va 2s  . com*/
        }

        _sem2.setFreeParamValues(p);

        MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);
        PointValuePair pair = search.optimize(new InitialGuess(_sem2.getFreeParamValues()),
                new ObjectiveFunction(fittingFunction(semIm)), GoalType.MINIMIZE, new MaxEval(100000));

        double chisq = _sem2.getChiSquare();
        System.out.println("chisq = " + chisq);

        if (chisq < min) {
            min = chisq;
            point = pair.getPoint();
        }
    }

    System.arraycopy(point, 0, semIm.getFreeParamValues(), 0, point.length);
}

From source file:com.cloudera.oryx.kmeans.common.Centers.java

/**
 * Returns the minimum squared Euclidean distance between the given
 * {@code Vector} and a point contained in this instance.
 * /* w w  w. j  av  a 2  s  .  c om*/
 * @param point The point
 * @return The minimum squared Euclidean distance from the point 
 */
public Distance getDistance(RealVector point) {
    double min = Double.POSITIVE_INFINITY;
    int index = -1;
    for (int i = 0; i < centers.size(); i++) {
        RealVector c = centers.get(i);
        double distance = c.getDistance(point);
        double distanceSquared = distance * distance;
        if (distanceSquared < min) {
            min = distanceSquared;
            index = i;
        }
        min = Math.min(min, distance * distance);
    }
    return new Distance(min, index);
}