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.facebook.presto.operator.aggregation.ApproximateUtils.java

/**
 * Computes the standard deviation for the random variable C = sum(1 / p * Bern(p))
 * <br /><br />//from   w  w w. ja  v a2  s  .c  o  m
 * Derivation:
 * <pre>
 * Var(C) = Var(sum(1 / p * Bern(p)))
 *        = sum(Var(1 / p * Bern(p)))   [Bienayme formula]
 *        = n * Var(1 / p * Bern(p))    [Bern(p) are iid]
 *        = n * 1 / p^2 * Var(Bern(p))  [1 / p is constant]
 *        = n * 1 / p^2 * p * (1 - p)   [Variance of a Bernoulli distribution]
 *        = n * (1 - p) / p
 *        = samples / p * (1 - p) / p   [samples = n * p, since it's only the observed rows]
 * </pre>
 * Therefore Stddev(C) = 1 / p * sqrt(samples * (1 - p))
 */
public static double countError(long samples, long count) {
    if (count == 0) {
        return Double.POSITIVE_INFINITY;
    }

    double p = samples / (double) count;
    double error = 1 / p * Math.sqrt(samples * (1 - p));
    return conservativeError(error, p, samples);
}

From source file:org.spf4j.perf.impl.chart.Charts.java

public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
        final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
    final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis,
            stepMillis);/*from  ww  w.  j a v a 2 s  .co m*/
    NumberAxis xAxis = new NumberAxis("Time");
    xAxis.setStandardTickUnits(dataSet.createXTickUnits());
    xAxis.setLowerMargin(0);
    xAxis.setUpperMargin(0);
    xAxis.setVerticalTickLabels(true);
    NumberAxis yAxis = new NumberAxis(uom);
    yAxis.setStandardTickUnits(dataSet.createYTickUnits());
    yAxis.setLowerMargin(0);
    yAxis.setUpperMargin(0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    PaintScale scale;
    if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
        if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
            scale = new InverseGrayScale(0, 1);
        } else {
            scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
        }
    } else {
        scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
    }
    renderer.setPaintScale(scale);
    renderer.setBlockWidth(1);
    renderer.setBlockHeight(1);
    XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);
    JFreeChart chart = new JFreeChart(chartName, plot);
    PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
    legend.setMargin(0, 5, 0, 5);
    chart.addSubtitle(legend);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:aos.creditassignment.setimprovement.MedianIndicatorImprovement.java

/**
 * Assumes that the offspring is the last index in the population. Returns
 * the difference between the mean fitness of the population and the
 * offspring fitness. If it is negative, it returns 0
 *
 * @param offspring solution that will receive credits
 * @param population the population to compare the offspring solutions with
 * @return the value of credit to resulting from the solution
 *///from  w  ww . j  ava 2 s  . c o  m
@Override
public double compute(Solution offspring, Population population) {

    double[] fitnessvals = new double[population.size()];
    double minFitness = Double.POSITIVE_INFINITY;
    double maxFitness = Double.NEGATIVE_INFINITY;
    //find sum of the fitness minus the offspring
    for (int i = 0; i < population.size() - 1; i++) {
        fitnessvals[i] = (double) population.get(i).getAttribute(FitnessEvaluator.FITNESS_ATTRIBUTE);
        minFitness = Math.min(minFitness, fitnessvals[i]);
        maxFitness = Math.max(maxFitness, fitnessvals[i]);
    }
    double median = medianCompute.evaluate(fitnessvals, 50.0);
    double offspringFit = (double) offspring.getAttribute(FitnessEvaluator.FITNESS_ATTRIBUTE);
    return Math.max((median - offspringFit) / (median - minFitness), 0.0);
}

From source file:br.unicamp.ic.recod.gpsi.ml.gpsi1NNToMomentScalarClassificationAlgorithm.java

@Override
public byte predict(double[] x) {

    //TODO: consider Euclidean disance instead of Manhattan for higher dimensionalities.

    byte minDistanceIndex = 0;
    double distance, minDistance = Double.POSITIVE_INFINITY;

    for (byte j : this.centroids.keySet()) {
        distance = 0.0;/* w ww  . ja  v  a2  s  .c  om*/
        for (int k = 0; k < this.dimensionality; k++)
            distance += Math.abs(x[k] - this.centroids.get(j)[k]);
        if (distance < minDistance) {
            minDistanceIndex = j;
            minDistance = distance;
        }
    }

    return minDistanceIndex;

}

From source file:com.rapidminer.gui.plotter.charts.ColorizedLineAndShapeRenderer.java

public ColorizedLineAndShapeRenderer(double[] colorValues) {
    this.colorValues = colorValues;
    this.minColor = Double.POSITIVE_INFINITY;
    this.maxColor = Double.NEGATIVE_INFINITY;
    if (this.colorValues != null) {
        for (double d : this.colorValues) {
            this.minColor = MathFunctions.robustMin(this.minColor, d);
            this.maxColor = MathFunctions.robustMax(this.maxColor, d);
        }/*from w  ww .  ja va2  s  .  c  o m*/
    }
}

