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:Main.java
/** This function performs a polynomial interpolation using a set of * given x and y values. It uses Neville's interpolation algorithm. * @param xa the array of known x-values * @param ya the array of known y-values * @param x the x value for which the y value will be computed * @return the corresponding y value/*from ww w .j a va2s . c om*/ */ public static double interpolate(double xa[], double ya[], double x) { /* Given arrays xa[1..n] and ya[1..n], and given a value x, this routine returns a value y. If P(x) is the polynomial of degree N ? 1 such that P(xa[i]) = ya[i]; i = 1...n, then the returned value y = P(x). */ if (xa.length != ya.length || xa.length == 0 || ya.length == 0) { System.out.println("** Invalid Parameter"); return Double.NaN; } int n = xa.length; double y = 0.0; double dy = 0.0; int i, m, ns = 1; double den, dif, dift, ho, hp, w; double[] c = new double[n]; double[] d = new double[n]; dif = Math.abs(x - xa[0]); for (i = 0; i < n; i++) { // Here we find the index ns of the closest table entry, if ((dift = Math.abs(x - xa[i])) < dif) { ns = i; dif = dift; } c[i] = ya[i]; // and initialize the tableau of c's and d's. d[i] = ya[i]; } y = ya[ns--]; // This is the initial approximation to y. //System.out.println("** y ~ "+y); for (m = 0; m < n - 1; m++) { // For each column of the tableau, for (i = 0; i < n - m - 1; i++) { // we loop over the current c's and d's and update them. //System.out.println("** m = "+m+", i = "+i); ho = xa[i] - x; hp = xa[i + m + 1] - x; w = c[i + 1] - d[i]; if ((den = ho - hp) == 0.0) { return Double.NaN; } // This error can occur only if two input xa's are (to within roundof identical. //System.out.println("** ho = "+ho+", hp = "+hp); den = w / den; d[i] = hp * den; // Here the c's and d's are updated. c[i] = ho * den; //System.out.println("** c[i] = "+c[i]+", d[i] = "+d[i]); } y += (dy = (2 * (ns + 1) < (n - m) ? c[ns + 1] : d[ns--])); //System.out.println("** dy = "+dy+", y = "+y); /* After each column in the tableau is completed, we decide which correction, c or d, we want to add to our accumulating value of y, i.e., which path to take through the tableau forking up or down. We do this in such a way as to take the most "straight line" route through the tableau to its apex, updating ns accordingly to keep track of where we are. This route keeps the partial approximations centered (insofar as possible) on the target x. The last dy added is thus the error indication. */ } return y; }
From source file:analysis.SilhouetteIndex.java
public double calculateIndex(SimpleKMeans sk, Instances inst, int c) throws Exception { //Map<Integer, Instances> clustermap = sk.clusterInstance; sk.setNumClusters(c);//from www . j a v a 2 s . c om sk.buildClusterer(inst); EuclideanDistance ed = new EuclideanDistance(); double avgSilhouetteOverAllPoints = 0.d; if (sk.getNumClusters() == 1) { //Index is not defined for k=1. needs at least 2 clusters return Double.NaN; } for (int i = 0; i < inst.numInstances(); i++) { //for the current element get its cluster int currentcluster = sk.clusterInstance(inst.instance(i)); //System.out.println(inst.instance(i).value(2)); double[] current_attr = new double[inst.numAttributes()]; double[] other_attr = new double[inst.numAttributes()]; //get attributes of the current instance for (int attr = 0; attr < inst.numAttributes(); attr++) { current_attr[attr] = inst.instance(i).value(attr); } // int counter double[] distances = new double[sk.getNumClusters()]; int[] counters = new int[sk.getNumClusters()]; //System.out.println("distances: "+distances.length); double avgInClusterDist = 0, dist = 0; int countsamecluster = 0; distances[currentcluster] = Double.MAX_VALUE; for (int j = 0; j < inst.numInstances(); j++) { for (int attr = 0; attr < inst.numAttributes(); attr++) { other_attr[attr] = inst.instance(j).value(attr); } //get cluster number of j th element int clusternumber = sk.clusterInstance(inst.instance(j)); //check if j and i in the same cluster if (clusternumber == currentcluster) { if (inst.instance(i) != inst.instance(j)) { //calculate average dist to other elements in the cluster //inst. dist = ed.compute(current_attr, other_attr); avgInClusterDist = avgInClusterDist + dist; countsamecluster++; } } else { dist = ed.compute(current_attr, other_attr); distances[clusternumber] = distances[clusternumber] + dist; counters[clusternumber]++; } } //calculate value ai if (countsamecluster > 0) { avgInClusterDist = avgInClusterDist / countsamecluster; //this is value ai } //find average distances to other clusters for (int k = 0; k < distances.length; k++) { if (k != currentcluster) { distances[k] = distances[k] / counters[k]; } } //Find the min value of average distance to other clusters double min = distances[0]; for (int k = 1; k < distances.length; k++) { if (min > distances[k]) { min = distances[k]; } } //si for current element: double si; // if we only have one element in our cluster it makes sense to set // si = 0 if (countsamecluster == 1) { si = 0.0d; } else { si = (min - avgInClusterDist) / Math.max(min, avgInClusterDist); } avgSilhouetteOverAllPoints = avgSilhouetteOverAllPoints + si; } //System.out.println(inst.numInstances()); return avgSilhouetteOverAllPoints / inst.numInstances(); }
From source file:MathFunc.java
/** * Returns the arc cosine of an angle, in the range of 0.0 through <code>Math.PI</code>. * Special case:/*from ww w .j ava 2 s . c om*/ * <ul> * <li>If the argument is <code>NaN</code> or its absolute value is greater than 1, * then the result is <code>NaN</code>. * </ul> * * @param a - the value whose arc cosine is to be returned. * @return the arc cosine of the argument. */ public static double acos(double a) { // Special case. if (Double.isNaN(a) || Math.abs(a) > 1.0) { return Double.NaN; } // Calculate the arc cosine. double aSquared = a * a; double arcCosine = atan2(Math.sqrt(1 - aSquared), a); return arcCosine; }
From source file:com.clustercontrol.performance.operator.Undefined.java
@Override public double calc(DataTable currentTable, DataTable previousTable, String deviceName) throws CollectedDataNotFoundException, InvalidValueException { m_log.warn("undefined"); return Double.NaN; }
From source file:cpcc.core.utils.GeoJsonUtils.java
/** * @param obj the GeoJSON object./* w w w . j a v a 2 s .c o m*/ * @return the bounding box of the object. */ public static double[] findBoundingBox(GeoJsonObject obj) { if (obj instanceof Point) { LngLatAlt c = ((Point) obj).getCoordinates(); return new double[] { c.getLongitude(), c.getLatitude(), c.getLongitude(), c.getLatitude() }; } if (obj instanceof Polygon) { List<List<LngLatAlt>> geometryList = ((Polygon) obj).getCoordinates(); double[] boundingBox = new double[] { Double.NaN, Double.NaN, Double.NaN, Double.NaN }; for (List<LngLatAlt> positionList : geometryList) { for (LngLatAlt position : positionList) { mergeBoundingBox(boundingBox, position); } } return boundingBox; } return ArrayUtils.EMPTY_DOUBLE_ARRAY; }
From source file:net.sourceforge.jabm.util.TimeSeriesWindow.java
public TimeSeriesWindow(int windowSize) { this.windowSize = windowSize; values = new double[windowSize]; for (int i = 0; i < windowSize; i++) { values[i] = Double.NaN; }//from w w w . j a v a 2 s .c om }
From source file:com.cloudera.oryx.common.math.AbstractRealVectorPreservingVisitor.java
@Override public double end() { // do nothing return Double.NaN; }
From source file:com.lth.thesis.blepublictransport.Utils.KalmanFilter.java
/** * Create 1-dimensional kalman filter/*from w w w . j a va2 s . co m*/ * * @param R Process noise * @param Q Measurement noise * @param A State vector * @param B Control vector * @param C Measurement vector */ public KalmanFilter(double R, double Q, double A, double B, double C) { this.R = R; this.Q = Q; this.A = A; this.B = B; this.C = C; cov = Double.NaN; x = Double.NaN; }
From source file:com.cloudera.oryx.common.math.DoubleWeightedMean.java
public DoubleWeightedMean() { this(0, 0.0, Double.NaN); }
From source file:com.facebook.presto.operator.aggregation.AggregationTestUtils.java
public static void assertAggregation(InternalAggregationFunction function, Object expectedValue, Page page) { BiFunction<Object, Object, Boolean> equalAssertion; if (expectedValue instanceof Double && !expectedValue.equals(Double.NaN)) { equalAssertion = (actual, expected) -> Precision.equals((double) actual, (double) expected, 1e-10); } else if (expectedValue instanceof Float && !expectedValue.equals(Float.NaN)) { equalAssertion = (actual, expected) -> Precision.equals((float) actual, (float) expected, 1e-10f); } else {// ww w . j av a 2 s.com equalAssertion = Objects::equals; } assertAggregation(function, equalAssertion, null, page, expectedValue); }