List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:net.sourceforge.jabm.report.StrategyExecutionFrequency.java
public double getPercentage(String tag) { double result = executionFrequency.getPct(tag); if (Double.isNaN(result)) { result = 0.0;/* w w w . j ava2s .c om*/ } return result; }
From source file:bide.core.par.Spot.java
private double[] formatSpot(double[] spot) { int express = 0; ArrayList<Double> expressSpot = new ArrayList<Double>(); for (int i = 0; i < spot.length; i++) { if (!Double.isNaN(spot[i])) { express++;/* w w w . j a v a2 s . c o m*/ expressSpot.add(spot[i]); } } double[] expSpot = ArrayUtils.toPrimitive(expressSpot.toArray(new Double[express])); return expSpot; }
From source file:com.clust4j.utils.VectorTests.java
@Test public void test() { final double[] a = new double[] { 0, 1, 2, 3, 4 }; double sum = 0; double mean = 0; assertTrue((sum = VecUtils.sum(a)) == 10); assertTrue((mean = VecUtils.mean(a)) == 2); assertTrue(VecUtils.mean(a, sum) == 2); assertTrue(VecUtils.stdDev(a, mean) == VecUtils.stdDev(a)); assertTrue(Double.isNaN(VecUtils.mean(empty))); }
From source file:dr.app.gui.chart.PDFPlot.java
/** * Set up the axis with some data//from www. j av a 2 s .co m */ public void setupAxis(Axis xAxis, Axis yAxis, Variate xData, Variate yData) { if (distribution == null) { return; } double quantile01 = distribution.quantile(0.01); double quantile99 = distribution.quantile(0.99); // if the distribution has a bound then use it, otherwise find a range using a small quantile if (!Double.isInfinite(distribution.getProbabilityDensityFunction().getLowerBound())) { // the actual bound may be undefined so come just inside it... xMin = distribution.getProbabilityDensityFunction().getLowerBound(); double value = distribution.getProbabilityDensityFunction().evaluate(xMin); if (Double.isNaN(value) || Double.isInfinite(value)) { xMin = Math.max(quantile01, distribution.getProbabilityDensityFunction().getLowerBound() + 1E-100); } } else { xMin = quantile01; } // if the distribution has a bound then use it, otherwise find a range using a small quantile if (!Double.isInfinite(distribution.getProbabilityDensityFunction().getUpperBound())) { // the actual bound may be undefined so come just inside it... xMax = distribution.getProbabilityDensityFunction().getUpperBound(); double value = distribution.getProbabilityDensityFunction().evaluate(xMax); if (Double.isNaN(value) || Double.isInfinite(value)) { xMax = Math.min(quantile99, distribution.getProbabilityDensityFunction().getUpperBound() - 1E-100); } } else { xMax = quantile99; } if (Double.isNaN(xMin) || Double.isInfinite(xMin)) { xMin = 0.0; } if (Double.isNaN(xMax) || Double.isInfinite(xMax)) { xMax = 1.0; } if (xMin == xMax) xMax += 1; double x = xMin + offset; yMax = distribution.pdf(x - offset); double step = (xMax - xMin) / stepCount; for (int i = 1; i < stepCount; i++) { x += step; double y = distribution.pdf(x - offset); if (y > yMax) yMax = y; } if (xAxis instanceof LogAxis) { throw new IllegalArgumentException("Log axis are not compatible to PDFPlot"); } else { xAxis.setRange(offset + xMin, offset + xMax); } if (yAxis instanceof LogAxis) { throw new IllegalArgumentException("Log axis are not compatible to PDFPlot"); } else { yAxis.setRange(0.0, yMax * (1.0 + headRoom)); } }
From source file:io.warp10.continuum.gts.GTSOutliersHelper.java
protected static double min(GeoTimeSerie gts) throws WarpScriptException { double min = gts.doubleValues[0]; if (Double.isNaN(min)) { throw new WarpScriptException("Method min: GTS contains NaN"); }// w w w . j a va 2 s .co m for (int i = 1; i < gts.values; i++) { if (min > gts.doubleValues[i]) { min = gts.doubleValues[i]; } } return min; }
From source file:com.clust4j.algo.preprocess.WeightTransformer.java
/** * Inverse transform the incoming data. If the corresponding weight is 0.0, * will coerce the column to positive infinity rather than NaN. *//*w w w . j av a 2 s .co m*/ @Override public RealMatrix inverseTransform(RealMatrix data) { checkFit(); final int m = data.getRowDimension(); if (data.getColumnDimension() != n) throw new DimensionMismatchException(n, data.getColumnDimension()); double[][] X = data.getData(); double weight, val; for (int j = 0; j < n; j++) { weight = weights[j]; for (int i = 0; i < m; i++) { // sometimes, weight can be 0.0 if the user is masochistic... val = X[i][j] / weight; X[i][j] = Double.isNaN(val) ? Inf : val; } } // assign -- already copied in getData() return new Array2DRowRealMatrix(X, false); }
From source file:juicebox.matrix.RealMatrixWrapper.java
private void computePercentiles() { // Statistics, other attributes DoubleArrayList flattenedDataList = new DoubleArrayList( matrix.getColumnDimension() * matrix.getRowDimension()); double min = 1; double max = -1; for (int i = 0; i < matrix.getRowDimension(); i++) { for (int j = 0; j < matrix.getColumnDimension(); j++) { double value = matrix.getEntry(i, j); if (!Double.isNaN(value) && value != 1) { min = value < min ? value : min; max = value > max ? value : max; flattenedDataList.add(value); }/*from ww w.j a v a2 s . co m*/ } } // Stats double[] flattenedData = flattenedDataList.toArray(); lowerValue = (float) StatUtils.percentile(flattenedData, 5); upperValue = (float) StatUtils.percentile(flattenedData, 95); System.out.println(lowerValue + " " + upperValue); }
From source file:com.joptimizer.optimizers.BarrierMethod.java
@Override public int optimize() throws Exception { Log.i(MainActivity.JOPTIMIZER_LOGTAG, "optimize"); long tStart = System.currentTimeMillis(); OptimizationResponse response = new OptimizationResponse(); // @TODO: check assumptions!!! // if(getA()!=null){ // if(ALG.rank(getA())>=getA().rows()){ // throw new IllegalArgumentException("A-rank must be less than A-rows"); // }// ww w . j a v a 2 s . co m // } DoubleMatrix1D X0 = getInitialPoint(); if (X0 == null) { DoubleMatrix1D X0NF = getNotFeasibleInitialPoint(); if (X0NF != null) { double rPriX0NFNorm = Math.sqrt(ALG.norm2(rPri(X0NF))); if (rPriX0NFNorm <= getToleranceFeas() && !Double.isNaN(this.barrierFunction.value(X0NF.toArray()))) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "the provided initial point is already feasible"); X0 = X0NF; } // DoubleMatrix1D fiX0NF = getFi(X0NF); // int maxIndex = Utils.getMaxIndex(fiX0NF); // double maxValue = fiX0NF.get(maxIndex); // if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"X0NF : " + ArrayUtils.toString(X0NF.toArray())); // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"fiX0NF: " + ArrayUtils.toString(fiX0NF.toArray())); // } // if(maxValue<0){ // //the provided not-feasible starting point is already feasible // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"the provided initial point is already feasible"); // X0 = X0NF; // } } if (X0 == null) { BasicPhaseIBM bf1 = new BasicPhaseIBM(this); X0 = F1.make(bf1.findFeasibleInitialPoint()); } } //check X0 feasibility double rPriX0Norm = Math.sqrt(ALG.norm2(rPri(X0))); if (Double.isNaN(this.barrierFunction.value(X0.toArray())) || rPriX0Norm > getToleranceFeas()) { throw new Exception("initial point must be strictly feasible"); } // DoubleMatrix1D fiX0 = getFi(X0); // if(fiX0!=null){ // int maxIndex = Utils.getMaxIndex(fiX0); // double maxValue = fiX0.get(maxIndex); // if(maxValue >= 0){ // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"ineqX0 : " + ArrayUtils.toString(fiX0.toArray())); // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"max ineq index: " + maxIndex); // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"max ineq value: " + maxValue); // throw new Exception("initial point must be strictly feasible"); // } // } DoubleMatrix1D V0 = (getA() != null) ? F1.make(getA().rows()) : F1.make(0); if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X0: " + ArrayUtils.toString(X0.toArray())); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "V0: " + ArrayUtils.toString(V0.toArray())); } DoubleMatrix1D X = X0; final int dim = X.size(); double t = 1d; int outerIteration = 0; while (true) { outerIteration++; if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "outerIteration: " + outerIteration); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X=" + ArrayUtils.toString(X.toArray())); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "f(X)=" + getF0(X)); } //Stopping criterion: quit if gap < tolerance. double gap = this.barrierFunction.getDualityGap(t); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "gap: " + gap); if (gap <= getTolerance()) { break; } // custom exit condition if (checkCustomExitConditions(X)) { response.setReturnCode(OptimizationResponse.SUCCESS); break; } //Centering step: compute x*(t) by minimizing tf0 + phi (the barrier function), subject to Ax = b, starting at x. final double tIter = t; Log.d(MainActivity.JOPTIMIZER_LOGTAG, "t: " + tIter); ConvexMultivariateRealFunction newObjectiveFunction = new ConvexMultivariateRealFunction() { public double value(double[] X) { DoubleMatrix1D x = F1.make(X); double phi = barrierFunction.value(X); return tIter * getF0(x) + phi; } public double[] gradient(double[] X) { DoubleMatrix1D x = F1.make(X); DoubleMatrix1D phiGrad = F1.make(barrierFunction.gradient(X)); return getGradF0(x).assign(Mult.mult(tIter)).assign(phiGrad, Functions.plus).toArray(); } public double[][] hessian(double[] X) { DoubleMatrix1D x = F1.make(X); DoubleMatrix2D hessF0X = getHessF0(x); double[][] hessX = barrierFunction.hessian(X); if (hessX == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER) { return hessF0X.assign(Mult.mult(tIter)).toArray(); } else { DoubleMatrix2D phiHess = F2.make(hessX); return hessF0X.assign(Mult.mult(tIter)).assign(phiHess, Functions.plus).toArray(); } } public int getDim() { return dim; } }; //NB: cannot use the same request object for the inner step OptimizationRequest or = new OptimizationRequest(); or.setA((getA() != null) ? getA().toArray() : null); or.setAlpha(getAlpha()); or.setB((getB() != null) ? getB().toArray() : null); or.setBeta(getBeta()); or.setCheckKKTSolutionAccuracy(isCheckKKTSolutionAccuracy()); or.setCheckProgressConditions(isCheckProgressConditions()); or.setF0(newObjectiveFunction); or.setInitialPoint(X.toArray()); or.setMaxIteration(getMaxIteration()); or.setMu(getMu()); or.setTolerance(getToleranceInnerStep()); or.setToleranceKKT(getToleranceKKT()); BarrierNewtonLEConstrainedFSP opt = new BarrierNewtonLEConstrainedFSP(true, this); opt.setOptimizationRequest(or); if (opt.optimize() == OptimizationResponse.FAILED) { response.setReturnCode(OptimizationResponse.FAILED); break; } OptimizationResponse newtonResponse = opt.getOptimizationResponse(); //Update. x := x*(t). X = F1.make(newtonResponse.getSolution()); // //Stopping criterion: quit if gap < tolerance. // double gap = this.barrierFunction.getDualityGap(t); // Log.d(MainActivity.JOPTIMIZER_LOGTAG,"gap: "+gap); // if(gap <= getTolerance()){ // break; // } // // // custom exit condition // if(checkCustomExitConditions(X)){ // response.setReturnCode(OptimizationResponse.SUCCESS); // break; // } //Increase t: t := mu*t. t = getMu() * t; // iteration limit condition if (outerIteration == getMaxIteration()) { response.setReturnCode(OptimizationResponse.WARN); Log.w(MainActivity.JOPTIMIZER_LOGTAG, "Max iterations limit reached"); break; } } long tStop = System.currentTimeMillis(); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "time: " + (tStop - tStart)); response.setSolution(X.toArray()); setOptimizationResponse(response); return response.getReturnCode(); }
From source file:org.talend.dataprofiler.chart.preview.DQRuleItemLabelGenerator.java
/** * DOC yyin Comment method "stringformat". * /*from w w w .ja v a 2 s .co m*/ * @param percent * @param i * @return */ private Object stringformat(Object percent, int i) { // ADD msjian TDQ-10793: when there is no data, the percent value is NaN if (Double.isNaN((double) percent)) { return String.valueOf(Double.NaN); } // TDQ-10793~ BigDecimal zero = new BigDecimal(0); BigDecimal temp = new BigDecimal(percent.toString()); BigDecimal min = new BigDecimal(10E-5); BigDecimal max = new BigDecimal(9999 * 10E-5); boolean isUseScientific = false; if (temp.compareTo(min) == -1 && temp.compareTo(zero) == 1) { isUseScientific = true; } else if (temp.compareTo(max) == 1 && temp.compareTo(new BigDecimal(1)) == -1) { percent = max.toString(); } DecimalFormat format = (DecimalFormat) DecimalFormat.getPercentInstance(Locale.ENGLISH); format.applyPattern("0.00%"); //$NON-NLS-1$ if (isUseScientific) { format.applyPattern("0.###E0%"); //$NON-NLS-1$ } return format.format(new Double(percent.toString())); }
From source file:fll.util.JsonUtilities.java
public static String generateJsonBracketInfo(final String division, final Map<Integer, Integer> ids, final Connection connection, final PerformanceScoreCategory perf, final BracketData bracketData, final boolean showOnlyVerifiedScores, final boolean showFinalsScores) { List<BracketLeafResultSet> datalist = new LinkedList<BracketLeafResultSet>(); try {//from w w w . j a v a2 s . c o m final int currentTournament = Queries.getCurrentTournament(connection); for (Map.Entry<Integer, Integer> entry : ids.entrySet()) { final int row = entry.getKey(); final int playoffRound = entry.getValue(); final TeamBracketCell tbc = (TeamBracketCell) bracketData.getData(playoffRound, row); if (tbc == null) { return "{\"refresh\":\"true\"}"; } final int numPlayoffRounds = Queries.getNumPlayoffRounds(connection); final int teamNumber = tbc.getTeam().getTeamNumber(); final int runNumber = Playoff.getRunNumber(connection, division, teamNumber, playoffRound); final TeamScore teamScore = new DatabaseTeamScore("Performance", currentTournament, teamNumber, runNumber, connection); final double computedTeamScore = perf.evaluate(teamScore); final boolean realScore = !Double.isNaN(computedTeamScore); final boolean noShow = Queries.isNoShow(connection, currentTournament, tbc.getTeam().getTeamNumber(), runNumber); // Sane request checks if (noShow) { datalist.add(new BracketLeafResultSet(tbc, -2.0, row + "-" + playoffRound)); } else if (!realScore || !showOnlyVerifiedScores || Queries.isVerified(connection, currentTournament, teamNumber, runNumber)) { if ((playoffRound == numPlayoffRounds && !showFinalsScores) || !realScore) { datalist.add(new BracketLeafResultSet(tbc, -1.0, row + "-" + playoffRound)); } else { datalist.add(new BracketLeafResultSet(tbc, computedTeamScore, row + "-" + playoffRound)); } } } } catch (final SQLException e) { throw new RuntimeException(e); } if (datalist.size() == 0) { // Add some data, JSON is happy datalist.add(new BracketLeafResultSet()); } try { final ObjectMapper jsonMapper = new ObjectMapper(); return jsonMapper.writeValueAsString(datalist); } catch (final JsonProcessingException e) { throw new RuntimeException(e); } }