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:Clustering.technique.KMeansPlusPlusClusterer.java
/** * Get the point farthest to its cluster center * * @param clusters the {@link Cluster}s to search * @return point farthest to its cluster center * @throws ConvergenceException if clusters are all empty *//*from ww w.ja v a 2 s. c o m*/ private T getFarthestPoint(final Collection<CentroidCluster<T>> clusters) throws ConvergenceException { double maxDistance = Double.NEGATIVE_INFINITY; Cluster<T> selectedCluster = null; int selectedPoint = -1; for (final CentroidCluster<T> cluster : clusters) { // get the farthest point final Clusterable center = cluster.getCenter(); final List<T> points = cluster.getPoints(); for (int i = 0; i < points.size(); ++i) { final double distance = distance(points.get(i), center); if (distance > maxDistance) { maxDistance = distance; selectedCluster = cluster; selectedPoint = i; } } } // did we find at least one non-empty cluster ? if (selectedCluster == null) { throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS); } return selectedCluster.getPoints().remove(selectedPoint); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.algorithm.MOEAD.java
/** * Evaluates the fitness of the specified solution using the Chebyshev * weights.// www . j a v a 2 s.c o m * * @param solution the solution * @param weights the weights * @return the fitness of the specified solution using the Chebyshev * weights */ private double fitness(Solution solution, double[] weights) { double max = Double.NEGATIVE_INFINITY; for (int i = 0; i < solution.getNumberOfObjectives(); i++) { max = Math.max(max, Math.max(weights[i], 0.0001) * Math.abs(solution.getObjective(i) - idealPoint[i])); } if (solution.violatesConstraints()) { max += 10000.0; } return max; }
From source file:ffx.xray.CrystalStats.java
/** * print R factors and associated statistics in a binned fashion *///w w w .j a va2 s.c o m public void printRStats() { double res[][] = new double[n][2]; double nhkl[] = new double[n + 1]; double rb[][] = new double[n + 1][2]; double sumfo[][] = new double[n + 1][2]; double s[][] = new double[n + 1][4]; double numer = 0.0; double denom = 0.0; double sumall = 0.0; double sumfoall = 0.0; ReflectionSpline sigmaaspline = new ReflectionSpline(reflectionlist, refinementdata.sigmaa.length); for (int i = 0; i < n; i++) { res[i][0] = Double.NEGATIVE_INFINITY; res[i][1] = Double.POSITIVE_INFINITY; } for (HKL ih : reflectionlist.hkllist) { int i = ih.index(); int b = ih.bin(); // ignored cases if (Double.isNaN(fc[i][0]) || Double.isNaN(fo[i][0]) || fo[i][1] <= 0.0) { continue; } // spline setup double ss = Crystal.invressq(crystal, ih); double fh = spline.f(ss, refinementdata.spline); double sa = sigmaaspline.f(ss, refinementdata.sigmaa); double wa = sigmaaspline.f(ss, refinementdata.sigmaw); double eoscale = sigmaaspline.f(ss, refinementdata.foesq); // determine res limits of each bin double rs = Crystal.res(crystal, ih); if (rs > res[b][0]) { res[b][0] = rs; } if (rs < res[b][1]) { res[b][1] = rs; } ComplexNumber c = new ComplexNumber(fc[i][0], fc[i][1]); numer = abs(abs(fo[i][0]) - fh * abs(c.abs())); denom = abs(fo[i][0]); if (refinementdata.isFreeR(i)) { rb[b][1] += numer; sumfo[b][1] += denom; rb[n][1] += numer; sumfo[n][1] += denom; sumall += numer; sumfoall += denom; } else { rb[b][0] += numer; sumfo[b][0] += denom; rb[n][0] += numer; sumfo[n][0] += denom; sumall += numer; sumfoall += denom; } nhkl[b]++; nhkl[n]++; s[b][0] += (sa - s[b][0]) / nhkl[b]; s[b][1] += (wa - s[b][1]) / nhkl[b]; s[b][2] += ((wa / Math.sqrt(eoscale)) - s[b][2]) / nhkl[b]; s[b][3] += (fomphi[i][0] - s[b][3]) / nhkl[b]; s[n][0] += (sa - s[n][0]) / nhkl[n]; s[n][1] += (wa - s[n][1]) / nhkl[n]; s[n][2] += ((wa / Math.sqrt(eoscale)) - s[n][2]) / nhkl[n]; s[n][3] += (fomphi[i][0] - s[n][3]) / nhkl[n]; } StringBuilder sb = new StringBuilder(String.format("\n %15s | %7s | %7s | %7s | %7s | %7s | %7s\n", "Res. Range", " R", "Rfree", "s", "w(E)", "w(F)", "FOM")); for (int i = 0; i < n; i++) { sb.append(String.format(" %7.3f %7.3f | ", res[i][0], res[i][1])); sb.append(String.format("%7.2f | %7.2f | %7.4f | %7.4f | %7.2f | %7.4f\n", (rb[i][0] / sumfo[i][0]) * 100.0, (rb[i][1] / sumfo[i][1]) * 100.0, s[i][0], s[i][1], s[i][2], s[i][3])); } sb.append(String.format(" %7.3f %7.3f | ", res[0][0], res[n - 1][1])); sb.append(String.format("%7.2f | %7.2f | %7.4f | %7.4f | %7.2f | %7.4f\n", (rb[n][0] / sumfo[n][0]) * 100.0, (rb[n][1] / sumfo[n][1]) * 100.0, s[n][0], s[n][1], s[n][2], s[n][3])); sb.append(" s and w are analagous to D and sum_wc"); reslow = res[0][0]; reshigh = res[n - 1][1]; highreslow = res[n - 1][0]; highreshigh = res[n - 1][1]; r = (rb[n][0] / sumfo[n][0]) * 100.0; rfree = (rb[n][1] / sumfo[n][1]) * 100.0; rall = (sumall / sumfoall) * 100.0; highr = (rb[n - 1][0] / sumfo[n - 1][0]) * 100.0; highrfree = (rb[n - 1][1] / sumfo[n - 1][1]) * 100.0; if (print) { logger.info(sb.toString()); } }
From source file:nars.concept.util.BeliefClusterer.java
/** * Get the point farthest to its cluster center * * @param clusters the {@link Cluster}s to search * @return point farthest to its cluster center * @throws ConvergenceException if clusters are all empty *///from www. j a v a 2 s .c o m @NotNull private ArrayRealVector getFarthestPoint(@NotNull final Collection<Cluster> clusters) throws ConvergenceException { double maxDistance = Double.NEGATIVE_INFINITY; Cluster selectedCluster = null; int selectedPoint = -1; for (final Cluster cluster : clusters) { // get the farthest point final ArrayRealVector center = cluster.pos; final List<T> points = cluster.getPoints(); for (int i = 0; i < points.size(); ++i) { final double distance = distance(points.get(i), center.getDataRef()); if (distance > maxDistance) { maxDistance = distance; selectedCluster = cluster; selectedPoint = i; } } } // did we find at least one non-empty cluster ? if (selectedCluster == null) { throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS); } return p(selectedCluster.getPoints().remove(selectedPoint)); }
From source file:com.xqdev.jam.MLJAM.java
private static void sendXQueryResponse(HttpServletResponse res, Object o) throws IOException { // Make sure to leave the status code alone. It defaults to 200, but sometimes // callers of this method will have set it to a custom code. res.setContentType("x-marklogic/xquery; charset=UTF-8"); //res.setContentType("text/plain"); Writer writer = res.getWriter(); // care to handle errors later? if (o == null) { writer.write("()"); }/*from w ww . j a va 2 s. co m*/ else if (o instanceof byte[]) { writer.write("binary {'"); writer.write(hexEncode((byte[]) o)); writer.write("'}"); } else if (o instanceof Object[]) { Object[] arr = (Object[]) o; writer.write("("); for (int i = 0; i < arr.length; i++) { sendXQueryResponse(res, arr[i]); if (i + 1 < arr.length) writer.write(", "); } writer.write(")"); } else if (o instanceof String) { writer.write("'"); writer.write(escapeSingleQuotes(o.toString())); writer.write("'"); } else if (o instanceof Integer) { writer.write("xs:int("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Long) { writer.write("xs:integer("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Float) { Float flt = (Float) o; writer.write("xs:float("); if (flt.equals(Float.POSITIVE_INFINITY)) { writer.write("'INF'"); } else if (flt.equals(Float.NEGATIVE_INFINITY)) { writer.write("'-INF'"); } else if (flt.equals(Float.NaN)) { writer.write("fn:number(())"); // poor man's way to write NaN } else { writer.write(o.toString()); } writer.write(")"); } else if (o instanceof Double) { Double dbl = (Double) o; writer.write("xs:double("); if (dbl.equals(Double.POSITIVE_INFINITY)) { writer.write("'INF'"); } else if (dbl.equals(Double.NEGATIVE_INFINITY)) { writer.write("'-INF'"); } else if (dbl.equals(Double.NaN)) { writer.write("fn:number(())"); // poor man's way to write NaN } else { writer.write(o.toString()); } writer.write(")"); } else if (o instanceof Boolean) { writer.write("xs:boolean('"); writer.write(o.toString()); writer.write("')"); } else if (o instanceof BigDecimal) { writer.write("xs:decimal("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Date) { // We want something like: 2006-04-30T01:28:30.499-07:00 // We format to get: 2006-04-30T01:28:30.499-0700 // Then we add in the colon writer.write("xs:dateTime('"); String d = dateFormat.format((Date) o); writer.write(d.substring(0, d.length() - 2)); writer.write(":"); writer.write(d.substring(d.length() - 2)); writer.write("')"); } else if (o instanceof XMLGregorianCalendar) { XMLGregorianCalendar greg = (XMLGregorianCalendar) o; QName type = greg.getXMLSchemaType(); if (type.equals(DatatypeConstants.DATETIME)) { writer.write("xs:dateTime('"); } else if (type.equals(DatatypeConstants.DATE)) { writer.write("xs:date('"); } else if (type.equals(DatatypeConstants.TIME)) { writer.write("xs:time('"); } else if (type.equals(DatatypeConstants.GYEARMONTH)) { writer.write("xs:gYearMonth('"); } else if (type.equals(DatatypeConstants.GMONTHDAY)) { writer.write("xs:gMonthDay('"); } else if (type.equals(DatatypeConstants.GYEAR)) { writer.write("xs:gYear('"); } else if (type.equals(DatatypeConstants.GMONTH)) { writer.write("xs:gMonth('"); } else if (type.equals(DatatypeConstants.GDAY)) { writer.write("xs:gDay('"); } writer.write(greg.toXMLFormat()); writer.write("')"); } else if (o instanceof Duration) { Duration dur = (Duration) o; /* // The following fails on Xerces QName type = dur.getXMLSchemaType(); if (type.equals(DatatypeConstants.DURATION)) { writer.write("xs:duration('"); } else if (type.equals(DatatypeConstants.DURATION_DAYTIME)) { writer.write("xdt:dayTimeDuration('"); } else if (type.equals(DatatypeConstants.DURATION_YEARMONTH)) { writer.write("xdt:yearMonthDuration('"); } */ // If no years or months, must be DURATION_DAYTIME if (dur.getYears() == 0 && dur.getMonths() == 0) { writer.write("xdt:dayTimeDuration('"); } // If has years or months but nothing else, must be DURATION_YEARMONTH else if (dur.getDays() == 0 && dur.getHours() == 0 && dur.getMinutes() == 0 && dur.getSeconds() == 0) { writer.write("xdt:yearMonthDuration('"); } else { writer.write("xs:duration('"); } writer.write(dur.toString()); writer.write("')"); } else if (o instanceof org.jdom.Element) { org.jdom.Element elt = (org.jdom.Element) o; writer.write("xdmp:unquote('"); // Because "<" in XQuery is the same as "<" I need to double escape any ampersands writer.write(new org.jdom.output.XMLOutputter().outputString(elt).replaceAll("&", "&") .replaceAll("'", "''")); writer.write("')/*"); // make sure to return the root elt } else if (o instanceof org.jdom.Document) { org.jdom.Document doc = (org.jdom.Document) o; writer.write("xdmp:unquote('"); writer.write(new org.jdom.output.XMLOutputter().outputString(doc).replaceAll("&", "&") .replaceAll("'", "''")); writer.write("')"); } else if (o instanceof org.jdom.Text) { org.jdom.Text text = (org.jdom.Text) o; writer.write("text {'"); writer.write(escapeSingleQuotes(text.getText())); writer.write("'}"); } else if (o instanceof org.jdom.Attribute) { // <fake xmlns:pref="http://uri.com" pref:attrname="attrvalue"/>/@*:attrname // <fake xmlns="http://uri.com" attrname="attrvalue"/>/@*:attrname org.jdom.Attribute attr = (org.jdom.Attribute) o; writer.write("<fake xmlns"); if ("".equals(attr.getNamespacePrefix())) { writer.write("=\""); } else { writer.write(":" + attr.getNamespacePrefix() + "=\""); } writer.write(attr.getNamespaceURI()); writer.write("\" "); writer.write(attr.getQualifiedName()); writer.write("=\""); writer.write(escapeSingleQuotes(attr.getValue())); writer.write("\"/>/@*:"); writer.write(attr.getName()); } else if (o instanceof org.jdom.Comment) { org.jdom.Comment com = (org.jdom.Comment) o; writer.write("comment {'"); writer.write(escapeSingleQuotes(com.getText())); writer.write("'}"); } else if (o instanceof org.jdom.ProcessingInstruction) { org.jdom.ProcessingInstruction pi = (org.jdom.ProcessingInstruction) o; writer.write("processing-instruction "); writer.write(pi.getTarget()); writer.write(" {'"); writer.write(escapeSingleQuotes(pi.getData())); writer.write("'}"); } else if (o instanceof QName) { QName q = (QName) o; writer.write("fn:expanded-QName('"); writer.write(escapeSingleQuotes(q.getNamespaceURI())); writer.write("','"); writer.write(q.getLocalPart()); writer.write("')"); } else { writer.write("error('XQuery tried to retrieve unsupported type: " + o.getClass().getName() + "')"); } writer.flush(); }
From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java
/** * If time is > 60*60*24 [seconds], it will be projected into next day, e.g. * time=60*60*24+1=1//from w w w .jav a 2 s. c o m * * even if time is negative, it is turned into a positive time by adding * number of seconds of day into it consecutively * * @param time * @return */ public static double projectTimeWithin24Hours(double time) { double secondsInOneDay = 60 * 60 * 24; if (time == Double.NEGATIVE_INFINITY || time == Double.POSITIVE_INFINITY) { DebugLib.stopSystemAndReportInconsistency("time is not allowed to be minus or plus infinity"); } while (time < 0) { time += secondsInOneDay; } if (time < secondsInOneDay) { return time; } else { return ((time / secondsInOneDay) - (Math.floor(time / secondsInOneDay))) * secondsInOneDay; } }
From source file:com.rapidminer.gui.plotter.charts.StackedBarChartPlotter.java
@Override public void updatePlotter() { final int categoryCount = prepareData(); if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title null, // domain axis label null, // range axis label categoryDataSet, // usedCategoryDataSet, // data orientationIndex == ORIENTATION_TYPE_VERTICAL ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, // orientation true, // include legend if group by column is set true, // tooltips false // URLs );/*ww w . j a v a2s.c o m*/ // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); CategoryPlot plot = chart.getCategoryPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); String domainName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null; domainAxis.setLabel(domainName); // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); String rangeName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null; rangeAxis.setLabel(rangeName); // bar renderer int length = 0; // if ((groupByColumn >= 0) && this.dataTable.isNominal(groupByColumn)) { // length = this.dataTable.getNumberOfValues(groupByColumn); // } else { // length = categoryDataSet.getColumnCount(); // } if (stackGroupColumn >= 0 && this.dataTable.isNominal(stackGroupColumn)) { length = this.dataTable.getNumberOfValues(stackGroupColumn); } else { length = categoryDataSet.getRowCount(); } final double[] colorValues = new double[length]; for (int i = 0; i < colorValues.length; i++) { colorValues[i] = i; } BarRenderer renderer = new StackedBarRenderer() { private static final long serialVersionUID = 1912387984078591157L; private ColorProvider colorProvider = getColorProvider(true); private double minColor = Double.POSITIVE_INFINITY; private double maxColor = Double.NEGATIVE_INFINITY; { if (colorValues != null) { for (double d : colorValues) { this.minColor = MathFunctions.robustMin(this.minColor, d); this.maxColor = MathFunctions.robustMax(this.maxColor, d); } } } @Override public Paint getSeriesPaint(int series) { if (colorValues == null || minColor == maxColor || series >= colorValues.length) { return ColorProvider.reduceColorBrightness(Color.RED); } else { double normalized = (colorValues[series] - minColor) / (maxColor - minColor); return colorProvider.getPointColor(normalized); } } }; renderer.setBarPainter(new RapidBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); plot.setRenderer(renderer); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (panel instanceof AbstractChartPanel) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.StackedBarChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
From source file:ml.shifu.shifu.core.binning.UpdateBinningInfoReducer.java
public double getCutoffBoundary(double val, double max, double min) { if (val == Double.POSITIVE_INFINITY) { return max; } else if (val == Double.NEGATIVE_INFINITY) { return min; } else {//from ww w .j a v a2 s . c o m return val; } }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the range of the values in this dataset's range. * * @param includeInterval ignored.//from w w w. j a v a2s. c om * * @return The range (or <code>null</code> if the dataset contains no * values). */ @Override public Range getRangeBounds(boolean includeInterval) { double lower = Double.POSITIVE_INFINITY; double upper = Double.NEGATIVE_INFINITY; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double minY = series.getMinY(); if (!Double.isNaN(minY)) { lower = Math.min(lower, minY); } double maxY = series.getMaxY(); if (!Double.isNaN(maxY)) { upper = Math.max(upper, maxY); } } if (lower > upper) { return null; } else { return new Range(lower, upper); } }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.DefaultCapacityOriginator.java
private double determineStepwiseElasticityFactor(double rateRatio) { double[][] elasticity = null; if (elasticity == null) { elasticity = ParserFunctions/*from w w w .java 2s . c o m*/ .parseMapToDoubleArray(capacityStructure.elasticityModelXml.getAttribute("map")); } if (Math.abs(rateRatio - 1) < 0.01 || elasticity.length == 0) return 1.0; PowerType powerType = parentBundle.getPowerType(); if (powerType.isConsumption() && rateRatio < 1.0) return 1.0; if (powerType.isProduction() && rateRatio > 1.0) return 1.0; final int RATE_RATIO_INDEX = 0; final int CAPACITY_FACTOR_INDEX = 1; double rateLowerBound = Double.NEGATIVE_INFINITY; double rateUpperBound = Double.POSITIVE_INFINITY; double lowerBoundCapacityFactor = 1.0; double upperBoundCapacityFactor = 1.0; for (int i = 0; i < elasticity.length; ++i) { double r = elasticity[i][RATE_RATIO_INDEX]; if (r <= rateRatio && r > rateLowerBound) { rateLowerBound = r; lowerBoundCapacityFactor = elasticity[i][CAPACITY_FACTOR_INDEX]; } if (r >= rateRatio && r < rateUpperBound) { rateUpperBound = r; upperBoundCapacityFactor = elasticity[i][CAPACITY_FACTOR_INDEX]; } } return (rateRatio < 1) ? upperBoundCapacityFactor : lowerBoundCapacityFactor; }