List of usage examples for java.lang Double NaN
double NaN
To view the source code for java.lang Double NaN.
Click Source Link
From source file:com.joptimizer.optimizers.NewtonUnconstrained.java
@Override public int optimize() throws Exception { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "optimize"); OptimizationResponse response = new OptimizationResponse(); // checking responsibility if (getA() != null || getFi() != null) { // forward to the chain return forwardOptimizationRequest(); }// w w w .java 2 s. com if (getF0() instanceof StrictlyConvexMultivariateRealFunction) { // OK, it's my duty } else { throw new Exception("Unsolvable problem"); } long tStart = System.currentTimeMillis(); DoubleMatrix1D X0 = getInitialPoint(); if (X0 == null) { X0 = F1.make(getDim()); } if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X0: " + ArrayUtils.toString(X0.toArray())); } DoubleMatrix1D X = X0; double previousLambda = Double.NaN; int iteration = 0; while (true) { iteration++; double F0X = getF0(X); if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "iteration " + iteration); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X=" + ArrayUtils.toString(X.toArray())); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "f(X)=" + F0X); } // custom exit condition if (checkCustomExitConditions(X)) { response.setReturnCode(OptimizationResponse.SUCCESS); break; } DoubleMatrix1D gradX = getGradF0(X); DoubleMatrix2D hessX = getHessF0(X); // Newton step and decrement DoubleMatrix1D step = calculateNewtonStep(hessX, gradX); //DoubleMatrix1D step = calculateNewtonStepCM(hessX, gradX); if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "step: " + ArrayUtils.toString(step.toArray())); } //Newton decrement double lambda = Math.sqrt(-ALG.mult(gradX, step)); Log.d(MainActivity.JOPTIMIZER_LOGTAG, "lambda: " + lambda); if (lambda / 2. <= getTolerance()) { response.setReturnCode(OptimizationResponse.SUCCESS); break; } // iteration limit condition if (iteration == getMaxIteration()) { response.setReturnCode(OptimizationResponse.WARN); Log.w(MainActivity.JOPTIMIZER_LOGTAG, "Max iterations limit reached"); break; } // progress conditions if (isCheckProgressConditions()) { Log.d(MainActivity.JOPTIMIZER_LOGTAG, "previous: " + previousLambda); if (!Double.isNaN(previousLambda) && previousLambda <= lambda) { Log.w(MainActivity.JOPTIMIZER_LOGTAG, "No progress achieved, exit iterations loop without desired accuracy"); response.setReturnCode(OptimizationResponse.WARN); break; } } previousLambda = lambda; // backtracking line search double s = 1d; DoubleMatrix1D X1 = null; int cnt = 0; while (cnt < 25) { cnt++; // @TODO: can we use semplification 9.7.1 (Pre-computation for line searches)? X1 = X.copy().assign(step.copy().assign(Mult.mult(s)), Functions.plus);// x + t*step double condSX = getF0(X1); //NB: this will also check !Double.isNaN(getF0(X1)) double condDX = F0X + getAlpha() * s * ALG.mult(gradX, step); if (condSX <= condDX) { break; } s = getBeta() * s; } Log.d(MainActivity.JOPTIMIZER_LOGTAG, "s: " + s); // update X = X1; } 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.jfree.data.time.ohlc.OHLCItem.java
/** * Returns the open value.// w ww. j ava 2 s . c o m * * @return The open value. */ public double getOpenValue() { OHLC ohlc = (OHLC) getObject(); if (ohlc != null) { return ohlc.getOpen(); } else { return Double.NaN; } }
From source file:jasima.core.random.continuous.DblDistribution.java
@Override public double getNumericalMean() { if (distribution == null) { return Double.NaN; } else {//from www . ja v a 2 s . co m return distribution.getNumericalMean(); } }
From source file:mop.MemoryLogger.java
/** * Registers the memory consumption independent of any internal event counter or timestamp. Flag MEMORY_LOGGING has * to be activated./* w ww.java 2s . c o m*/ */ public void reallyLogMemoryConsumption() { if (STATS_LOGGING) { double memoryConsumption = (((double) (Runtime.getRuntime().totalMemory() / 1024) / 1024) - ((double) (Runtime.getRuntime().freeMemory() / 1024) / 1024)); // filter NaNs if (memoryConsumption != Double.NaN) { memStats.addValue(memoryConsumption); } else { NaNcount++; } } }
From source file:com.clust4j.algo.ClustTests.java
@Test(expected = NaNException.class) public void testNanException() { final double[][] train_array = new double[][] { new double[] { 0.0, 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.3, Double.NaN, 4.0 }, new double[] { 9.06, 12.6, 6.5, 9.0 } }; final Array2DRowRealMatrix mat = new Array2DRowRealMatrix(train_array); new NearestNeighbors(mat, 1); }
From source file:edu.cudenver.bios.power.glmm.GLMMTestWilksLambda.java
/** * Calculate the denominator degrees of freedom for the WL, based on * whether the null or alternative hypothesis is assumed true. * /*from w w w. j a v a2 s . c o m*/ * @param type distribution type * @return denominator degrees of freedom * @throws IllegalArgumentException */ @Override public double getDenominatorDF(DistributionType type) { // a = #rows in between subject contrast matrix, C double a = C.getRowDimension(); // b = #columns in within subject contrast matrix double b = U.getColumnDimension(); double df = Double.NaN; // double gDenominator = (a*a + b*b - 5); // if (gDenominator == 0) // throw new IllegalArgumentException("Within and between subject contrasts yielded divide by zero: row of C=" + a + ", cols of U=" + b); // double g = Math.sqrt((a*a*b*b - 4) / gDenominator); // df = (g*((N - r) - (b - a +1)/2)) - (a*b - 2)/2; if (a * a * b * b <= 4) { df = totalN - rank - b + 1; } else { double gDenominator = (a * a + b * b - 5); if (gDenominator == 0) throw new IllegalArgumentException( "Within and between subject contrasts yielded divide by zero: row of C=" + a + ", cols of U=" + b); double g = Math.sqrt((a * a * b * b - 4) / gDenominator); df = (g * ((totalN - rank) - (b - a + 1) / 2)) - (a * b - 2) / 2; } return df; }
From source file:es.udc.gii.common.eaf.benchmark.real_param.ShekelFamilyObjectiveFunction.java
private double getOptimumValue() { double opt = Double.NaN; double[] optimum = new double[4]; for (int i = 0; i < 4; i++) { optimum[i] = 4.0 / 5.0 - 1.0;/*from w ww .j a v a2 s .c om*/ } opt = this.shekel(optimum); return opt; }
From source file:beast.math.distributions.BetaDistribution.java
/** * probability density function of the distribution * * @param x argument/*from w w w . j av a 2s . co m*/ * @return pdf value */ public double pdf(double x) { recomputeZ(); if (x < 0 || x > 1) { return 0; } else if (x == 0) { if (alpha < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } return 0; } else if (x == 1) { if (beta < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 1 when beta = %.3g", beta); } return 0; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z); } }
From source file:org.talend.dataprofiler.chart.preview.DQRuleItemLabelGenerator.java
/** * DOC yyin Comment method "stringformat". * // w ww . j a v a 2 s .c om * @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:geogebra.util.MyMath.java
final public static double gammaIncompleteRegularized(double a, double x) { try {// w w w . j av a2s .co m return Gamma.regularizedGammaP(a, x); } catch (MathException e) { return Double.NaN; } }