List of usage examples for java.lang Double MAX_VALUE
double MAX_VALUE
To view the source code for java.lang Double MAX_VALUE.
Click Source Link
From source file:com.taobao.weex.devtools.json.ObjectMapperTest.java
@Test public void testObjectToPrimitive() throws JSONException { ArrayOfPrimitivesContainer container = new ArrayOfPrimitivesContainer(); ArrayList<Object> primitives = container.primitives; primitives.add(Long.MIN_VALUE); primitives.add(Long.MAX_VALUE); primitives.add(Integer.MIN_VALUE); primitives.add(Integer.MAX_VALUE); primitives.add(Float.MIN_VALUE); primitives.add(Float.MAX_VALUE); primitives.add(Double.MIN_VALUE); primitives.add(Double.MAX_VALUE); String json = mObjectMapper.convertValue(container, JSONObject.class).toString(); JSONObject obj = new JSONObject(json); JSONArray array = obj.getJSONArray("primitives"); ArrayList<Object> actual = new ArrayList<>(); for (int i = 0, N = array.length(); i < N; i++) { actual.add(array.get(i));/* w w w . java 2s . c o m*/ } assertEquals(primitives.toString(), actual.toString()); }
From source file:acromusashi.stream.ml.clustering.kmeans.KmeansCalculator.java
/** * ????????????/* w w w.java2 s .c o m*/ * * @param targetPoint ? * @param centroids ? * @return Kmeans? */ public static KmeansResult nearestCentroid(double[] targetPoint, double[][] centroids) { int nearestCentroidIndex = 0; Double minDistance = Double.MAX_VALUE; double[] currentCentroid = null; Double currentDistance; for (int index = 0; index < centroids.length; index++) { currentCentroid = centroids[index]; if (currentCentroid != null) { currentDistance = MathUtils.distance(targetPoint, currentCentroid); if (currentDistance < minDistance) { minDistance = currentDistance; nearestCentroidIndex = index; } } } currentCentroid = centroids[nearestCentroidIndex]; KmeansResult result = new KmeansResult(); result.setDataPoint(targetPoint); result.setCentroidIndex(nearestCentroidIndex); result.setCentroid(currentCentroid); result.setDistance(minDistance); return result; }
From source file:ui.results.ResultChartPanel.java
public void recalculate(Vector<String> children) throws RestrictionViolation { results = ((ResultsCell) Grid.instance().getCell("results")).getValue(); logger.debug("Refresh the chart"); if (results != null) { // removing all the rows from the matrix dataset.clear();/*from w w w. ja v a 2 s . c o m*/ upper.clear(); lower.clear(); // Minimum and Maximum double minimum = Double.MAX_VALUE; double maximum = 1; // averages for (int i = 0; i < results.length; i++) if (results[i].getMSP() > 1) { if (results[i].getStdDev() < 0) { dataset.add(results[i].getMSP(), 0, "msp", results[i].getDataset()); } else { dataset.add(results[i].getMSP(), results[i].getStdDev(), "msp", results[i].getDataset()); } if (results[i].getMSP() > maximum) maximum = results[i].getMSP(); if (minimum > results[i].getMSP()) minimum = results[i].getMSP(); } else { dataset.add(1.0, 0.0, "msp", results[i].getDataset()); minimum = 1.0; } // Upper and Lower (if standard deviation is present) if (results.length > 1 && results[0].getStdDev() >= 0) { for (int i = 0; i < results.length; i++) if (results[i].getMSP() + 2 * results[i].getStdDev() > 1) { double v = results[i].getMSP() + 2 * results[i].getStdDev(); upper.addValue(v, "upper", results[i].getDataset()); if (v > maximum) maximum = v; } else upper.addValue(1.0, "upper", results[i].getDataset()); for (int i = 0; i < results.length; i++) if (results[i].getMSP() - 2 * results[i].getStdDev() > 1) { double v = results[i].getMSP() - 2 * results[i].getStdDev(); lower.addValue(v, "lower", results[i].getDataset()); if (minimum > v) minimum = v; } else { lower.addValue(1.0, "lower", results[i].getDataset()); minimum = 1.0; } // Set the lower and upper datasets ((CategoryPlot) chart.getPlot()).setDataset(0, lower); ((CategoryPlot) chart.getPlot()).setDataset(2, upper); } else { // Remove lower and upper datasets ((CategoryPlot) chart.getPlot()).setDataset(0, null); ((CategoryPlot) chart.getPlot()).setDataset(2, null); } // Add 10% of the range above and below if (minimum == maximum) { minimum = minimum - minimum / 10; maximum = maximum + maximum / 10; } else { minimum = minimum - ((maximum - minimum) / 10); maximum = maximum + ((maximum - minimum) / 10); } ((CategoryPlot) chart.getPlot()).getRangeAxis().setLowerBound(minimum); ((CategoryPlot) chart.getPlot()).getRangeAxis().setUpperBound(maximum); } }
From source file:dk.dma.epd.common.prototype.notification.MsiNmNotification.java
/** * Computes the distance between the MSI-NM and the given position. * NB: Test method - not precise for Polygon and Polylines * @param pos the pos/*from ww w . jav a2 s .co m*/ * @return the distance in NM */ public Double getDistanceToPosition(Position pos) { if (pos != null && get().getLocations() != null && get().getLocations().size() > 0) { Double minDist = Double.MAX_VALUE; for (MCLocation loc : get().getLocations()) { // Circle if (loc.getType() == MCLocationType.CIRCLE && loc.getRadius() != null && loc.getPoints().size() == 1) { double dist = Calculator.range(pos, toPos(loc.getPoints().get(0)), Heading.GC); minDist = Math.min(minDist, Math.max(0, dist - loc.getRadius().doubleValue())); } else if (loc.getType() == MCLocationType.POINT && loc.getPoints().size() == 1) { // Point minDist = Math.min(minDist, Calculator.range(pos, toPos(loc.getPoints().get(0)), Heading.GC)); } else if (loc.getType() == MCLocationType.POLYGON) { // Polygon for (MCPoint pt : loc.getPoints()) { minDist = Math.min(minDist, Calculator.range(pos, toPos(pt), Heading.GC)); } } else if (loc.getType() == MCLocationType.POLYLINE) { // Polyline for (MCPoint pt : loc.getPoints()) { minDist = Math.min(minDist, Calculator.range(pos, toPos(pt), Heading.GC)); } } } return minDist; } return null; }
From source file:mastermind.RandomGenerator.java
public double getRandomDouble() { return getRandomDouble(Double.MIN_VALUE, Double.MAX_VALUE); }
From source file:com.joptimizer.util.Utils.java
/** * Get the index of the minimum entry.//w w w .ja v a 2s . com */ public static int getMinIndex(double[] v) { int minIndex = -1; double minValue = Double.MAX_VALUE; for (int i = 0; i < v.length; i++) { if (v[i] < minValue) { minIndex = i; minValue = v[i]; } } return minIndex; }
From source file:com.joptimizer.functions.SOCPLogarithmicBarrier.java
/** * Calculates the initial value for the s parameter in Phase I. * Return s = max(||Ai.x+bi|| - (ci.x+di)) * @see "S.Boyd and L.Vandenberghe, Convex Optimization, 11.6.2" *///from www.j av a 2s . c o m public double calculatePhase1InitialFeasiblePoint(double[] originalNotFeasiblePoint, double tolerance) { double s = -Double.MAX_VALUE; RealVector x = new ArrayRealVector(originalNotFeasiblePoint); for (int i = 0; i < socpConstraintParametersList.size(); i++) { SOCPConstraintParameters param = socpConstraintParametersList.get(i); RealMatrix A = param.getA(); RealVector b = param.getB(); RealVector c = param.getC(); double d = param.getD(); s = Math.max(s, (A.operate(x).subtract(b).getNorm() - (c.dotProduct(x) + d)) * Math.pow(tolerance, -0.5)); } return s; }
From source file:org.yccheok.jstock.charting.Utils.java
/** * Returns weekly chart data based on given stock history server. * /*from w w w . j av a2 s .c om*/ * @param stockHistoryServer the stock history server * @return list of weekly chart data */ public static List<ChartData> getWeeklyChartData(StockHistoryServer stockHistoryServer) { final int days = stockHistoryServer.size(); Calendar prevCalendar = null; List<ChartData> chartDatas = new ArrayList<ChartData>(); double prevPrice = 0; double openPrice = 0; double lastPrice = 0; double highPrice = Double.MIN_VALUE; double lowPrice = Double.MAX_VALUE; long volume = 0; long timestamp = 0; int count = 0; for (int i = 0; i < days; i++) { // First, determine the current data is same week as the previous // data. boolean isSameWeek = false; final long t = stockHistoryServer.getTimestamp(i); Stock stock = stockHistoryServer.getStock(t); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(t); if (prevCalendar != null) { int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); int prevWeekOfYear = prevCalendar.get(Calendar.WEEK_OF_YEAR); // Is this the same week? isSameWeek = (weekOfYear == prevWeekOfYear); } else { // First time for us to enter this for loop. isSameWeek = true; openPrice = stock.getOpenPrice(); prevPrice = stock.getPrevPrice(); } if (isSameWeek == false) { // This is a new week. There must be data for previous week. assert (count > 0); ChartData chartData = ChartData.newInstance(prevPrice, openPrice, lastPrice / count, // Average last price. highPrice, lowPrice, volume / count, // Average volume. timestamp); chartDatas.add(chartData); // First day of the week. prevPrice = stock.getPrevPrice(); openPrice = stock.getOpenPrice(); lastPrice = stock.getLastPrice(); highPrice = stock.getHighPrice(); lowPrice = stock.getLowPrice(); volume = stock.getVolume(); timestamp = stock.getTimestamp(); count = 1; } else { // We will not update prevPrice and openPrice. They will remain // as the first day of the week's. lastPrice += stock.getLastPrice(); highPrice = Math.max(highPrice, stock.getHighPrice()); lowPrice = Math.min(lowPrice, stock.getLowPrice()); volume += stock.getVolume(); timestamp = stock.getTimestamp(); count++; } prevCalendar = calendar; } // Is there any data which is not being inserted yet? if (count > 0) { ChartData chartData = ChartData.newInstance(prevPrice, openPrice, lastPrice / count, highPrice, lowPrice, volume / count, timestamp); chartDatas.add(chartData); } return chartDatas; }
From source file:edu.stanford.cfuller.imageanalysistools.clustering.GaussianLikelihoodObjectiveFunction.java
/** * Evaluates the function with the specified parameters. * * The parameters describe a set of gaussian generators (which are the Clusters). * * @param parameters A RealVector containing the values of all the parameters of each Gaussian, ordered so that all the parameters of a single gaussian are together, then the next gaussian, etc. * @return The negative log likelihood of having observed the ClusterObjects at their locations, given the parameters describing the Gaussian clusters. *//* w w w. ja v a 2 s .c o m*/ public double evaluate(RealVector parameters) { int nClusters = parameters.getDimension() / nParametersEach; //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("nClusters: " + nClusters + " abdMatrices_size: " + abdMatrices.size() + " det_dim: " + det.getDimension()); if (det.getDimension() != nClusters) { clusterProbs = new Array2DRowRealMatrix(this.objects.size(), nClusters); det = new ArrayRealVector(nClusters); pk = new ArrayRealVector(nClusters); if (abdMatrices.size() < nClusters) { int originalSize = abdMatrices.size(); for (int i = 0; i < nClusters - originalSize; i++) { abdMatrices.add(new Array2DRowRealMatrix(numDim, numDim)); } } else { abdMatrices.setSize(nClusters); } } pk.mapMultiplyToSelf(0.0); //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("nClusters: " + nClusters + " abdMatrices_size: " + abdMatrices.size() + " det_dim: " + det.getDimension()); for (int i = 0; i < nClusters; i++) { /* double ct = Math.cos(parameters.getEntry(nParametersEach*i+3)); double st = Math.sin(parameters.getEntry(nParametersEach*i+3)); double sin2t = Math.sin(2*parameters.getEntry(nParametersEach*i+3)); double a = (ct*ct/(2*parameters.getEntry(nParametersEach*i+2)) + st*st/(2*parameters.getEntry(nParametersEach*i+4))); double b = (sin2t/(4*parameters.getEntry(nParametersEach*i+4)) - sin2t/(4*parameters.getEntry(nParametersEach*i+2))); double d = (st*st/(2*parameters.getEntry(nParametersEach*i+2)) + ct*ct/(2*parameters.getEntry(nParametersEach*i+4))); */ double a = parameters.getEntry(nParametersEach * i + 2); double d = parameters.getEntry(nParametersEach * i + 4); double b = Math.sqrt(a * d) * parameters.getEntry(nParametersEach * i + 3); abdMatrices.get(i).setEntry(0, 0, a); abdMatrices.get(i).setEntry(1, 0, b); abdMatrices.get(i).setEntry(0, 1, b); abdMatrices.get(i).setEntry(1, 1, d); LUDecomposition abdLU = (new LUDecomposition(abdMatrices.get(i))); det.setEntry(i, (abdLU).getDeterminant()); //det.setEntry(i, a*d-b*b); try { abdMatrices.set(i, abdLU.getSolver().getInverse()); } catch (org.apache.commons.math3.linear.SingularMatrixException e) { return Double.MAX_VALUE; } } for (int n = 0; n < this.objects.size(); n++) { ClusterObject c = this.objects.get(n); double max = -1.0 * Double.MAX_VALUE; int maxIndex = 0; for (int k = 0; k < nClusters; k++) { mean.setEntry(0, c.getCentroid().getX() - parameters.getEntry(nParametersEach * k)); mean.setEntry(1, c.getCentroid().getY() - parameters.getEntry(nParametersEach * k + 1)); x = abdMatrices.get(k).operate(mean); double dot = x.dotProduct(mean); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("k, n: " + k + ", " + this.objects.size()); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("parameters: " + parameters.toString()); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("abd matrix: " + abdMatrices.get(k).toString()); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("det: " + det.getEntry(k)); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("mean: " + mean.toString()); // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("dot: " + dot); double logN = negLog2PI - 0.5 * Math.log(det.getEntry(k)) - 0.5 * dot; // java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("logN: " + logN); clusterProbs.setEntry(n, k, logN); if (logN > max) { max = logN; maxIndex = k; } if (Double.isInfinite(logN) || Double.isNaN(logN)) { return Double.MAX_VALUE; } } c.setMostProbableCluster(maxIndex); } for (int k = 0; k < nClusters; k++) { double tempMax = -1.0 * Double.MAX_VALUE; for (int n = 0; n < this.objects.size(); n++) { if (clusterProbs.getEntry(n, k) > tempMax) tempMax = clusterProbs.getEntry(n, k); } pk.setEntry(k, tempMax + Math.log( clusterProbs.getColumnVector(k).mapSubtract(tempMax).mapToSelf(new Exp()).getL1Norm()) - Math.log(this.objects.size())); } double pkMax = -1.0 * Double.MAX_VALUE; for (int k = 0; k < nClusters; k++) { if (pk.getEntry(k) > pkMax) pkMax = pk.getEntry(k); } double logSumPk = pkMax + Math.log(pk.mapSubtract(pkMax).mapToSelf(new Exp()).getL1Norm()); pk.mapSubtractToSelf(logSumPk); //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("pk: " + pk.toString()); double L = 0; for (int n = 0; n < this.objects.size(); n++) { RealVector toSum = clusterProbs.getRowVector(n).add(pk); double tempMax = -1.0 * Double.MAX_VALUE; for (int k = 0; k < nClusters; k++) { if (toSum.getEntry(k) > tempMax) tempMax = toSum.getEntry(k); } double pn = tempMax + Math.log(toSum.mapSubtract(tempMax).mapToSelf(new Exp()).getL1Norm()); //java.util.logging.Logger.getLogger("edu.stanford.cfuller.imageanalysistools").info("pn: " + pn); L += pn; } return -1.0 * L; }
From source file:edu.oregonstate.eecs.mcplan.ml.GaussianMixtureModel.java
public int mapCluster(final double[] x) { final double[] post = posteriorCluster(x); double ml = -Double.MAX_VALUE; int mlc = -1; for (int i = 0; i < k_; ++i) { if (post[i] > ml) { ml = post[i];//from ww w . jav a 2 s. c o m mlc = i; } } return mlc; }