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:eu.cassandra.utils.Utils.java
public static double estimateThreshold(double[] power, boolean median) { double result = 0; ArrayList<Double> minimums = new ArrayList<Double>(); double min = Double.POSITIVE_INFINITY; for (int i = 0; i < power.length; i++) { if (min > power[i]) min = power[i];/* w w w . j a va2 s . com*/ if (i % 1440 == 0 && i != 0) { minimums.add(min); min = Double.POSITIVE_INFINITY; } } if (minimums.size() == 0) minimums.add(min); log.debug("================THRESHOLD SETTING================"); log.debug("Minimums: " + minimums.toString()); log.debug("Median:" + median); if (median) result = Utils.estimateMedian(minimums); else result = Utils.estimateMean(minimums); log.debug("Resulting threshold: " + result); log.debug(""); log.debug(""); return result; }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the range of the values in this dataset's range. * * @param includeInterval ignored./*from ww w .j a va2s . com*/ * * @return The range (or <code>null</code> if the dataset contains no * values). */ @Override public Range getRangeBounds(boolean includeInterval) { double lower = Double.POSITIVE_INFINITY; double upper = Double.NEGATIVE_INFINITY; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double minY = series.getMinY(); if (!Double.isNaN(minY)) { lower = Math.min(lower, minY); } double maxY = series.getMaxY(); if (!Double.isNaN(maxY)) { upper = Math.max(upper, maxY); } } if (lower > upper) { return null; } else { return new Range(lower, upper); } }
From source file:cc.osint.graphd.graph.Graph.java
public JSONObject getShortestPath(String vFromKey, String vToKey, double radius) throws Exception { JSONVertex vFrom = getVertex(vFromKey); JSONVertex vTo = getVertex(vToKey);/* w ww .j a v a 2s . c om*/ List<JSONObject> results = new ArrayList<JSONObject>(); DijkstraShortestPath dsp = new DijkstraShortestPath(gr, vFrom, vTo, radius); GraphPath<JSONVertex, JSONEdge> path = dsp.getPath(); if (null == path) { return null; } else { if (path.getEdgeList().size() == 0) return null; JSONObject result = new JSONObject(); List<String> edges = new ArrayList<String>(); for (JSONEdge edge : path.getEdgeList()) { edges.add(edge.get(KEY_FIELD)); } result.put("weight", path.getWeight()); result.put("edges", edges); result.put("start_vertex", path.getStartVertex().getString(KEY_FIELD)); result.put("end_vertex", path.getEndVertex().getString(KEY_FIELD)); if (radius != Double.POSITIVE_INFINITY) { result.put("radius", radius); } return result; } }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.DefaultCapacityOriginator.java
private double determineStepwiseElasticityFactor(double rateRatio) { double[][] elasticity = null; if (elasticity == null) { elasticity = ParserFunctions//from w w w. j a v a 2 s . c o m .parseMapToDoubleArray(capacityStructure.elasticityModelXml.getAttribute("map")); } if (Math.abs(rateRatio - 1) < 0.01 || elasticity.length == 0) return 1.0; PowerType powerType = parentBundle.getPowerType(); if (powerType.isConsumption() && rateRatio < 1.0) return 1.0; if (powerType.isProduction() && rateRatio > 1.0) return 1.0; final int RATE_RATIO_INDEX = 0; final int CAPACITY_FACTOR_INDEX = 1; double rateLowerBound = Double.NEGATIVE_INFINITY; double rateUpperBound = Double.POSITIVE_INFINITY; double lowerBoundCapacityFactor = 1.0; double upperBoundCapacityFactor = 1.0; for (int i = 0; i < elasticity.length; ++i) { double r = elasticity[i][RATE_RATIO_INDEX]; if (r <= rateRatio && r > rateLowerBound) { rateLowerBound = r; lowerBoundCapacityFactor = elasticity[i][CAPACITY_FACTOR_INDEX]; } if (r >= rateRatio && r < rateUpperBound) { rateUpperBound = r; upperBoundCapacityFactor = elasticity[i][CAPACITY_FACTOR_INDEX]; } } return (rateRatio < 1) ? upperBoundCapacityFactor : lowerBoundCapacityFactor; }
From source file:beast.evolution.tree.RandomTree.java
private Node simulateCoalescent(final int isMonophyleticNode, final Map<String, Node> allCandidates, final Set<Node> candidates, final PopulationFunction demoFunction) throws ConstraintViolatedException { final List<Node> remainingCandidates = new ArrayList<>(); final Set<String> taxaDone = new TreeSet<>(); for (final int monoNode : children[isMonophyleticNode]) { // create list of leaf nodes for this monophyletic MRCA final Set<Node> candidates2 = new LinkedHashSet<>(); final Set<String> isTaxonSet = taxonSets.get(monoNode); for (String taxon : isTaxonSet) { candidates2.add(allCandidates.get(taxon)); }//from w w w. ja va 2 s . c om final Node MRCA = simulateCoalescent(monoNode, allCandidates, candidates2, demoFunction); remainingCandidates.add(MRCA); taxaDone.addAll(isTaxonSet); } for (final Node node : candidates) { if (!taxaDone.contains(node.getID())) { remainingCandidates.add(node); } } final double upper = isMonophyleticNode < m_bounds.size() ? m_bounds.get(isMonophyleticNode).upper : Double.POSITIVE_INFINITY; final Node MRCA = simulateCoalescentWithMax(remainingCandidates, demoFunction, upper); return MRCA; }
From source file:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java
/** * _more_//from w w w .j av a 2s .c o m * * @param v _more_ * * @return _more_ */ protected double checkWriteValue(double v) { if (v != v) { return MISSING; } if (v == Double.POSITIVE_INFINITY) { return Double.MAX_VALUE; } if (v == Double.NEGATIVE_INFINITY) { return -Double.MAX_VALUE; } return v; }
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static JFreeChart createPredictionBarChart(PredictionCenter center) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; String title = runner.getVariableString("title"); Object[] legends = (Object[]) runner.getVariableCell("legends"); Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = runner.getVariableString("Xlabel"); String yLabel = runner.getVariableString("Ylabel"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int numLegends = legends.length; int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0) .getTransactionTypeNames();// w w w . j a v a 2s . c om for (int i = 0; i < numLegends; ++i) { String legend = (String) legends[i]; for (int j = 0; j < transactionNames.size(); ++j) { if (legend.contains("Type " + (j + 1))) { legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j)); break; } } } for (int j = 0; j < transactionNames.size(); ++j) { if (xLabel.contains("Type " + (j + 1))) { xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int j = 0; j < transactionNames.size(); ++j) { if (yLabel.contains("Type " + (j + 1))) { yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int i = 0; i < numYCellArray; ++i) { runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { String category = ""; int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount; String legend = (String) legends[legendIdx]; if (numLegends == 0) { category = "Data " + dataCount + 1; } else if (dataCount >= numLegends) { category = legend + (dataCount + 1); } else { category = legend; } for (int r = 0; r < row; ++r) { double yValue = yArray[r + c * row]; // remove negatives. if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY || yValue == Double.NEGATIVE_INFINITY) { yValue = 0.0; } dataset.addValue(yValue, category, ""); } ++dataCount; } } JFreeChart chart = ChartFactory.createBarChart(title, xLabel, yLabel, dataset); return chart; }
From source file:com.opengamma.analytics.financial.model.finitedifference.CrankNicolsonFiniteDifference2D.java
public double[][] solve(final ConvectionDiffusion2DPDEDataBundle pdeData, final double[] timeGrid, final double[] xGrid, final double[] yGrid, final BoundaryCondition2D xLowerBoundary, final BoundaryCondition2D xUpperBoundary, final BoundaryCondition2D yLowerBoundary, final BoundaryCondition2D yUpperBoundary, @SuppressWarnings("unused") final Cube<Double, Double, Double, Double> freeBoundary) { Validate.notNull(pdeData, "pde data"); final int tNodes = timeGrid.length; final int xNodes = xGrid.length; final int yNodes = yGrid.length; Validate.isTrue(tNodes > 1, "need at least 2 time nodes"); Validate.isTrue(xNodes > 2, "need at least 3 x nodes"); Validate.isTrue(yNodes > 2, "need at least 3 y nodes"); // check grid and boundaries are consistent Validate.isTrue(Math.abs(xGrid[0] - xLowerBoundary.getLevel()) < 1e-7, "x grid not consistent with boundary level"); Validate.isTrue(Math.abs(xGrid[xNodes - 1] - xUpperBoundary.getLevel()) < 1e-7, "x grid not consistent with boundary level"); Validate.isTrue(Math.abs(yGrid[0] - yLowerBoundary.getLevel()) < 1e-7, "y grid not consistent with boundary level"); Validate.isTrue(Math.abs(yGrid[yNodes - 1] - yUpperBoundary.getLevel()) < 1e-7, "y grid not consistent with boundary level"); final double[] dt = new double[tNodes - 1]; for (int n = 0; n < tNodes - 1; n++) { dt[n] = timeGrid[n + 1] - timeGrid[n]; Validate.isTrue(dt[n] > 0, "time steps must be increasing"); }/*ww w .ja v a2 s .co m*/ final double[] dx = new double[xNodes - 1]; for (int i = 0; i < xNodes - 1; i++) { dx[i] = xGrid[i + 1] - xGrid[i]; Validate.isTrue(dx[i] > 0, "x steps must be increasing"); } final double[] dy = new double[yNodes - 1]; for (int i = 0; i < yNodes - 1; i++) { dy[i] = yGrid[i + 1] - yGrid[i]; Validate.isTrue(dy[i] > 0, "y steps must be increasing"); } // since the space grid is time independent, we can calculate the coefficients for derivatives once final double[][] x1st = new double[xNodes - 2][3]; final double[][] x2nd = new double[xNodes - 2][3]; for (int i = 0; i < xNodes - 2; i++) { x1st[i][0] = -dx[i + 1] / dx[i] / (dx[i] + dx[i + 1]); x1st[i][1] = (dx[i + 1] - dx[i]) / dx[i] / dx[i + 1]; x1st[i][2] = dx[i] / dx[i + 1] / (dx[i] + dx[i + 1]); x2nd[i][0] = 2 / dx[i] / (dx[i] + dx[i + 1]); x2nd[i][1] = -2 / dx[i] / dx[i + 1]; x2nd[i][2] = 2 / dx[i + 1] / (dx[i] + dx[i + 1]); } final double[][] y1st = new double[yNodes - 2][3]; final double[][] y2nd = new double[yNodes - 2][3]; for (int i = 0; i < yNodes - 2; i++) { y1st[i][0] = -dy[i + 1] / dy[i] / (dy[i] + dy[i + 1]); y1st[i][1] = (dy[i + 1] - dy[i]) / dy[i] / dy[i + 1]; y1st[i][2] = dy[i] / dy[i + 1] / (dy[i] + dy[i + 1]); y2nd[i][0] = 2 / dy[i] / (dy[i] + dy[i + 1]); y2nd[i][1] = -2 / dy[i] / dy[i + 1]; y2nd[i][2] = 2 / dy[i + 1] / (dy[i] + dy[i + 1]); } final int size = xNodes * yNodes; final double[][] v = new double[xNodes][yNodes]; final double[] u = new double[size]; final double[] q = new double[size]; int index = 0; for (int j = 0; j < yNodes; j++) { for (int i = 0; i < xNodes; i++) { u[index++] = pdeData.getInitialValue(xGrid[i], yGrid[j]); } } double a, b, c, d, e, f; final double[][] w = new double[size][9]; for (int n = 1; n < tNodes; n++) { for (int i = 1; i < xNodes - 1; i++) { for (int j = 1; j < yNodes - 1; j++) { index = j * xNodes + i; a = pdeData.getA(timeGrid[n - 1], xGrid[i], yGrid[j]); b = pdeData.getB(timeGrid[n - 1], xGrid[i], yGrid[j]); c = pdeData.getC(timeGrid[n - 1], xGrid[i], yGrid[j]); d = pdeData.getD(timeGrid[n - 1], xGrid[i], yGrid[j]); e = pdeData.getE(timeGrid[n - 1], xGrid[i], yGrid[j]); f = pdeData.getF(timeGrid[n - 1], xGrid[i], yGrid[j]); double sum = 0; if (_theta != 1.0) { sum -= a * (x2nd[i - 1][0] * u[index - 1] + x2nd[i - 1][1] * u[index] + x2nd[i - 1][2] * u[index + 1]); sum -= b * (x1st[i - 1][0] * u[index - 1] + x1st[i - 1][1] * u[index] + x1st[i - 1][2] * u[index + 1]); sum -= c * u[index]; sum -= d * (y2nd[j - 1][0] * u[index - xNodes] + y2nd[j - 1][1] * u[index] + y2nd[j - 1][2] * u[index + xNodes]); sum -= e * (x1st[i - 1][0] * (y1st[j - 1][0] * u[index - xNodes - 1] + y1st[j - 1][1] * u[index - 1] + y1st[j - 1][2] * u[index + xNodes - 1]) + x1st[i - 1][1] * (y1st[j - 1][0] * u[index - xNodes] + y1st[j - 1][1] * u[index] + y1st[j - 1][2] * u[index + xNodes]) + x1st[i - 1][2] * (y1st[j - 1][0] * u[index - xNodes + 1] + y1st[j - 1][1] * u[index + 1] + y1st[j - 1][2] * u[index + xNodes + 1])); sum -= f * (y1st[j - 1][0] * u[index - xNodes] + y1st[j - 1][1] * u[index] + y1st[j - 1][2] * u[index + xNodes]); sum *= (1 - _theta) * dt[n - 1]; } sum += u[index]; q[index] = sum; w[index][0] = _theta * dt[n - 1] * x1st[i - 1][0] * y1st[j - 1][0] * e; // i-1,j-1 w[index][1] = _theta * dt[n - 1] * (y2nd[j - 1][0] * d + x1st[i - 1][1] * y1st[j - 1][0] * e + y1st[j - 1][0] * f); // i,j-1 w[index][2] = -_theta * dt[n - 1] * x1st[i - 1][2] * y1st[j - 1][0] * e; // i+1,j-1 w[index][3] = _theta * dt[n - 1] * (x2nd[i - 1][0] * a + x1st[i - 1][0] * b + x1st[i - 1][0] * y1st[j - 1][1] * e); // i-1,j w[index][4] = 1 + _theta * dt[n - 1] * (x2nd[i - 1][1] * a + x1st[i - 1][1] * b + c + y2nd[j - 1][1] * d + x1st[i - 1][1] * y1st[j - 1][1] * e + y1st[j - 1][1] * f); // i,j w[index][5] = _theta * dt[n - 1] * (x2nd[i - 1][2] * a + x1st[i - 1][2] * b + x1st[i - 1][2] * y1st[j - 1][1] * e); // i+1,j w[index][6] = -_theta * dt[n - 1] * x1st[i - 1][0] * y1st[j - 1][2] * e; // i-1,j+1 w[index][7] = _theta * (y2nd[j - 1][2] * d + x1st[i - 1][1] * y1st[j - 1][2] * e + y1st[j - 1][2] * f); // i,j+1 w[index][8] = _theta * dt[n - 1] * x1st[i - 1][2] * y1st[j - 1][2] * e; // i+1,j+1 } } // The y boundary conditions final double[][][] yBoundary = new double[2][xNodes][]; for (int i = 0; i < xNodes; i++) { yBoundary[0][i] = yLowerBoundary.getLeftMatrixCondition(timeGrid[n], xGrid[i]); yBoundary[1][i] = yUpperBoundary.getLeftMatrixCondition(timeGrid[n], xGrid[i]); double[] temp = yLowerBoundary.getRightMatrixCondition(timeGrid[n], xGrid[i]); double sum = 0; for (int k = 0; k < temp.length; k++) { final int offset = k * xNodes; sum += temp[k] * u[offset + i]; } q[i] = sum + yLowerBoundary.getConstant(timeGrid[n], xGrid[i], dy[0]); // TODO need to change how boundary are calculated temp = yUpperBoundary.getRightMatrixCondition(timeGrid[n], xGrid[i]); sum = 0; for (int k = 0; k < temp.length; k++) { final int offset = (yNodes - 1 - k) * xNodes; sum += temp[k] * u[offset + i]; } q[i + (yNodes - 1) * xNodes] = sum + yUpperBoundary.getConstant(timeGrid[n], xGrid[i], dy[yNodes - 2]); } // The x boundary conditions final double[][][] xBoundary = new double[2][yNodes - 2][]; for (int j = 1; j < yNodes - 1; j++) { xBoundary[0][j - 1] = xLowerBoundary.getLeftMatrixCondition(timeGrid[n], yGrid[j]); xBoundary[1][j - 1] = xUpperBoundary.getLeftMatrixCondition(timeGrid[n], yGrid[j]); double[] temp = xLowerBoundary.getRightMatrixCondition(timeGrid[n], yGrid[j]); int offset = j * xNodes; double sum = 0; for (int k = 0; k < temp.length; k++) { sum += temp[k] * u[offset + k]; } q[offset] = sum + xLowerBoundary.getConstant(timeGrid[n], yGrid[j], dx[0]); temp = xUpperBoundary.getRightMatrixCondition(timeGrid[n], yGrid[j]); offset = (j + 1) * xNodes - 1; sum = 0; for (int k = 0; k < temp.length; k++) { sum += temp[k] * u[offset - k]; } q[offset] = sum + xUpperBoundary.getConstant(timeGrid[n], yGrid[j], dx[xNodes - 2]); } // SOR final double omega = 1.0; double scale = 1.0; double errorSqr = Double.POSITIVE_INFINITY; double sum; int l; while (errorSqr / (scale + 1e-10) > 1e-18) { errorSqr = 0.0; scale = 0.0; // solve for the innards first for (int i = 1; i < xNodes - 1; i++) { for (int j = 1; j < yNodes - 1; j++) { l = j * xNodes + i; sum = 0; sum += w[l][0] * u[l - xNodes - 1]; sum += w[l][1] * u[l - xNodes]; sum += w[l][2] * u[l - xNodes + 1]; sum += w[l][3] * u[l - 1]; sum += w[l][4] * u[l]; sum += w[l][5] * u[l + 1]; sum += w[l][6] * u[l + xNodes - 1]; sum += w[l][7] * u[l + xNodes]; sum += w[l][8] * u[l + xNodes + 1]; final double correction = omega / w[l][4] * (q[l] - sum); // if (freeBoundary != null) { // correction = Math.max(correction, freeBoundary.getZValue(t, x[j]) - f[j]); // } errorSqr += correction * correction; u[l] += correction; scale += u[l] * u[l]; } } // the lower y boundary for (int i = 0; i < xNodes; i++) { sum = 0; l = i; final double[] temp = yBoundary[0][i]; for (int k = 0; k < temp.length; k++) { final int offset = k * xNodes; sum += temp[k] * u[offset + i]; } final double correction = omega / temp[0] * (q[l] - sum); errorSqr += correction * correction; u[l] += correction; scale += u[l] * u[l]; } // the upper y boundary for (int i = 0; i < xNodes; i++) { sum = 0; l = xNodes * (yNodes - 1) + i; final double[] temp = yBoundary[1][i]; for (int k = 0; k < temp.length; k++) { final int offset = (yNodes - 1 - k) * xNodes; sum += temp[k] * u[offset + i]; } final double correction = omega / temp[0] * (q[l] - sum); errorSqr += correction * correction; u[l] += correction; scale += u[l] * u[l]; } // the lower x boundary for (int j = 1; j < yNodes - 1; j++) { sum = 0; l = j * xNodes; final double[] temp = xBoundary[0][j - 1]; for (int k = 0; k < temp.length; k++) { sum += temp[k] * u[l + k]; } final double correction = omega / temp[0] * (q[l] - sum); errorSqr += correction * correction; u[l] += correction; scale += u[l] * u[l]; } // the upper x boundary for (int j = 1; j < yNodes - 1; j++) { sum = 0; l = (j + 1) * xNodes - 1; final double[] temp = xBoundary[1][j - 1]; for (int k = 0; k < temp.length; k++) { sum += temp[k] * u[l - k]; } final double correction = omega / temp[0] * (q[l] - sum); errorSqr += correction * correction; u[l] += correction; scale += u[l] * u[l]; } } // end of SOR } // time loop // unpack vector to matrix for (int j = 0; j < yNodes; j++) { final int offset = j * xNodes; for (int i = 0; i < xNodes; i++) { v[i][j] = u[offset + i]; } } return v; }
From source file:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java
public double getInfectiousTime(AbstractCase thisCase) { if (!hasLatentPeriods) { return getInfectionTime(thisCase); } else {//from w w w .j a v a 2 s . co m if (recalculateCaseFlags[outbreak.getCaseIndex(thisCase)]) { if (thisCase.wasEverInfected()) { String latentCategory = ((CategoryOutbreak) outbreak).getLatentCategory(thisCase); Parameter latentPeriod = ((CategoryOutbreak) outbreak).getLatentPeriod(latentCategory); infectiousTimes[outbreak.getCaseIndex(thisCase)] = getInfectionTime(thisCase) + latentPeriod.getParameterValue(0); } else { infectiousTimes[outbreak.getCaseIndex(thisCase)] = Double.POSITIVE_INFINITY; } } return infectiousTimes[outbreak.getCaseIndex(thisCase)]; } }
From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.MultivariateNormalParameters.java
/** * {@inheritDoc}//from w w w. j av a 2 s . c om * <p> * Sets all means to zero and all covariances to infinity */ @Override public final void setUniform() { setMeanAndVariance(new double[_size], arrayOf(_size, Double.POSITIVE_INFINITY)); toInformationFormat(); }