List of usage examples for java.lang Double isNaN
public static boolean isNaN(double v)
From source file:copter.GpsdConnector.java
public void setTpvObject(TPVObject tpvObject) { if (!Double.isNaN(tpvObject.getLongitude()) && !Double.isNaN(tpvObject.getLatitude())) { tpvSetTimeMillis = System.currentTimeMillis(); this.tpvObject = tpvObject; }//from w w w. j a v a 2 s . co m }
From source file:com.cloudera.oryx.rdf.common.information.NumericalInformation.java
static Pair<Decision, Double> bestGain(Iterable<Decision> decisions, ExampleSet examples) { UpdatableVariance varianceNegativeStat = new UpdatableVariance(); // Start with everything considered a negative example: for (Example example : examples) { float value = ((NumericFeature) example.getTarget()).getValue(); varianceNegativeStat.increment(value); }//from w w w .jav a 2 s . c o m // Save this off double varianceAll = varianceNegativeStat.getResult(); if (Double.isNaN(varianceAll) || varianceAll <= 0.0) { // Weird case, no information at all return null; } // Entropy in nats is ln (stdev * sqrt(2*pi*e)) = ln(stdev) + 0.5*ln(2*pi*e) = 0.5*ln(variance) + ... // Actually to compute gain, we only need to know the ln(variance) since the additive constants will // fall out when we take the difference in entropies. //double entropyAll = 0.5 * Math.log(varianceAll) + HALF_LN_2_PI_E; double logVarianceAll = Math.log(varianceAll); List<Example> exampleList = examples.getExamples(); BitSet notYetPositiveExamples = new BitSet(exampleList.size()); notYetPositiveExamples.set(0, exampleList.size()); Decision bestDecision = null; double bestGain = Double.NEGATIVE_INFINITY; UpdatableVariance variancePositiveStat = new UpdatableVariance(); for (Decision decision : decisions) { boolean noChange = true; int nextNotYetPositive = -1; while ((nextNotYetPositive = notYetPositiveExamples.nextSetBit(nextNotYetPositive + 1)) >= 0) { Example example = exampleList.get(nextNotYetPositive); if (decision.isPositive(example)) { noChange = false; float value = ((NumericFeature) example.getTarget()).getValue(); varianceNegativeStat.decrement(value); variancePositiveStat.increment(value); notYetPositiveExamples.clear(nextNotYetPositive); } } if (noChange) { continue; } double variancePositive = variancePositiveStat.getResult(); double varianceNegative = varianceNegativeStat.getResult(); if (Double.isNaN(variancePositive) || variancePositive <= 0.0 || Double.isNaN(varianceNegative) || varianceNegative <= 0.0) { continue; } //double entropyNegative = 0.5 * Math.log(varianceNegative) + HALF_LN_2_PI_E; //double entropyPositive = 0.5 * Math.log(variancePositive) + HALF_LN_2_PI_E; double logVarianceNegative = Math.log(varianceNegative); double logVariancePositive = Math.log(variancePositive); long numNegative = varianceNegativeStat.getN(); long numPositive = variancePositiveStat.getN(); //double oldgain = entropyAll - // (numNegative * entropyNegative + numPositive * entropyPositive) / (numNegative + numPositive); double gain = 0.5 * (logVarianceAll - (numNegative * logVarianceNegative + numPositive * logVariancePositive) / (numNegative + numPositive)); if (gain > bestGain) { bestGain = gain; bestDecision = decision; } } return bestDecision == null ? null : new Pair<Decision, Double>(bestDecision, bestGain); }
From source file:cn.edu.pku.cbi.mosaichunter.math.WilcoxonRankSumTest.java
public static double twoSided(double[] x, double[] y) { int nx = x.length; int ny = y.length; double[] v = new double[nx + ny]; Arrays.sort(x);// w w w . j a va 2 s. c o m System.arraycopy(x, 0, v, 0, nx); System.arraycopy(y, 0, v, nx, ny); Arrays.sort(v); double[] u = new double[v.length]; double[] rank = new double[v.length]; int[] cnt = new int[v.length]; int n = 0; for (int i = 0; i < v.length; ++i) { if (i == 0 || v[i] - v[i - 1] > EPS) { u[n] = v[i]; n++; } cnt[n - 1]++; rank[n - 1] += i + 1; } for (int i = 0; i < n; ++i) { rank[i] /= cnt[i]; } double stats = 0; int j = 0; for (int i = 0; i < nx; ++i) { while (x[i] > u[j] + EPS) { j++; } stats += rank[j]; } stats -= nx * (nx + 1) / 2; double z = stats - x.length * y.length / 2; double tmp = 0; for (int i = 0; i < n; ++i) { tmp += (double) cnt[i] * cnt[i] * cnt[i] - cnt[i]; } double sigma = Math.sqrt(((double) nx * ny / 12) * (nx + ny + 1 - tmp / (nx + ny) / (nx + ny - 1))); if (z > EPS) { z -= 0.5; } else if (z < -EPS) { z += 0.5; } z /= sigma; double p = new NormalDistribution().cumulativeProbability(z); double pValue = 2 * Math.min(p, 1 - p); if (Double.isNaN(pValue)) { return 1; } return pValue; }
From source file:com.opengamma.analytics.math.interpolation.PiecewiseCubicHermiteSplineInterpolatorWithSensitivity.java
@Override public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues, final double[] yValues) { ArgumentChecker.notNull(xValues, "xValues"); ArgumentChecker.notNull(yValues, "yValues"); ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length"); ArgumentChecker.isTrue(xValues.length > 1, "Data points should be more than 1"); final int nDataPts = xValues.length; for (int i = 0; i < nDataPts; ++i) { ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity"); ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity"); }/* w w w . ja v a2 s . c om*/ double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts); double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts); ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt); for (int i = 1; i < nDataPts; ++i) { ArgumentChecker.isFalse(xValuesSrt[i - 1] == xValuesSrt[i], "xValues should be distinct"); } final DoubleMatrix2D[] temp = solve(xValuesSrt, yValuesSrt); // check the matrices // TODO remove some of these tests ArgumentChecker.noNulls(temp, "error in solve - some matrices are null"); int n = temp.length; ArgumentChecker.isTrue(n == nDataPts, "wrong number of matricies"); for (int k = 0; k < n; k++) { DoubleMatrix2D m = temp[k]; final int rows = m.getNumberOfRows(); final int cols = m.getNumberOfColumns(); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { ArgumentChecker.isTrue(Doubles.isFinite(m.getEntry(i, j)), "Matrix contains a NaN or infinite"); } } } DoubleMatrix2D coefMatrix = temp[0]; DoubleMatrix2D[] coefMatrixSense = new DoubleMatrix2D[n - 1]; System.arraycopy(temp, 1, coefMatrixSense, 0, n - 1); return new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(xValuesSrt), coefMatrix, 4, 1, coefMatrixSense); }
From source file:com.rapidminer.tools.expression.internal.function.statistical.Binominal.java
@Override protected double compute(double value1, double value2) { // special case for handling missing values if (Double.isNaN(value1) || Double.isNaN(value2)) { return Double.NaN; }/*from w ww . j a v a 2s . co m*/ if (value1 < 0 || value2 < 0) { throw new FunctionInputException("expression_parser.function_non_negative", getFunctionName()); } // This is the common definition for the case for k > n. if (value2 > value1) { return 0; } else { return CombinatoricsUtils.binomialCoefficientDouble((int) value1, (int) value2); } }
From source file:com.insightml.data.features.stats.FeatureStatistics.java
public FeatureStatistics(final ISamples<?, Double> instances, final int labelIndex) { this.instances = instances; this.labelIndex = labelIndex; final String[] featureNames = this.instances.featureNames(); final double[][] feats = this.instances.features(); final IntSumMapBuilder<CharSequence> nan = IntSumMap.builder(false, 16); for (int i = 0; i < this.instances.size(); ++i) { for (int j = 0; j < featureNames.length; ++j) { final double value = feats[i][j]; if (Double.isNaN(value) || value == Double.NEGATIVE_INFINITY) { nan.increment(featureNames[j], 1); } else { stats.getOrLoad(featureNames[j]).addValue(value); }/*w ww.j a v a 2 s. c om*/ } } nans = nan.build(0); }
From source file:it.unibo.alchemist.model.implementations.timedistributions.ExponentialTime.java
@Override public void updateStatus(final Time curTime, final boolean executed, final double newpropensity, final Environment<T> env) { assert !Double.isNaN(newpropensity); assert !Double.isNaN(oldPropensity); if (oldPropensity == 0 && newpropensity != 0) { update(newpropensity, true, curTime); } else if (oldPropensity != 0 && newpropensity != 0) { update(newpropensity, executed, curTime); } else if (oldPropensity != 0 && newpropensity == 0) { setTau(DoubleTime.INFINITE_TIME); }//ww w .j a v a 2s . c o m oldPropensity = newpropensity; }
From source file:com.graphhopper.api.WebHelper.java
public static GHPoint toGHPoint(JSONArray point) { if (point.length() == 3 && !Double.isNaN(point.getDouble(2))) { return new GHPoint3D(point.getDouble(1), point.getDouble(0), point.getDouble(2)); }/* w ww . j av a2s . c o m*/ return new GHPoint(point.getDouble(1), point.getDouble(0)); }
From source file:com.joptimizer.util.CholeskyFactorization.java
/** * Cholesky factorization L of psd matrix, Q = L.LT *///ww w. j a v a 2 s . c o m private void factorize() throws Exception { if (!MatrixUtils.isSymmetric(new Array2DRowRealMatrix(Q), Utils.getDoubleMachineEpsilon())) { throw new Exception("Matrix is not symmetric"); } int N = Q.length; double[][] L = new double[N][N]; this.eigenvalues = new ArrayList<Double>(); for (int i = 0; i < N; i++) { for (int j = 0; j <= i; j++) { double sum = 0.0; for (int k = 0; k < j; k++) { sum += L[i][k] * L[j][k]; } if (i == j) { double d = Math.sqrt(Q[i][i] - sum); if (Double.isNaN(d) || d * d < Utils.getDoubleMachineEpsilon()) {//d*d is a Q's eigenvalue Log.w(MainActivity.JOPTIMIZER_LOGTAG, "Not positive eigenvalues: " + d * d); throw new Exception("not positive definite matrix"); } L[i][i] = d; this.eigenvalues.add(this.eigenvalues.size(), d * d); } else { L[i][j] = 1.0 / L[j][j] * (Q[i][j] - sum); } } } this.L = L; }
From source file:gdsc.smlm.ij.utils.Utils.java
/** * Round the double to the specified significant digits * //from w w w .j a v a 2 s .co m * @param d * @param significantDigits * @return */ public static String rounded(double d, int significantDigits) { if (Double.isInfinite(d) || Double.isNaN(d)) return "" + d; BigDecimal bd = new BigDecimal(d); bd = bd.round(new MathContext(significantDigits)); return "" + bd.doubleValue(); }