List of usage examples for java.lang Double POSITIVE_INFINITY
double POSITIVE_INFINITY
To view the source code for java.lang Double POSITIVE_INFINITY.
Click Source Link
From source file:org.jfree.chart.demo.SampleXYDataset2.java
/** * Creates a sample dataset./*from w w w .j a va 2 s . c o m*/ * * @param seriesCount the number of series. * @param itemCount the number of items. */ public SampleXYDataset2(final int seriesCount, final int itemCount) { this.xValues = new Double[seriesCount][itemCount]; this.yValues = new Double[seriesCount][itemCount]; this.seriesCount = seriesCount; this.itemCount = itemCount; double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { final double x = (Math.random() - 0.5) * DEFAULT_RANGE; this.xValues[series][item] = new Double(x); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } final double y = (Math.random() + 0.5) * 6 * x + x; this.yValues[series][item] = new Double(y); if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } this.domainMin = new Double(minX); this.domainMax = new Double(maxX); this.domainRange = new Range(minX, maxX); this.rangeMin = new Double(minY); this.rangeMax = new Double(maxY); this.range = new Range(minY, maxY); }
From source file:org.jfree.data.RangeTest.java
/** * Simple tests for the contains() method. *//*from w w w . j a va2 s . co m*/ @Test public void testContains() { Range r1 = new Range(0.0, 1.0); assertFalse(r1.contains(Double.NaN)); assertFalse(r1.contains(Double.NEGATIVE_INFINITY)); assertFalse(r1.contains(-1.0)); assertTrue(r1.contains(0.0)); assertTrue(r1.contains(0.5)); assertTrue(r1.contains(1.0)); assertFalse(r1.contains(2.0)); assertFalse(r1.contains(Double.POSITIVE_INFINITY)); }
From source file:mase.spec.BasicHybridExchangerDunn.java
private double dunnIndex(double[][] distances) { double maxIntraCluster = Double.NEGATIVE_INFINITY; double minInterCluster = Double.POSITIVE_INFINITY; for (int i = 0; i < distances.length; i++) { maxIntraCluster = Math.max(distances[i][i], maxIntraCluster); for (int j = 0; j < distances.length; j++) { if (i != j) { minInterCluster = Math.min(minInterCluster, distances[i][j]); }/*ww w. j a v a 2 s . c o m*/ } } return minInterCluster / maxIntraCluster; }
From source file:com.clust4j.algo.KDTree.java
@Override void initNode(NearestNeighborHeapSearch tree, int i_node, int idx_start, int idx_end) { int n_features = tree.N_FEATURES, i, j; double rad = 0; double[] lowerBounds = tree.node_bounds[0][i_node]; double[] upperBounds = tree.node_bounds[1][i_node]; double[][] data = tree.data_arr; int[] idx_array = tree.idx_array; double[] data_row; // Get node bounds for (j = 0; j < n_features; j++) { lowerBounds[j] = Double.POSITIVE_INFINITY; upperBounds[j] = Double.NEGATIVE_INFINITY; }/* w ww.ja v a 2 s . c o m*/ // Compute data range for (i = idx_start; i < idx_end; i++) { data_row = data[idx_array[i]]; for (j = 0; j < n_features; j++) { lowerBounds[j] = FastMath.min(lowerBounds[j], data_row[j]); upperBounds[j] = FastMath.max(upperBounds[j], data_row[j]); } // The python code does not increment up to the range boundary, // the java for loop does. So we must decrement j by one. j--; if (tree.infinity_dist) rad = FastMath.max(rad, 0.5 * (upperBounds[j] - lowerBounds[j])); else rad += FastMath.pow(0.5 * FastMath.abs(upperBounds[j] - lowerBounds[j]), tree.dist_metric.getP()); } tree.node_data[i_node].idx_start = idx_start; tree.node_data[i_node].idx_end = idx_end; // radius assignment tree.node_data[i_node].radius = Math.pow(rad, 1.0 / tree.dist_metric.getP()); }
From source file:conceptor.Util.java
public static DenseMatrix64F PHI(DenseMatrix64F C, double gamma) { // % aperture adaptation of conceptor C by factor gamma, // % where 0 <= gamma <= Inf if (gamma == 0) { // [U S V] = svd(C); // Sdiag = diag(S); // Sdiag(Sdiag < 1) = zeros(sum(Sdiag < 1),1); // Cnew = U * diag(Sdiag) * U'; return null; } else if (gamma == Double.POSITIVE_INFINITY) { // [U S V] = svd(C); // Sdiag = diag(S); // Sdiag(Sdiag > 0) = ones(sum(Sdiag > 0),1); // Cnew = U * diag(Sdiag) * U'; return null; } else {/* w w w . j a v a 2s . c om*/ // Cnew = C * inv(C + gamma^(-2) * (eye(dim) - C)); DenseMatrix64F efactor = CommonOps.identity(C.numRows); subEquals(efactor, C); scale(Math.pow(gamma, -2), efactor); addEquals(efactor, C); invert(efactor); DenseMatrix64F Cnew = new DenseMatrix64F(C.numRows, C.numCols); mult(C, efactor, Cnew); return Cnew; } }
From source file:jtrace.Scene.java
/** * Trace a ray through the scene, returning the resulting colour. * * @param ray/* ww w . j av a2 s. co m*/ * @return */ public Colour traceRay(Ray ray) { // Check for recursion depth violation: if (recursionDepth++ > maxRecursionDepth) { System.err.println("Warning: max recursion depth exceeded."); return backgroundColour; } // Determine closest intersecting object in scene: double nearestObjectDist = Double.POSITIVE_INFINITY; SceneObject nearestObject = null; for (SceneObject object : sceneObjects) { double dist = object.getFirstCollision(ray); if (dist < nearestObjectDist) { nearestObject = object; nearestObjectDist = dist; } } if (nearestObject == null) return backgroundColour; else { return nearestObject.getCollisionColour(); } }
From source file:com.analog.lyric.dimple.factorfunctions.Poisson.java
@Override public final double evalEnergy(Value[] arguments) { int index = 0; // First argument of the factor: lambda if (!_lambdaParameterConstant) { _lambda = arguments[index++].getDouble(); if (_lambda < 0) return Double.POSITIVE_INFINITY; _logLambda = Math.log(_lambda); }/* w ww. ja v a2s. c o m*/ // Second argument of the factor: k final int k = arguments[index++].getInt(); final double negativeLogFactorialK = -org.apache.commons.math3.special.Gamma.logGamma(k + 1); if (_lambda > 0) return -(-_lambda + k * _logLambda + negativeLogFactorialK); else if (_lambda == 0 && k != 0) return Double.POSITIVE_INFINITY; else if (_lambda == 0 && k == 0) return 0; return Double.POSITIVE_INFINITY; }
From source file:com.zekke.webapp.service.impl.DijkstraRouteFinderService.java
/** * Initializes the distance map that will be used to rebuild the optimal * route.// w ww . j a v a 2 s.c o m * * @param root the root Place. * @param g the list of "nodes". * @return the distance map. */ private Map<Place, Double> initDistanceMap(Place root, List<Place> g) { Map<Place, Double> d = new HashMap<>(g.size()); for (Place p : g) { d.put(p, Double.POSITIVE_INFINITY); } d.put(root, 0.0); return d; }
From source file:com.google.blockly.model.FieldNumber.java
/** * Sets the constraints on valid number values. * <p/>//from www . j av a2 s. co m * Changing the constraints may trigger a {@link ChangeEvent}, even if the value does not * change. * * @param min The minimum allowed value, inclusive. * @param max The maximum allowed value, inclusive. * @param precision The precision of allowed values. Valid values are multiples of this number, * such as 1, 0.1, 100, or 0.125. */ public void setConstraints(double min, double max, double precision) { if (max == Double.POSITIVE_INFINITY || Double.isNaN(max)) { max = NO_CONSTRAINT; } else if (max == Double.NEGATIVE_INFINITY) { throw new IllegalArgumentException("Max cannot be -Inf. No valid values would exist."); } if (min == Double.NEGATIVE_INFINITY || Double.isNaN(min)) { min = NO_CONSTRAINT; } else if (min == Double.POSITIVE_INFINITY) { throw new IllegalArgumentException("Min cannot be Inf. No valid values would exist."); } if (precision == 0 || Double.isNaN(precision)) { precision = NO_CONSTRAINT; } if (Double.isInfinite(precision)) { throw new IllegalArgumentException("Precision cannot be infinite."); } if (!Double.isNaN(min) && !Double.isNaN(max) && min > max) { throw new IllegalArgumentException("Minimum value must be less than max. Found " + min + " > " + max); } if (!Double.isNaN(precision) && precision <= 0) { throw new IllegalArgumentException("Precision must be positive. Found " + precision); } double effectiveMin = Double.isNaN(min) ? -Double.MAX_VALUE : min; double effectiveMax = Double.isNaN(max) ? Double.MAX_VALUE : max; if (!Double.isNaN(precision)) { if (effectiveMin < 0) { double multiplier = Math.floor(-effectiveMin / precision); effectiveMin = precision * -multiplier; } else { double multiplier = Math.ceil(effectiveMin / precision); effectiveMin = precision * multiplier; } if (effectiveMax < 0) { double multiplier = Math.ceil(-effectiveMax / precision); effectiveMax = precision * -multiplier; } else { double multiplier = Math.floor(effectiveMax / precision); effectiveMax = precision * multiplier; } if (effectiveMin > effectiveMax) { throw new IllegalArgumentException("No valid value in range."); } } mMin = min; mMax = max; mPrecision = precision; mEffectiveMin = effectiveMin; mEffectiveMax = effectiveMax; mIntegerPrecision = (precision == Math.round(precision)); if (!hasPrecision()) { mFormatter = NAIVE_DECIMAL_FORMAT; } else if (mIntegerPrecision) { mFormatter = INTEGER_DECIMAL_FORMAT; } else { String precisionStr = NAIVE_DECIMAL_FORMAT.format(precision); int decimalChar = precisionStr.indexOf('.'); if (decimalChar == -1) { mFormatter = INTEGER_DECIMAL_FORMAT; } else { int significantDigits = precisionStr.length() - decimalChar; StringBuilder sb = new StringBuilder("0."); char[] sigDigitsFormat = new char[significantDigits]; Arrays.fill(sigDigitsFormat, '#'); sb.append(sigDigitsFormat); mFormatter = new DecimalFormat(sb.toString()); } } setValueImpl(mValue, true); }
From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.DirichletParameters.java
@Override public double evalEnergy(Value value) { final double[] x = value.getDoubleArray(); final int n = _alphaMinusOne.length; if (x.length != n) { throw new DimpleException("Argument does not contain %d-dimensional real joint value", n); }/* w ww . j a v a 2s. c om*/ double sum = 0.0, xSum = 0.0; if (isSymmetric()) { for (int i = n; --i >= 0;) { final double xi = x[i]; if (xi <= 0) { return Double.POSITIVE_INFINITY; } sum -= Math.log(xi); xSum += xi; } sum *= _alphaMinusOne[0]; } else { for (int i = n; --i >= 0;) { final double xi = x[i]; if (xi <= 0) { return Double.POSITIVE_INFINITY; } sum -= (_alphaMinusOne[i]) * Math.log(xi); // -log(x_i ^ (a_i-1)) xSum += xi; } } if (!DoubleMath.fuzzyEquals(xSum, 1, SIMPLEX_THRESHOLD * n)) // Values must be on the probability simplex { return Double.POSITIVE_INFINITY; } return sum; }