List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:io.horizondb.model.core.fields.DecimalField.java
/** * Converts the specified decimal into a double. * /*from w w w . j a v a2 s. co m*/ * @param mantissa the decimal mantissa * @param exponent the decimal exponent * @return the double corresponding to the specified decimal */ private static double toDouble(long mantissa, int exponent) { if (isNaN(mantissa, exponent)) { return Double.NaN; } if (isPositiveInfinity(mantissa, exponent)) { return Double.POSITIVE_INFINITY; } if (isNegativeInfinity(mantissa, exponent)) { return Double.NEGATIVE_INFINITY; } if (exponent > 0) { return mantissa * pow10(exponent); } return mantissa / pow10(-exponent); }
From source file:com.genericworkflownodes.knime.config.writer.CTDConfigurationWriter.java
private void addDoubleListParameterRestrictions(Parameter<?> p, StringBuffer restriction) { DoubleListParameter dlp = (DoubleListParameter) p; boolean lbSet = Double.NEGATIVE_INFINITY != dlp.getLowerBound().doubleValue(); boolean ubSet = Double.POSITIVE_INFINITY != dlp.getUpperBound().doubleValue(); if (lbSet) {/* w w w. j a va2 s . c o m*/ restriction.append(String.format(Locale.ENGLISH, "%f", dlp.getLowerBound()) .replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, "")); } if (ubSet || lbSet) { restriction.append(':'); } if (ubSet) { restriction.append(String.format(Locale.ENGLISH, "%f", dlp.getUpperBound()) .replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, "")); } }
From source file:ddf.catalog.source.opensearch.impl.OpenSearchParserImpl.java
/** * Takes in an array of coordinates and converts it to a (rough approximation) bounding box. * * <p>Note: Searches being performed where the polygon goes through the international date line * may return a bad bounding box./*from www. j ava2s . c om*/ * * @param polyAry array of coordinates (lon,lat,lon,lat,lon,lat..etc) * @return Array of bounding box coordinates in the following order: West South East North. Also * described as minX, minY, maxX, maxY (where longitude is the X-axis, and latitude is the * Y-axis). */ private double[] createBBoxFromPolygon(String[] polyAry) { double minX = Double.POSITIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; double curX, curY; for (int i = 0; i < polyAry.length - 1; i += 2) { LOGGER.debug("polyToBBox: lon - {} lat - {}", polyAry[i], polyAry[i + 1]); curX = Double.parseDouble(polyAry[i]); curY = Double.parseDouble(polyAry[i + 1]); if (curX < minX) { minX = curX; } if (curX > maxX) { maxX = curX; } if (curY < minY) { minY = curY; } if (curY > maxY) { maxY = curY; } } return new double[] { minX, minY, maxX, maxY }; }
From source file:edu.uc.rphash.tests.kmeanspp.KMeansPlusPlus.java
/** * Get a random point from the {@link Cluster} with the largest distance variance. * * @param clusters the {@link Cluster}s to search * @return a random point from the selected cluster * @throws ConvergenceException if clusters are all empty *//* w ww . java 2s. c o m*/ private T getPointFromLargestVarianceCluster(final Collection<Cluster<T>> clusters) throws Exception { double maxVariance = Double.NEGATIVE_INFINITY; Cluster<T> selected = null; for (final Cluster<T> cluster : clusters) { if (!cluster.getPoints().isEmpty()) { // compute the distance variance of the current cluster final T center = cluster.getCenter(); //final Variance stat = new Variance(); double n = 0; double mean = 0; double M2 = 0; for (final T point : cluster.getPoints()) { double x = point.distanceFrom(center); n++; double delta = x - mean; mean = mean + delta / n; M2 = M2 + delta * (x - mean); //stat.increment(point.distanceFrom(center)); } final double variance = M2 / (n - 1f);//stat.getResult(); // select the cluster with the largest variance if (variance > maxVariance) { maxVariance = variance; selected = cluster; } } } // did we find at least one non-empty cluster ? if (selected == null) { throw new Exception(); } // extract a random point from the cluster final List<T> selectedPoints = selected.getPoints(); return selectedPoints.remove(random.nextInt(selectedPoints.size())); }
From source file:info.debatty.java.datasets.sift.Matrix.java
public static double max(final double[] A) { double maxval = Double.NEGATIVE_INFINITY; for (double val : A) { if (val > maxval) { maxval = val; }/*from ww w . ja va 2 s . co m*/ } return maxval; }
From source file:ml.shifu.shifu.util.CommonUtilsTest.java
@Test public void binIndexTest() { Double[] array = { Double.NEGATIVE_INFINITY, 2.1E-4, 0.00351, 0.01488, 0.02945, 0.0642, 0.11367, 0.22522, 0.23977 };/*w ww .ja v a 2s . c o m*/ List<Double> binBoundary = Arrays.asList(array); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 0.00350), 1); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 0.00351), 2); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 0.00353), 2); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 0.0642), 5); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 0.00010), 0); Assert.assertEquals(BinUtils.getBinIndex(binBoundary, 5D), 8); }
From source file:imagingbook.pub.fd.FourierDescriptor.java
/** * Calculates the 'canonical' start point. This version uses * (a) a coarse search for a global maximum of fp() and subsequently * (b) a numerical optimization using Brent's method * (implemented with Apache Commons Math). */// w ww . j ava 2 s. c o m public double getStartPointPhase(int Mp) { Mp = Math.min(Mp, (G.length - 1) / 2); UnivariateFunction fp = new TargetFunction(Mp); // search for the global maximum in coarse steps double cmax = Double.NEGATIVE_INFINITY; int kmax = -1; int K = 25; // number of steps over 180 degrees for (int k = 0; k < K; k++) { final double phi = Math.PI * k / K; // phase to evaluate final double c = fp.value(phi); if (c > cmax) { cmax = c; kmax = k; } } // optimize using previous and next point as the bracket. double minPhi = Math.PI * (kmax - 1) / K; double maxPhi = Math.PI * (kmax + 1) / K; UnivariateOptimizer optimizer = new BrentOptimizer(1E-4, 1E-6); int maxIter = 20; UnivariatePointValuePair result = optimizer.optimize(new MaxEval(maxIter), new UnivariateObjectiveFunction(fp), GoalType.MAXIMIZE, new SearchInterval(minPhi, maxPhi)); double phi0 = result.getPoint(); return phi0; // the canonical start point phase }
From source file:ml.shifu.dtrain.DTrainRequestProcessor.java
private void validateTreeParams(Params params) { validateInt(params, DtrainConstants.SHIFU_DTRAIN_TREE_TREENUM); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_TREENUM); // TODO validate SHIFU_DTRAIN_TREE_FEATURESUBSETSTRATEGY in list of choices validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_FEATURESUBSETSTRATEGY); validateInt(params, DtrainConstants.SHIFU_DTRAIN_TREE_MAXDEPTH); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_MAXDEPTH); // TODO validate SHIFU_DTRAIN_TREE_IMPURITY in list of choices validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_IMPURITY); validateDoubleAndRange(params, DtrainConstants.SHIFU_DTRAIN_TREE_LEARNINGRATE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_LEARNINGRATE); validateInt(params, DtrainConstants.SHIFU_DTRAIN_TREE_MININSTANCESPERNODE); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_MININSTANCESPERNODE); validateDoubleAndRange(params, DtrainConstants.SHIFU_DTRAIN_TREE_MININFOGAIN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_MININFOGAIN); // TODO validate SHIFU_DTRAIN_TREE_LOSS in list of choices validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TREE_LOSS); // TODO validate SHIFU_DTRAIN_TARGET_COLUMN_NAME in list of choices validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_TARGET_COLUMN_NAME); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_NEGATIVE_TAGS); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_POSITIVE_TAGS); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_EPOCH); validateInt(params, DtrainConstants.SHIFU_DTRAIN_EPOCH); validateBoolean(params, DtrainConstants.SHIFU_DTRAIN_IS_TRAIN_ON_DISK); validateBoolean(params, DtrainConstants.SHIFU_DTRAIN_IS_BAGGING_WITH_REPLACEMENT); validateBoolean(params, DtrainConstants.SHIFU_DTRAIN_IS_FIX_INITIAL_INPUT); validateBoolean(params, DtrainConstants.SHIFU_DTRAIN_PARALLEL); validateDoubleAndRange(params, DtrainConstants.SHIFU_DTRAIN_CROSS_VALIDATION_RATE, 0.0d, 1.0d); validateDoubleAndRange(params, DtrainConstants.SHIFU_DTRAIN_BAGGING_SAMPLE_RATE, 0.0d, 1.0d); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_INPUT); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_INPUT_DELIMETER); validateNotNull(params, DtrainConstants.SHIFU_DTRAIN_ALGORITHM); }
From source file:dkpro.similarity.algorithms.wikipedia.measures.WikipediaSimilarityMeasureBase.java
/** * @param valueList A list containing the values. * @return Returns the maximum of the values in the given list, or NO_SENSE if the value list is empty. */// w ww.ja va 2 s.c o m public double getMaximum(List<Double> valueList) { if (valueList == null) { return NO_SENSE; } boolean valid = false; double maximum = Double.NEGATIVE_INFINITY; for (double value : valueList) { if (value > maximum) { maximum = value; valid = true; } } if (!valid) { return NO_SENSE; } return maximum; }
From source file:be.ugent.maf.cellmissy.analysis.doseresponse.impl.DoseResponseLMOptimizer.java
/** * Copy of super source code. Decompose a matrix A as A.P = Q.R using * Householder transforms./*from ww w. j av a 2 s .co m*/ * <p> * As suggested in the P. Lascaux and R. Theodor book * <i>Analyse numérique matricielle appliquée à l'art * de l'ingénieur</i> (Masson, 1986), instead of representing the * Householder transforms with u<sub>k</sub> unit vectors such that: * <pre> * H<sub>k</sub> = I - 2u<sub>k</sub>.u<sub>k</sub><sup>t</sup> * </pre> we use <sub>k</sub> non-unit vectors such that: * <pre> * H<sub>k</sub> = I - beta<sub>k</sub>v<sub>k</sub>.v<sub>k</sub><sup>t</sup> * </pre> where v<sub>k</sub> = a<sub>k</sub> - alpha<sub>k</sub> * e<sub>k</sub>. The beta<sub>k</sub> coefficients are provided upon exit * as recomputing them from the v<sub>k</sub> vectors would be costly.</p> * <p> * This decomposition handles rank deficient cases since the tranformations * are performed in non-increasing columns norms order thanks to columns * pivoting. The diagonal elements of the R matrix are therefore also in * non-increasing absolute values order.</p> * * @param jacobian Weighted Jacobian matrix at the current point. * @param solvedCols Number of solved point. * @return data used in other methods of this class. * @throws ConvergenceException if the decomposition cannot be performed. */ private InternalData qrDecomposition(RealMatrix jacobian, int solvedCols) throws ConvergenceException { // Code in this class assumes that the weighted Jacobian is -(W^(1/2) J), // hence the multiplication by -1. final double[][] weightedJacobian = jacobian.scalarMultiply(-1).getData(); final int nR = weightedJacobian.length; final int nC = weightedJacobian[0].length; final int[] permutation = new int[nC]; final double[] diagR = new double[nC]; final double[] jacNorm = new double[nC]; final double[] beta = new double[nC]; // initializations for (int k = 0; k < nC; ++k) { permutation[k] = k; double norm2 = 0; for (int i = 0; i < nR; ++i) { double akk = weightedJacobian[i][k]; norm2 += akk * akk; } jacNorm[k] = FastMath.sqrt(norm2); } // transform the matrix column after column for (int k = 0; k < nC; ++k) { // select the column with the greatest norm on active components int nextColumn = -1; double ak2 = Double.NEGATIVE_INFINITY; for (int i = k; i < nC; ++i) { double norm2 = 0; for (int j = k; j < nR; ++j) { double aki = weightedJacobian[j][permutation[i]]; norm2 += aki * aki; } if (Double.isInfinite(norm2) || Double.isNaN(norm2)) { throw new ConvergenceException(LocalizedFormats.UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN, nR, nC); } if (norm2 > ak2) { nextColumn = i; ak2 = norm2; } } if (ak2 <= getRankingThreshold()) { return new InternalData(weightedJacobian, permutation, k, diagR, jacNorm, beta); } int pk = permutation[nextColumn]; permutation[nextColumn] = permutation[k]; permutation[k] = pk; // choose alpha such that Hk.u = alpha ek double akk = weightedJacobian[k][pk]; double alpha = (akk > 0) ? -FastMath.sqrt(ak2) : FastMath.sqrt(ak2); double betak = 1.0 / (ak2 - akk * alpha); beta[pk] = betak; // transform the current column diagR[pk] = alpha; weightedJacobian[k][pk] -= alpha; // transform the remaining columns for (int dk = nC - 1 - k; dk > 0; --dk) { double gamma = 0; for (int j = k; j < nR; ++j) { gamma += weightedJacobian[j][pk] * weightedJacobian[j][permutation[k + dk]]; } gamma *= betak; for (int j = k; j < nR; ++j) { weightedJacobian[j][permutation[k + dk]] -= gamma * weightedJacobian[j][pk]; } } } return new InternalData(weightedJacobian, permutation, solvedCols, diagR, jacNorm, beta); }