From source file:ch.zweivelo.renderer.simple.math.RayTest.java

@Test
public void testIsValidT() throws Exception {
    assertTrue(ray.isValidT(EPSILON));/*w  w w .  j a va 2 s  . c  o m*/
    assertTrue(ray.isValidT(1d));
    assertTrue(ray.isValidT(10d));
    assertTrue(ray.isValidT(100d));
    assertTrue(ray.isValidT(1000d));
    assertTrue(ray.isValidT(EPSIPON_MAX));

    assertFalse(ray.isValidT(0d));
    assertFalse(ray.isValidT(-1d));
    assertFalse(ray.isValidT(-100000d));
    assertFalse(ray.isValidT(Double.NaN));
    assertFalse(ray.isValidT(Double.POSITIVE_INFINITY));
    assertFalse(ray.isValidT(Double.NEGATIVE_INFINITY));
}

From source file:mase.app.soccer.SoccerIndEvalAdjusted.java

private double[] computeDistances(SoccerAgent sa, Soccer soc) {
    double[] res = new double[4];
    // Distance to opponent goal
    res[0] = sa.distanceTo(sa.oppGoal);//w  ww . j a  v  a 2  s . com

    // Distance to ball
    res[1] = sa.distanceTo(soc.ball);

    // Distance to closest teammate
    double min = Double.POSITIVE_INFINITY;
    for (SoccerAgent other : sa.teamMates) {
        min = Math.min(min, sa.distanceTo(other));
    }
    res[2] = min;

    // Distance to closest opponent
    min = Double.POSITIVE_INFINITY;
    for (SoccerAgent other : sa.oppTeam) {
        min = Math.min(min, sa.distanceTo(other));
    }
    res[3] = min;
    return res;
}

From source file:com.insightml.math.distributions.AbstractGaussian.java

@Override
public final String toStringInterval(final int precision) {
    return toStringInterval(this, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 2, precision);
}

From source file:hivemall.common.ConversionState.java

public ConversionState(boolean conversionCheck, double convergenceRate) {
    this.conversionCheck = conversionCheck;
    this.convergenceRate = convergenceRate;
    this.readyToFinishIterations = false;
    this.totalErrors = 0.d;
    this.currLosses = 0.d;
    this.prevLosses = Double.POSITIVE_INFINITY;
    this.curIter = 0;
    this.curEta = Float.NaN;
}

From source file:Main.java

/**
 * Helper that does the work of the above functions. Gets the rectangular
 * position of a Bitmap if it were placed inside a View with scale type set
 * to {@link ImageView#ScaleType #CENTER_INSIDE}.
 * /*from  w  w w. ja va2  s. c  o m*/
 * @param bitmapWidth the Bitmap's width
 * @param bitmapHeight the Bitmap's height
 * @param viewWidth the parent View's width
 * @param viewHeight the parent View's height
 * @return the rectangular position of the Bitmap
 */
private static Rect getBitmapRectCenterInsideHelper(int bitmapWidth, int bitmapHeight, int viewWidth,
        int viewHeight) {
    double resultWidth;
    double resultHeight;
    int resultX;
    int resultY;

    double viewToBitmapWidthRatio = Double.POSITIVE_INFINITY;
    double viewToBitmapHeightRatio = Double.POSITIVE_INFINITY;

    // Checks if either width or height needs to be fixed
    if (viewWidth < bitmapWidth) {
        viewToBitmapWidthRatio = (double) viewWidth / (double) bitmapWidth;
    }
    if (viewHeight < bitmapHeight) {
        viewToBitmapHeightRatio = (double) viewHeight / (double) bitmapHeight;
    }

    // If either needs to be fixed, choose smallest ratio and calculate from
    // there
    if (viewToBitmapWidthRatio != Double.POSITIVE_INFINITY
            || viewToBitmapHeightRatio != Double.POSITIVE_INFINITY) {
        if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) {
            resultWidth = viewWidth;
            resultHeight = (bitmapHeight * resultWidth / bitmapWidth);
        } else {
            resultHeight = viewHeight;
            resultWidth = (bitmapWidth * resultHeight / bitmapHeight);
        }
    }
    // Otherwise, the picture is within frame layout bounds. Desired width
    // is simply picture size
    else {
        resultHeight = bitmapHeight;
        resultWidth = bitmapWidth;
    }

    // Calculate the position of the bitmap inside the ImageView.
    if (resultWidth == viewWidth) {
        resultX = 0;
        resultY = (int) Math.round((viewHeight - resultHeight) / 2);
    } else if (resultHeight == viewHeight) {
        resultX = (int) Math.round((viewWidth - resultWidth) / 2);
        resultY = 0;
    } else {
        resultX = (int) Math.round((viewWidth - resultWidth) / 2);
        resultY = (int) Math.round((viewHeight - resultHeight) / 2);
    }

    final Rect result = new Rect(resultX, resultY, resultX + (int) Math.ceil(resultWidth),
            resultY + (int) Math.ceil(resultHeight));

    return result;
}