List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotBoth(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape, double minX, double maxX) throws ConvertException { double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); double[][] functionErrors = null; String legend = shortLegend.get(id); Color color = colors.get(id); Shape shape = shapes.get(id); if (showConfidenceInterval) { functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); }//from w ww. j ava 2 s . c o m if (addInfoInLegend) { legend = longLegend.get(id); } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (modelPoints != null) { int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } if (functionErrors != null) { YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection(); DeviationRenderer functionRenderer = new DeviationRenderer(true, false); YIntervalSeries series = new YIntervalSeries(legend); for (int j = 0; j < modelPoints[0].length; j++) { double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j]; series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error, modelPoints[1][j] + error); } functionDataset.addSeries(series); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesFillPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (dataPoints != null) { functionRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } else { DefaultXYDataset functionDataset = new DefaultXYDataset(); XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false); functionDataset.addSeries(legend, modelPoints); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (dataPoints != null) { functionRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } } if (dataPoints != null) { DefaultXYDataset dataSet = new DefaultXYDataset(); XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true); dataSet.addSeries(legend, dataPoints); dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); dataRenderer.setSeriesPaint(0, color); dataRenderer.setSeriesShape(0, shape); int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } plot.setDataset(i, dataSet); plot.setRenderer(i, dataRenderer); } }
From source file:com.androzic.vnspeech.MapFragment.java
private void onUpdateNavigationStatus() { if (!application.isNavigating()) return;//w ww . j a va 2s .c o m if (!map.isFollowing()) map.refreshMap(); long now = System.currentTimeMillis(); double distance = application.navigationService.navDistance; double bearing = application.navigationService.navBearing; long turn = application.navigationService.navTurn; double vmg = application.navigationService.navVMG; int ete = application.navigationService.navETE; String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat); String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never) : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); String extra = StringFormatter.speedH(vmg) + " | " + eteString; String trnsym = ""; if (turn > 0) { trnsym = "R"; } else if (turn < 0) { trnsym = "L"; turn = -turn; } bearing = application.fixDeclination(bearing); distanceValue.setText(dist[0]); distanceUnit.setText(dist[1]); bearingValue.setText(StringFormatter.angleC(bearing)); turnValue.setText(StringFormatter.angleC(turn) + trnsym); waypointExtra.setText(extra); if (application.navigationService.isNavigatingViaRoute()) { View rootView = getView(); boolean hasNext = application.navigationService.hasNextRouteWaypoint(); if (distance < application.navigationService.navProximity * 3 && !animationSet) { AnimationSet animation = new AnimationSet(true); animation.addAnimation(new AlphaAnimation(1.0f, 0.3f)); animation.addAnimation(new AlphaAnimation(0.3f, 1.0f)); animation.setDuration(500); animation.setRepeatCount(10); rootView.findViewById(R.id.waypointinfo).startAnimation(animation); if (!hasNext) { rootView.findViewById(R.id.routeinfo).startAnimation(animation); } animationSet = true; } else if (animationSet) { rootView.findViewById(R.id.waypointinfo).setAnimation(null); if (!hasNext) { rootView.findViewById(R.id.routeinfo).setAnimation(null); } animationSet = false; } if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) { xtkValue.setText("--"); xtkUnit.setText("--"); } else { String xtksym = application.navigationService.navXTK == 0 ? "" : application.navigationService.navXTK > 0 ? "R" : "L"; String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK)); xtkValue.setText(xtks[0] + xtksym); xtkUnit.setText(xtks[1]); } double navDistance = application.navigationService.navRouteDistanceLeft(); int eta = application.navigationService.navRouteETE(navDistance); if (eta < Integer.MAX_VALUE) eta += application.navigationService.navETE; String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never) : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString; routeExtra.setText(extra); } }
From source file:geogebra.kernel.AlgoFunctionAreaSums.java
protected final void compute() { GeoElement geo; // temporary variable //Application.debug(type); switch (type) { case TYPE_LOWERSUM: case TYPE_UPPERSUM: if (!(f.isDefined() && ageo.isDefined() && bgeo.isDefined() && ngeo.isDefined())) sum.setUndefined();/*from w w w.ja va 2 s. c o m*/ RealRootFunction fun = f.getRealRootFunctionY(); double ad = a.getDouble(); double bd = b.getDouble(); double ints = n.getDouble(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; // calc minimum in every interval if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } RealRootFunction fmin = fun; if (type == TYPE_UPPERSUM) fmin = new NegativeRealRootFunction(fun); // use -f to find maximum double cumSum = 0; double left, right, min; // calulate the min and max x-coords of what actually needs to be drawn // do subsampling only in this region EuclidianView ev = app.getEuclidianView(); double visibleMin = Math.max(Math.min(ad, bd), ev.getXmin()); double visibleMax = Math.min(Math.max(ad, bd), ev.getXmax()); // subsample every 5 pixels double noOfSamples = Math.abs(ev.toScreenCoordXd(visibleMax) - ev.toScreenCoordX(visibleMin)) / SAMPLE_PIXELS; double subStep = Math.abs(visibleMax - visibleMin) / noOfSamples; boolean doSubSamples = !Kernel.isZero(subStep) && Math.abs(STEP) > subStep; boolean positiveStep = STEP >= 0; for (int i = 0; i < N; i++) { leftBorder[i] = ad + i * STEP; if (positiveStep) { left = leftBorder[i]; right = leftBorder[i] + STEP; } else { left = leftBorder[i] + STEP; right = leftBorder[i]; } min = Double.POSITIVE_INFINITY; // heuristic: take some samples in this interval // and find smallest one // subsampling needed in case there are two eg minimums and we get the wrong one with extrFinder.findMinimum() //Application.debug(left + " "+ visibleMin+" "+right + " "+visibleMax); // subsample visible bit only if (doSubSamples && ((STEP > 0 ? left : right) < visibleMax && (STEP > 0 ? right : left) > visibleMin)) { //Application.debug("subsampling from "+left+" to "+right); double y, minSample = left; for (double x = left; x < right; x += subStep) { y = fmin.evaluate(x); if (y < min) { min = y; minSample = x; } } // if the minimum is on the left border then minSample == left now // check right border too y = fmin.evaluate(right); if (y < min) minSample = right; // investigate only the interval around the minSample // make sure we don't get out of our interval! left = Math.max(left, minSample - subStep); right = Math.min(right, minSample + subStep); } // find minimum (resp. maximum) over interval double x = extrFinder.findMinimum(left, right, fmin, TOLERANCE); double y = fmin.evaluate(x); // one of the evaluated sub-samples could be smaller // e.g. at the border of this interval if (y > min) y = min; // store min/max if (type == TYPE_UPPERSUM) y = -y; yval[i] = y; // add to sum cumSum += y; } // calc area of rectangles sum.setValue(cumSum * STEP); break; case TYPE_TRAPEZOIDALSUM: case TYPE_RECTANGLESUM: case TYPE_LEFTSUM: if (!(f.isDefined() && ageo.isDefined() && bgeo.isDefined() && ngeo.isDefined())) sum.setUndefined(); /* Rectanglesum needs extra treatment */ if ((type == TYPE_RECTANGLESUM) && (!dgeo.isDefined())) { //extra parameter sum.setUndefined(); } //if d parameter for rectanglesum fun = f.getRealRootFunctionY(); ad = a.getDouble(); bd = b.getDouble(); ints = n.getDouble(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; // calc minimum in every interval if (yval == null || yval.length < N + 1) {// N+1 for trapezoids yval = new double[N + 1]; // N+1 for trapezoids leftBorder = new double[N + 1]; // N+1 for trapezoids } cumSum = 0; for (int i = 0; i < N + 1; i++) { // N+1 for trapezoids leftBorder[i] = ad + i * STEP; /* Extra treatment for RectangleSum */ if (type == TYPE_RECTANGLESUM) { double dd = d.getDouble(); if ((0.0 <= dd) && (dd <= 1.0)) { yval[i] = fun.evaluate(leftBorder[i] + dd * STEP); //divider into step-interval } else { sum.setUndefined(); return; } // if divider ok } else { yval[i] = fun.evaluate(leftBorder[i]); } //if cumSum += yval[i]; } // calc area of rectangles or trapezoids if ((type == TYPE_RECTANGLESUM) || (type == TYPE_LEFTSUM)) { cumSum -= yval[N]; //Last right value not needed } else { cumSum -= (yval[0] + yval[N]) / 2; } //if rectangles or trapezoids //for (int i=0; i < N+1 ; i++) cumSum += yval[i]; sum.setValue(cumSum * STEP); break; case TYPE_BARCHART: if (!(ageo.isDefined() && bgeo.isDefined() && list1.isDefined())) { sum.setUndefined(); return; } N = list1.size(); ad = a.getDouble(); bd = b.getDouble(); ints = list1.size(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } cumSum = 0; for (int i = 0; i < N; i++) { leftBorder[i] = ad + i * STEP; geo = list1.get(i); if (geo.isGeoNumeric()) yval[i] = ((GeoNumeric) geo).getDouble(); else yval[i] = 0; cumSum += yval[i]; } // calc area of rectangles sum.setValue(cumSum * STEP); break; case TYPE_BARCHART_RAWDATA: // BarChart[{1,1,2,3,3,3,4,5,5,5,5,5,5,5,6,8,9,10,11,12},3] if (!list1.isDefined() || !ngeo.isDefined()) { sum.setUndefined(); return; } double mini = Double.POSITIVE_INFINITY; double maxi = Double.NEGATIVE_INFINITY; int minIndex = -1, maxIndex = -1; double step = n.getDouble(); int rawDataSize = list1.size(); if (step < 0 || Kernel.isZero(step) || rawDataSize < 2) { sum.setUndefined(); return; } // find max and min for (int i = 0; i < rawDataSize; i++) { geo = list1.get(i); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } double val = ((GeoNumeric) geo).getDouble(); if (val > maxi) { maxi = val; maxIndex = i; } if (val < mini) { mini = val; minIndex = i; } } if (maxi == mini || maxIndex == -1 || minIndex == -1) { sum.setUndefined(); return; } double totalWidth = maxi - mini; double noOfBars = totalWidth / n.getDouble(); double gap = 0; /* if (kernel.isInteger(noOfBars)) { N = (int)noOfBars + 1; a = (NumberValue)list1.get(minIndex); b = (NumberValue)list1.get(maxIndex); } else */ { N = (int) noOfBars + 2; gap = ((N - 1) * step - totalWidth) / 2.0; a = (NumberValue) (new GeoNumeric(cons, mini - gap)); b = (NumberValue) (new GeoNumeric(cons, maxi + gap)); //Application.debug("gap = "+gap); } //Application.debug("N = "+N+" maxi = "+maxi+" mini = "+mini); if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } // fill in class boundaries //double width = (maxi-mini)/(double)(N-2); for (int i = 0; i < N; i++) { leftBorder[i] = mini - gap + step * i; } // zero frequencies for (int i = 0; i < N; i++) yval[i] = 0; // work out frequencies in each class double datum; for (int i = 0; i < list1.size(); i++) { geo = list1.get(i); if (geo.isGeoNumeric()) datum = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } // if datum is outside the range, set undefined //if (datum < leftBorder[0] || datum > leftBorder[N-1] ) { sum.setUndefined(); return; } // fudge to make the last boundary eg 10 <= x <= 20 // all others are 10 <= x < 20 double oldMaxBorder = leftBorder[N - 1]; leftBorder[N - 1] += Math.abs(leftBorder[N - 1] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { //System.out.println("checking "+leftBorder[j]); if (datum < leftBorder[j]) { //System.out.println(datum+" "+j); yval[j - 1]++; break; } } leftBorder[N - 1] = oldMaxBorder; // area of rectangles sum.setValue(list1.size() * step); } // find maximum frequency // this is used by the stat dialogs freqMax = 0.0; for (int k = 0; k < yval.length; ++k) { freqMax = Math.max(yval[k], freqMax); } break; case TYPE_BARCHART_FREQUENCY_TABLE: case TYPE_BARCHART_BINOMIAL: case TYPE_BARCHART_POISSON: case TYPE_BARCHART_HYPERGEOMETRIC: case TYPE_BARCHART_PASCAL: case TYPE_BARCHART_ZIPF: if (type != TYPE_BARCHART_FREQUENCY_TABLE) { if (!prepareDistributionLists()) { sum.setUndefined(); return; } } // BarChart[{11,12,13,14,15},{1,5,0,13,4}] if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size() + 1; //if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; // } if (N == 2) { // special case, 1 bar yval = new double[2]; leftBorder = new double[2]; yval[0] = ((GeoNumeric) (list2.get(0))).getDouble(); leftBorder[0] = ((GeoNumeric) (list1.get(0))).getDouble() - 0.5; leftBorder[1] = leftBorder[0] + 1; ageo = new GeoNumeric(cons, leftBorder[0]); bgeo = new GeoNumeric(cons, leftBorder[1]); a = (NumberValue) ageo; b = (NumberValue) bgeo; sum.setValue(yval[0]); return; } if (list2.size() + 1 != N || N < 3) { sum.setUndefined(); return; } double start = ((GeoNumeric) (list1.get(0))).getDouble(); double end = ((GeoNumeric) (list1.get(N - 2))).getDouble(); step = ((GeoNumeric) (list1.get(1))).getDouble() - start; //Application.debug("N = "+N+" start = "+start+" end = "+end+" width = "+width); if (!Kernel.isEqual(end - start, step * (N - 2)) // check first list is (consistent) with being AP || step <= 0) { sum.setUndefined(); return; } ageo = new GeoNumeric(cons, start - step / 2); bgeo = new GeoNumeric(cons, end + step / 2); a = (NumberValue) ageo; b = (NumberValue) bgeo; // fill in class boundaries for (int i = 0; i < N; i++) { leftBorder[i] = start - step / 2 + step * i; } double area = 0; // fill in frequencies for (int i = 0; i < N - 1; i++) { geo = list2.get(i); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } yval[i] = ((GeoNumeric) (list2.get(i))).getDouble(); area += yval[i] * step; } // area of rectangles = total frequency if (type == TYPE_BARCHART_FREQUENCY_TABLE) { sum.setValue(area); } else { if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { sum.setValue(Double.POSITIVE_INFINITY); } else sum.setValue(1.0); sum.updateCascade(); } break; case TYPE_BARCHART_BERNOULLI: double p = p1.getDouble(); if (p < 0 || p > 1) { sum.setUndefined(); return; } N = 3; // special case, 2 bars leftBorder = new double[3]; yval = new double[3]; boolean cumulative = ((GeoBoolean) isCumulative).getBoolean(); yval[0] = 1 - p; yval[1] = cumulative ? 1 : p; leftBorder[0] = -0.5; leftBorder[1] = 0.5; leftBorder[2] = 1.5; ageo = new GeoNumeric(cons, leftBorder[0]); bgeo = new GeoNumeric(cons, leftBorder[1]); a = (NumberValue) ageo; b = (NumberValue) bgeo; if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { sum.setValue(Double.POSITIVE_INFINITY); } else sum.setValue(1.0); sum.updateCascade(); return; case TYPE_BARCHART_FREQUENCY_TABLE_WIDTH: // BarChart[{1,2,3,4,5},{1,5,0,13,4}, 0.5] if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size() + 1; int NN = 2 * N - 1; if (list2.size() + 1 != N || N < 3) { sum.setUndefined(); return; } start = ((GeoNumeric) (list1.get(0))).getDouble(); end = ((GeoNumeric) (list1.get(N - 2))).getDouble(); step = ((GeoNumeric) (list1.get(1))).getDouble() - start; double colWidth = width.getDouble(); //Application.debug("N = "+N+" start = "+start+" end = "+end+" colWidth = "+colWidth); if (!Kernel.isEqual(end - start, step * (N - 2)) // check first list is (consistent) with being AP || step <= 0) { sum.setUndefined(); return; } ageo = new GeoNumeric(cons, start - colWidth / 2); bgeo = new GeoNumeric(cons, end + colWidth / 2); a = (NumberValue) ageo; b = (NumberValue) bgeo; if (yval == null || yval.length < NN - 1) { yval = new double[NN - 1]; leftBorder = new double[NN - 1]; } // fill in class boundaries for (int i = 0; i < NN - 1; i += 2) { leftBorder[i] = start + step * (i / 2.0) - colWidth / 2.0; leftBorder[i + 1] = start + step * (i / 2.0) + colWidth / 2.0; } area = 0; // fill in frequencies for (int i = 0; i < NN - 1; i++) { if (i % 2 == 1) { // dummy columns, zero height yval[i] = 0; } else { geo = list2.get(i / 2); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } yval[i] = ((GeoNumeric) (list2.get(i / 2))).getDouble(); area += yval[i] * colWidth; } } // area of rectangles = total frequency sum.setValue(area); N = NN - 1; break; case TYPE_HISTOGRAM: case TYPE_HISTOGRAM_DENSITY: if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size(); if (N < 2) { sum.setUndefined(); return; } // set the density scale factor // default is 1; densityFactor == -1 means do not convert from frequency to density double densityFactor; if (useDensityGeo == null) { densityFactor = 1; } else if (!((GeoBoolean) useDensityGeo).getBoolean()) { densityFactor = -1; } else { densityFactor = (density != null) ? density.getDouble() : 1; if (densityFactor <= 0 && densityFactor != -1) { sum.setUndefined(); return; } } // list2 contains raw data // eg Histogram[{1,1.5,2,4},{1.0,1.1,1.1,1.2,1.7,1.7,1.8,2.2,2.5,4.0}] // problem: if N-1 = list2.size() then raw data is not assumed // fix for now is to check if other parameters are present, then it must be raw data if (N - 1 != list2.size() || useDensityGeo != null || isCumulative != null) { if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } // fill in class boundaries for (int i = 0; i < N - 1; i++) { geo = list1.get(i); if (i == 0) { if (geo.isNumberValue()) a = (NumberValue) geo; else { sum.setUndefined(); return; } } if (geo.isGeoNumeric()) leftBorder[i] = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } } geo = list1.get(N - 1); if (geo.isNumberValue()) b = (NumberValue) geo; else { sum.setUndefined(); return; } leftBorder[N - 1] = ((GeoNumeric) geo).getDouble(); // zero frequencies for (int i = 0; i < N; i++) yval[i] = 0; // work out frequencies in each class //TODO: finish right histogram option for 2nd case below for (int i = 0; i < list2.size(); i++) { geo = list2.get(i); if (geo.isGeoNumeric()) datum = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } // if datum is outside the range, set undefined if (datum < leftBorder[0] || datum > leftBorder[N - 1]) { sum.setUndefined(); return; } if (!this.histogramRight) { // fudge to make the last boundary eg 10 <= x <= 20 // all others are 10 <= x < 20 double oldMaxBorder = leftBorder[N - 1]; leftBorder[N - 1] += Math.abs(leftBorder[N - 1] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { if (Kernel.isGreater(leftBorder[j], datum)) { yval[j - 1]++; break; } } leftBorder[N - 1] = oldMaxBorder; } else { // fudge to make the first boundary eg 10 <= x <= 20 // all others are 10 < x <= 20 (HistogramRight) double oldMinBorder = leftBorder[0]; leftBorder[0] += Math.abs(leftBorder[0] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { if (Kernel.isGreaterEqual(leftBorder[j], datum)) { yval[j - 1]++; break; } } leftBorder[0] = oldMinBorder; } } // turn frequencies into frequency densities // if densityFactor = -1 then do not convert frequency to density if (densityFactor != -1) for (int i = 1; i < N; i++) yval[i - 1] = densityFactor * yval[i - 1] / (leftBorder[i] - leftBorder[i - 1]); //convert to cumulative frequencies if cumulative option is set if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { for (int i = 1; i < N; i++) yval[i] += yval[i - 1]; } // area of rectangles = total frequency * densityFactor sum.setValue(Math.abs(list2.size() * densityFactor)); // find maximum frequency // this is used by the stat dialogs freqMax = 0.0; for (int k = 0; k < yval.length; ++k) { freqMax = Math.max(yval[k], freqMax); } } else { // list2 contains the heights if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } for (int i = 0; i < N - 1; i++) { geo = list1.get(i); if (i == 0) { if (geo.isNumberValue()) a = (NumberValue) geo; else { sum.setUndefined(); return; } } if (geo.isGeoNumeric()) leftBorder[i] = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } geo = list2.get(i); if (geo.isGeoNumeric()) yval[i] = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } } yval[N - 1] = yval[N - 2]; geo = list1.get(N - 1); if (geo.isNumberValue()) b = (NumberValue) geo; else { sum.setUndefined(); return; } leftBorder[N - 1] = ((GeoNumeric) geo).getDouble(); cumSum = 0; for (int i = 1; i < N; i++) cumSum += (leftBorder[i] - leftBorder[i - 1]) * yval[i - 1]; // area of rectangles sum.setValue(cumSum); } // find maximum frequency // this is used by the stat dialogs freqMax = 0.0; for (int k = 0; k < yval.length; ++k) { freqMax = Math.max(yval[k], freqMax); } break; } }
From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java
public static OptMapResultNode newBlankMapNode(DataNode f) { return new OptMapResultNode(f, null, 0, -1, -1, -1, -1, null, Double.NEGATIVE_INFINITY, -1); }
From source file:com.tinspx.util.json.JSONParserTest.java
@Test public void testAllNonStandardFeatures() throws IOException { assertEquals(ALL_COMMENTS, COMMENTS.or(YAML)); Map<String, Object> map = Maps.newHashMap(); map.put("unq'8\u0000", "test"); List<Object> value = Arrays.<Object>asList(true, false, null, 0xFFF, 0xFFFFFFFFFL, bi("FFFFFFFFFFFFFFFFFFFFFFF", 16), d("0xabcd.45p8d"), d("89f"), "\u0000\ny", "\t7", Double.NaN, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 8, 0, 0, d("0x00p5"), bd(".89"), d("+.9D"), map); fail("[,True, False, Null,, 0xFFF, 0xFFFFFFFFF, 0xFFFFFFFFFFFFFFFFFFFFFFF, /* 100[ */ 0xabcd.45p8d, 89f, # y5{\n \"\u0000\n\\y\", '\t\\7', NaN, nan, Inf, -inFiNitY , 0008, +0, //90{'90\r -0, 0x00p5, .89, +.9D, { , unq'8\u0000\n : 'test' ,,} ]"); pass(value,//from ww w . j a v a 2s .c o m "[,True, False, Null,, 0xFFF, 0xFFFFFFFFF, 0xFFFFFFFFFFFFFFFFFFFFFFF, /* 100[ */ 0xabcd.45p8d, 89f, # y5{\n \"\u0000\n\\y\", '\t\\7', NaN, nan, Inf, -inFiNitY , 0008, +0, //90{'90\r -0, 0x00p5, .89, +.9D, { , unq'8\u0000\n : 'test' ,,} ]", LENIENT); }
From source file:com.clust4j.data.BufferedMatrixReader.java
/** * Static tokenizing method to move a row of strings into a double array * @param row/*ww w. ja v a 2 s . c o m*/ * @return * @throws NumberFormatException */ static double[] tokenize(String[] row) throws NumberFormatException { final double[] out = new double[row.length]; int idx = 0; for (String str : row) { double val = 0; try { val = Double.parseDouble(str); } catch (NumberFormatException e) { String lower = str.toLowerCase(); // Check if it's a nan... if (isNaN(lower)) val = Double.NaN; else if (isPosInf(lower)) val = Double.POSITIVE_INFINITY; else if (isNegInf(lower)) val = Double.NEGATIVE_INFINITY; else throw e; } out[idx++] = val; } return out; }
From source file:com.clust4j.algo.NearestNeighborHeapSearch.java
private double logAddExp(double x1, double x2) { final double a = FastMath.max(x1, x2); if (Double.NEGATIVE_INFINITY == a) return a; return a + FastMath.log(FastMath.exp(x1 - a) + FastMath.exp(x2 - a)); }
From source file:it.units.malelab.ege.util.DUMapper.java
private static double normalizedVar(double[] values) { double minValue = Double.POSITIVE_INFINITY; double maxValue = Double.NEGATIVE_INFINITY; //rescale/*from w ww . j a v a 2 s. co m*/ for (double value : values) { minValue = Math.min(value, minValue); maxValue = Math.max(value, maxValue); } if (minValue == maxValue) { return 0; } for (int i = 0; i < values.length; i++) { values[i] = (values[i] - minValue) / (maxValue - minValue); } return Utils.normalizedVariance(values); }
From source file:geogebra.common.kernel.algos.AlgoFunctionAreaSums.java
private void compute(boolean onlyZoom) { GeoElement geo, geo2; // temporary variables boolean isDefined = true; // problem with Sequence[LowerSum[x, i, i + 1, 1], i, 1, 5] on file // load/*www . jav a 2 s . com*/ if (sum == null) { sum = new GeoNumeric(cons); } switch (type) { case LOWERSUM: case UPPERSUM: if (f == null || !(f.isDefined() && ageo.isDefined() && bgeo.isDefined() && ngeo.isDefined())) { sum.setUndefined(); return; } RealRootFunction fun = f.getRealRootFunctionY(); double ad = a.getDouble(); double bd = b.getDouble(); if (!onlyZoom) { isDefined = functionDefined(ad, bd); } else { isDefined = sum.isDefined(); } double ints = n.getDouble(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; // calc minimum in every interval if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } RealRootFunction fmin = fun; if (type == SumType.UPPERSUM) fmin = new NegativeRealRootFunction(fun); // use -f to find // maximum double totalArea = 0; double left, right, min; // calulate the min and max x-coords of what actually needs to be // drawn // do subsampling only in this region double visibleMin = Math.max(Math.min(ad, bd), kernel.getViewsXMin(sum)); double visibleMax = Math.min(Math.max(ad, bd), kernel.getViewsXMax(sum)); // subsample every 5 pixels double noOfSamples = kernel.getApplication().countPixels(visibleMin, visibleMax) / SAMPLE_PIXELS; double subStep = Math.abs(visibleMax - visibleMin) / noOfSamples; boolean doSubSamples = !Kernel.isZero(subStep) && Math.abs(STEP) > subStep; boolean positiveStep = STEP >= 0; for (int i = 0; i < N; i++) { leftBorder[i] = ad + i * STEP; if (positiveStep) { left = leftBorder[i]; right = leftBorder[i] + STEP; } else { left = leftBorder[i] + STEP; right = leftBorder[i]; } min = Double.POSITIVE_INFINITY; // heuristic: take some samples in this interval // and find smallest one // subsampling needed in case there are two eg minimums and we // get the wrong one with extrFinder.findMinimum() // Application.debug(left + " "+ visibleMin+" "+right + // " "+visibleMax); // subsample visible bit only if (doSubSamples && ((STEP > 0 ? left : right) < visibleMax && (STEP > 0 ? right : left) > visibleMin)) { // Application.debug("subsampling from "+left+" to "+right); double y, minSample = left; for (double x = left; x < right; x += subStep) { y = fmin.evaluate(x); if (y < min) { min = y; minSample = x; } } // if the minimum is on the left border then minSample == // left now // check right border too y = fmin.evaluate(right); if (y < min) minSample = right; // investigate only the interval around the minSample // make sure we don't get out of our interval! left = Math.max(left, minSample - subStep); right = Math.min(right, minSample + subStep); } // find minimum (resp. maximum) over interval double x = extrFinder.findMinimum(left, right, fmin, TOLERANCE); double y = fmin.evaluate(x); // one of the evaluated sub-samples could be smaller // e.g. at the border of this interval if (y > min) y = min; // store min/max if (type == SumType.UPPERSUM) y = -y; yval[i] = y; // add to sum totalArea += y; } // calc area of rectangles sum.setValue(totalArea * STEP); if (!isDefined) sum.setUndefined(); break; case TRAPEZOIDALSUM: case RECTANGLESUM: case LEFTSUM: if (f == null || !(f.isDefined() && ageo.isDefined() && bgeo.isDefined() && ngeo.isDefined())) { sum.setUndefined(); return; } /* Rectanglesum needs extra treatment */ if ((type == SumType.RECTANGLESUM) && (!dgeo.isDefined())) { // extra // parameter sum.setUndefined(); } // if d parameter for rectanglesum fun = f.getRealRootFunctionY(); ad = a.getDouble(); bd = b.getDouble(); if (!onlyZoom) { isDefined = functionDefined(ad, bd); } else { isDefined = sum.isDefined(); } ints = n.getDouble(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; // calc minimum in every interval if (yval == null || yval.length < N + 1) {// N+1 for trapezoids yval = new double[N + 1]; // N+1 for trapezoids leftBorder = new double[N + 1]; // N+1 for trapezoids } totalArea = 0; int upperBound = type == SumType.TRAPEZOIDALSUM ? N + 1 : N; for (int i = 0; i < upperBound; i++) { // N+1 for trapezoids leftBorder[i] = ad + i * STEP; /* Extra treatment for RectangleSum */ if (type == SumType.RECTANGLESUM) { double dd = d.getDouble(); if ((0.0 <= dd) && (dd <= 1.0)) { yval[i] = fun.evaluate(leftBorder[i] + dd * STEP); // divider // into // step-interval } else { sum.setUndefined(); return; } // if divider ok } else { yval[i] = fun.evaluate(leftBorder[i]); } // if totalArea += yval[i]; } // calc area of rectangles or trapezoids if (type == SumType.TRAPEZOIDALSUM) { totalArea -= (yval[0] + yval[N]) / 2; } // if rectangles or trapezoids // for (int i=0; i < N+1 ; i++) cumSum += yval[i]; sum.setValue(totalArea * STEP); break; case BARCHART: if (!(ageo.isDefined() && bgeo.isDefined() && list1.isDefined())) { sum.setUndefined(); return; } N = list1.size(); ad = a.getDouble(); bd = b.getDouble(); ints = list1.size(); if (ints < 1) { sum.setUndefined(); return; } else if (ints > MAX_RECTANGLES) { N = MAX_RECTANGLES; } else { N = (int) Math.round(ints); } STEP = (bd - ad) / N; if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } totalArea = 0; for (int i = 0; i < N; i++) { leftBorder[i] = ad + i * STEP; geo = list1.get(i); if (geo.isGeoNumeric()) yval[i] = ((GeoNumeric) geo).getDouble(); else yval[i] = 0; totalArea += yval[i]; } // calc area of rectangles sum.setValue(totalArea * STEP); if (!isDefined) { sum.setUndefined(); } break; case BARCHART_RAWDATA: // BarChart[{1,1,2,3,3,3,4,5,5,5,5,5,5,5,6,8,9,10,11,12},3] if (!list1.isDefined() || !ngeo.isDefined()) { sum.setUndefined(); return; } double mini = Double.POSITIVE_INFINITY; double maxi = Double.NEGATIVE_INFINITY; int minIndex = -1, maxIndex = -1; double step = n.getDouble(); int rawDataSize = list1.size(); if (step < 0 || Kernel.isZero(step) || rawDataSize < 2) { sum.setUndefined(); return; } // find max and min for (int i = 0; i < rawDataSize; i++) { geo = list1.get(i); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } double val = ((GeoNumeric) geo).getDouble(); if (val > maxi) { maxi = val; maxIndex = i; } if (val < mini) { mini = val; minIndex = i; } } if (maxi == mini || maxIndex == -1 || minIndex == -1) { sum.setUndefined(); return; } double totalWidth = maxi - mini; double noOfBars = totalWidth / n.getDouble(); double gap = 0; /* * if (kernel.isInteger(noOfBars)) { N = (int)noOfBars + 1; a = * (NumberValue)list1.get(minIndex); b = * (NumberValue)list1.get(maxIndex); } else */ { N = (int) noOfBars + 2; gap = ((N - 1) * step - totalWidth) / 2.0; a = (new GeoNumeric(cons, mini - gap)); b = (new GeoNumeric(cons, maxi + gap)); // Application.debug("gap = "+gap); } // Application.debug("N = "+N+" maxi = "+maxi+" mini = "+mini); if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } // fill in class boundaries // double width = (maxi-mini)/(double)(N-2); for (int i = 0; i < N; i++) { leftBorder[i] = mini - gap + step * i; } // zero frequencies for (int i = 0; i < N; i++) yval[i] = 0; // work out frequencies in each class double datum, valueFrequency = 1; for (int i = 0; i < list1.size(); i++) { geo = list1.get(i); if (geo.isGeoNumeric()) datum = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } // if datum is outside the range, set undefined // if (datum < leftBorder[0] || datum > leftBorder[N-1] ) { // sum.setUndefined(); return; } // fudge to make the last boundary eg 10 <= x <= 20 // all others are 10 <= x < 20 double oldMaxBorder = leftBorder[N - 1]; leftBorder[N - 1] += Math.abs(leftBorder[N - 1] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { // System.out.println("checking "+leftBorder[j]); if (datum < leftBorder[j]) { // System.out.println(datum+" "+j); yval[j - 1]++; break; } } leftBorder[N - 1] = oldMaxBorder; // area of rectangles sum.setValue(list1.size() * step); } break; case BARCHART_FREQUENCY_TABLE: case BARCHART_BINOMIAL: case BARCHART_POISSON: case BARCHART_HYPERGEOMETRIC: case BARCHART_PASCAL: case BARCHART_ZIPF: if (type != SumType.BARCHART_FREQUENCY_TABLE) { if (!prepareDistributionLists()) { sum.setUndefined(); return; } } // BarChart[{11,12,13,14,15},{1,5,0,13,4}] if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size() + 1; // if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; // } if (N == 2) { // special case, 1 bar yval = new double[2]; leftBorder = new double[2]; yval[0] = ((GeoNumeric) (list2.get(0))).getDouble(); leftBorder[0] = ((GeoNumeric) (list1.get(0))).getDouble() - 0.5; leftBorder[1] = leftBorder[0] + 1; ageo = new GeoNumeric(cons, leftBorder[0]); bgeo = new GeoNumeric(cons, leftBorder[1]); a = (NumberValue) ageo; b = (NumberValue) bgeo; sum.setValue(yval[0]); return; } if (list2.size() + 1 != N || N < 3) { sum.setUndefined(); return; } double start = ((GeoNumeric) (list1.get(0))).getDouble(); double end = ((GeoNumeric) (list1.get(N - 2))).getDouble(); step = ((GeoNumeric) (list1.get(1))).getDouble() - start; // Application.debug("N = "+N+" start = "+start+" end = "+end+" width = "+width); if (!Kernel.isEqual(end - start, step * (N - 2)) // check first list // is // (consistent) // with being AP || step <= 0) { sum.setUndefined(); return; } ageo = new GeoNumeric(cons, start - step / 2); bgeo = new GeoNumeric(cons, end + step / 2); a = (NumberValue) ageo; b = (NumberValue) bgeo; // fill in class boundaries for (int i = 0; i < N; i++) { leftBorder[i] = start - step / 2 + step * i; } double area = 0; // fill in frequencies for (int i = 0; i < N - 1; i++) { geo = list2.get(i); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } yval[i] = ((GeoNumeric) (list2.get(i))).getDouble(); area += yval[i] * step; } // area of rectangles = total frequency if (type == SumType.BARCHART_FREQUENCY_TABLE) { sum.setValue(area); } else { if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { sum.setValue(Double.POSITIVE_INFINITY); } else sum.setValue(1.0); sum.updateCascade(); } break; case BARCHART_BERNOULLI: double p = p1.getDouble(); if (p < 0 || p > 1) { sum.setUndefined(); return; } N = 3; // special case, 2 bars leftBorder = new double[3]; yval = new double[3]; boolean cumulative = ((GeoBoolean) isCumulative).getBoolean(); yval[0] = 1 - p; yval[1] = cumulative ? 1 : p; leftBorder[0] = -0.5; leftBorder[1] = 0.5; leftBorder[2] = 1.5; ageo = new GeoNumeric(cons, leftBorder[0]); bgeo = new GeoNumeric(cons, leftBorder[1]); a = (NumberValue) ageo; b = (NumberValue) bgeo; if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { sum.setValue(Double.POSITIVE_INFINITY); } else { sum.setValue(1.0); } sum.updateCascade(); return; case BARCHART_FREQUENCY_TABLE_WIDTH: // BarChart[{1,2,3,4,5},{1,5,0,13,4}, 0.5] if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size() + 1; int NN = 2 * N - 1; if (list2.size() + 1 != N || N < 2) { sum.setUndefined(); return; } start = ((GeoNumeric) (list1.get(0))).getDouble(); end = ((GeoNumeric) (list1.get(N - 2))).getDouble(); if (N == 2) { // special case, one bar step = 1; } else { step = ((GeoNumeric) (list1.get(1))).getDouble() - start; } double colWidth = width.getDouble(); // Application.debug("N = "+N+" start = "+start+" end = "+end+" colWidth = "+colWidth); if (!Kernel.isEqual(end - start, step * (N - 2)) // check first list // is // (consistent) // with being AP || step <= 0) { sum.setUndefined(); return; } ageo = new GeoNumeric(cons, start - colWidth / 2); bgeo = new GeoNumeric(cons, end + colWidth / 2); a = (NumberValue) ageo; b = (NumberValue) bgeo; if (yval == null || yval.length < NN - 1) { yval = new double[NN - 1]; leftBorder = new double[NN - 1]; } // fill in class boundaries for (int i = 0; i < NN - 1; i += 2) { leftBorder[i] = start + step * (i / 2.0) - colWidth / 2.0; leftBorder[i + 1] = start + step * (i / 2.0) + colWidth / 2.0; } area = 0; // fill in frequencies for (int i = 0; i < NN - 1; i++) { if (i % 2 == 1) { // dummy columns, zero height yval[i] = 0; } else { geo = list2.get(i / 2); if (!geo.isGeoNumeric()) { sum.setUndefined(); return; } yval[i] = ((GeoNumeric) (list2.get(i / 2))).getDouble(); area += yval[i] * colWidth; } } // area of rectangles = total frequency sum.setValue(area); N = NN - 1; break; case HISTOGRAM: case HISTOGRAM_DENSITY: if (!list1.isDefined() || !list2.isDefined()) { sum.setUndefined(); return; } N = list1.size(); if (N < 2) { sum.setUndefined(); return; } boolean useFrequency = list3 != null; if (useFrequency && !list3.isDefined()) { sum.setUndefined(); return; } // set the density scale factor // default is 1; densityFactor == -1 means do not convert from // frequency to density double densityFactor; if (useDensityGeo == null) { densityFactor = 1; } else if (!((GeoBoolean) useDensityGeo).getBoolean()) { densityFactor = -1; } else { densityFactor = (density != null) ? density.getDouble() : 1; if (densityFactor <= 0 && densityFactor != -1) { sum.setUndefined(); return; } } // list2 contains raw data // eg // Histogram[{1,1.5,2,4},{1.0,1.1,1.1,1.2,1.7,1.7,1.8,2.2,2.5,4.0}] // problem: if N-1 = list2.size() then raw data is not assumed // fix for now is to check if other parameters are present, then it // must be raw data if (N - 1 != list2.size() || useDensityGeo != null || isCumulative != null) { if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } // fill in class boundaries for (int i = 0; i < N - 1; i++) { geo = list1.get(i); if (i == 0) { if (geo instanceof NumberValue) a = (NumberValue) geo; else { sum.setUndefined(); return; } } if (geo.isGeoNumeric()) leftBorder[i] = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } } geo = list1.get(N - 1); if (geo instanceof NumberValue) { b = (NumberValue) geo; } else { sum.setUndefined(); return; } leftBorder[N - 1] = ((GeoNumeric) geo).getDouble(); // zero frequencies for (int i = 0; i < N; i++) yval[i] = 0; // work out frequencies in each class // TODO: finish right histogram option for 2nd case below valueFrequency = 1; for (int i = 0; i < list2.size(); i++) { geo = list2.get(i); if (geo.isGeoNumeric()) datum = ((GeoNumeric) geo).getDouble(); else { sum.setUndefined(); return; } if (useFrequency) { geo2 = list3.get(i); if (geo2.isGeoNumeric()) valueFrequency = ((GeoNumeric) geo2).getDouble(); else { sum.setUndefined(); return; } } // if negative frequency, set undefined if (valueFrequency < 0) { sum.setUndefined(); return; } // if datum is outside the range, set undefined if (datum < leftBorder[0] || datum > leftBorder[N - 1]) { sum.setUndefined(); return; } if (!this.histogramRight) { // fudge to make the last boundary eg 10 <= x <= 20 // all others are 10 <= x < 20 double oldMaxBorder = leftBorder[N - 1]; leftBorder[N - 1] += Math.abs(leftBorder[N - 1] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { if (Kernel.isGreater(leftBorder[j], datum)) { yval[j - 1] += valueFrequency; break; } } leftBorder[N - 1] = oldMaxBorder; } else { // fudge to make the first boundary eg 10 <= x <= 20 // all others are 10 < x <= 20 (HistogramRight) double oldMinBorder = leftBorder[0]; leftBorder[0] += Math.abs(leftBorder[0] / 100000000); // check which class this datum is in for (int j = 1; j < N; j++) { if (Kernel.isGreaterEqual(leftBorder[j], datum)) { yval[j - 1] += valueFrequency; break; } } leftBorder[0] = oldMinBorder; } } } else { // list2 contains the heights // make sure heights not rescaled #2579 densityFactor = -1; if (yval == null || yval.length < N) { yval = new double[N]; leftBorder = new double[N]; } for (int i = 0; i < N - 1; i++) { geo = list1.get(i); if (i == 0) { if (geo instanceof NumberValue) a = (NumberValue) geo; else { sum.setUndefined(); return; } } if (geo instanceof NumberValue) leftBorder[i] = ((NumberValue) geo).getDouble(); else { sum.setUndefined(); return; } geo = list2.get(i); if (geo instanceof NumberValue) { yval[i] = ((NumberValue) geo).getDouble(); } else { sum.setUndefined(); return; } } // yval[N - 1] = yval[N - 2]; geo = list1.get(N - 1); if (geo instanceof NumberValue) { b = (NumberValue) geo; } else { sum.setUndefined(); return; } leftBorder[N - 1] = ((GeoNumeric) geo).getDouble(); } // convert to cumulative frequencies if cumulative option is set if (isCumulative != null && ((GeoBoolean) isCumulative).getBoolean()) { for (int i = 1; i < N; i++) { yval[i] += yval[i - 1]; } } // turn frequencies into frequency densities // if densityFactor = -1 then do not convert frequency to // density if (densityFactor != -1) { for (int i = 1; i < N; i++) { yval[i - 1] = densityFactor * yval[i - 1] / (leftBorder[i] - leftBorder[i - 1]); } } totalArea = 0; for (int i = 1; i < N; i++) { totalArea += (leftBorder[i] - leftBorder[i - 1]) * yval[i - 1]; } // area of rectangles sum.setValue(totalArea); break; } }
From source file:com.clust4j.algo.NearestNeighborHeapSearch.java
private double logSubExp(double x1, double x2) { if (x1 <= x2) return Double.NEGATIVE_INFINITY; return x1 + FastMath.log(1 - FastMath.exp(x2 - x1)); }