Example usage for java.lang Double POSITIVE_INFINITY

List of usage examples for java.lang Double POSITIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double POSITIVE_INFINITY.

Prototype

double POSITIVE_INFINITY

To view the source code for java.lang Double POSITIVE_INFINITY.

Click Source Link

Document

A constant holding the positive infinity of type double .

Usage

From source file:ffx.xray.CrystalStats.java

/**
 * print R factors and associated statistics in a binned fashion
 *//*from   w ww.  j  a  v  a  2 s  .c  om*/
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:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java

/**
* The dual gamma/*  w  ww  .  j a  v a 2s  . c  o  m*/
* @param spot The spot value of the underlying
* @param strike The Strike
* @param timeToExpiry The time-to-expiry
* @param lognormalVol The log-normal volatility
* @param interestRate The interest rate 
* @param costOfCarry The cost-of-carry  rate
* @return The dual gamma
*/
@ExternalFunction
public static double dualGamma(final double spot, final double strike, final double timeToExpiry,
        final double lognormalVol, final double interestRate, final double costOfCarry) {
    ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot);
    ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike);
    ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry);
    ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol);
    ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN");
    ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN");

    if (-interestRate > LARGE) {
        return costOfCarry > LARGE ? 0. : Double.POSITIVE_INFINITY;
    }
    if (interestRate > LARGE) {
        return 0.;
    }
    double discount = (Math.abs(interestRate) < SMALL && timeToExpiry > LARGE) ? 1.
            : Math.exp(-interestRate * timeToExpiry);

    final double rootT = Math.sqrt(timeToExpiry);
    double sigmaRootT = lognormalVol * rootT;
    if (Double.isNaN(sigmaRootT)) {
        sigmaRootT = 1.; //ref value is returned
    }
    if (spot > LARGE * strike || spot < SMALL * strike || sigmaRootT > LARGE) {
        return 0.;
    }

    double factor = Math.exp(costOfCarry * timeToExpiry);
    if (Double.isNaN(factor)) {
        factor = 1.;
    }

    double d2 = 0.;
    if (Math.abs(spot - strike) < SMALL || (spot > LARGE && strike > LARGE)) {
        final double coefD1 = (Math.abs(costOfCarry) < SMALL && lognormalVol < SMALL)
                ? Math.signum(costOfCarry) - 0.5 * lognormalVol
                : (costOfCarry / lognormalVol - 0.5 * lognormalVol);
        final double tmp = coefD1 * rootT;
        d2 = Double.isNaN(tmp) ? 0. : tmp;
    } else {
        if (sigmaRootT < SMALL) {
            final double scnd = (Math.abs(costOfCarry) > LARGE && rootT < SMALL) ? Math.signum(costOfCarry)
                    : costOfCarry * rootT;
            final double tmp = (Math.log(spot / strike) / rootT + scnd) / lognormalVol;
            d2 = Double.isNaN(tmp) ? 0. : tmp;
        } else {
            final double tmp = costOfCarry * rootT / lognormalVol;
            final double sig = (costOfCarry >= 0.) ? 1. : -1.;
            final double scnd = Double.isNaN(tmp)
                    ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT)
                    : tmp;
            d2 = Math.log(spot / strike) / sigmaRootT + scnd - 0.5 * sigmaRootT;
        }
    }
    //    if (Double.isNaN(d2)) {
    //      throw new IllegalArgumentException("NaN found");
    //    }
    final double norm = NORMAL.getPDF(d2);

    final double res = norm < SMALL ? 0. : discount * norm / strike / sigmaRootT;
    return Double.isNaN(res) ? Double.POSITIVE_INFINITY : res;
}

From source file:etomica.models.co2.PNCO2GCPM.java

public final double getRange() {
    return Double.POSITIVE_INFINITY;
}

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("()");
    }/*  www. j  av a2 s . c om*/

    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 "&lt;" in XQuery is the same as "<" I need to double escape any ampersands
        writer.write(new org.jdom.output.XMLOutputter().outputString(elt).replaceAll("&", "&amp;")
                .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("&", "&amp;")
                .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:edu.rice.cs.bioinfo.programs.phylonet.algos.network.NetworkLikelihoodFromGTTBL.java

private void computeNodeHeightUpperbound(Network network, Map<NetNode, Double> node2constraints) {
    Map<NetNode, Set<String>> node2taxa = new HashMap<>();
    for (Object o : Networks.postTraversal(network)) {
        NetNode node = (NetNode) o;//w ww. j  ava 2s .  com
        Set<String> taxa = new HashSet<>();
        double upperBound = Double.POSITIVE_INFINITY;
        if (node.isLeaf()) {
            taxa.add(node.getName());
        } else if (node.isNetworkNode()) {
            NetNode childNode = (NetNode) node.getChildren().iterator().next();
            if (!childNode.isLeaf())
                upperBound = node2constraints.get(childNode);
            taxa.addAll(node2taxa.get(childNode));
        } else {
            Set<String> intersection = null;
            List<NetNode> childNodes = null;
            for (Object childO : node.getChildren()) {
                NetNode childNode = (NetNode) childO;
                if (childNodes == null) {
                    childNodes = new ArrayList<>();
                }
                childNodes.add(childNode);
                if (intersection == null) {
                    intersection = new HashSet<>();
                    intersection.addAll(node2taxa.get(childNode));
                } else {
                    intersection.retainAll(node2taxa.get(childNode));
                }

                taxa.addAll(node2taxa.get(childNode));
            }

            for (int i = 0; i < childNodes.size(); i++) {
                Set<String> taxa1 = node2taxa.get(childNodes.get(i));
                for (int j = i + 1; j < childNodes.size(); j++) {
                    Set<String> taxa2 = node2taxa.get(childNodes.get(j));
                    for (String taxon1 : taxa1) {
                        if (intersection.contains(taxon1))
                            continue;
                        for (String taxon2 : taxa2) {
                            if (intersection.contains(taxon2))
                                continue;
                            upperBound = Math.min(upperBound,
                                    _pair2time.get(new UnorderedPair(taxon1, taxon2)));
                        }
                    }

                }
            }
        }
        if (!node.isLeaf()) {
            node2constraints.put(node, upperBound);
        }
        node2taxa.put(node, taxa);
    }
}

From source file:de.tuberlin.uebb.jbop.example.DerivativeStructureOnlyCompose.java

/**
 * Returns the hypotenuse of a triangle with sides {@code x} and {@code y} -
 * sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)<br/>
 * avoiding intermediate overflow or underflow.
 * //  w  w  w.  jav a 2s  .c  o  m
 * <ul>
 * <li>If either argument is infinite, then the result is positive infinity.</li>
 * <li>else, if either argument is NaN then the result is NaN.</li>
 * </ul>
 * 
 * @param x
 *          a value
 * @param y
 *          a value
 * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
 * @throws DimensionMismatchException
 *           if number of free parameters or orders are inconsistent
 */
public static DerivativeStructureOnlyCompose hypot(final DerivativeStructureOnlyCompose x,
        final DerivativeStructureOnlyCompose y) throws DimensionMismatchException {

    x.compiler.checkCompatibility(y.compiler);

    if (Double.isInfinite(x.data[0]) || Double.isInfinite(y.data[0])) {
        return new DerivativeStructureOnlyCompose(x.compiler.getFreeParameters(),
                x.compiler.getFreeParameters(), Double.POSITIVE_INFINITY);
    } else if (Double.isNaN(x.data[0]) || Double.isNaN(y.data[0])) {
        return new DerivativeStructureOnlyCompose(x.compiler.getFreeParameters(),
                x.compiler.getFreeParameters(), Double.NaN);
    } else {

        final int expX = x.getExponent();
        final int expY = y.getExponent();
        if (expX > (expY + 27)) {
            // y is neglectible with respect to x
            return x.abs();
        } else if (expY > (expX + 27)) {
            // x is neglectible with respect to y
            return y.abs();
        } else {

            // find an intermediate scale to avoid both overflow and underflow
            final int middleExp = (expX + expY) / 2;

            // scale parameters without losing precision
            final DerivativeStructureOnlyCompose scaledX = x.scalb(-middleExp);
            final DerivativeStructureOnlyCompose scaledY = y.scalb(-middleExp);

            // compute scaled hypotenuse
            final DerivativeStructureOnlyCompose scaledH = scaledX.multiply(scaledX)
                    .add(scaledY.multiply(scaledY)).sqrt();

            // remove scaling
            return scaledH.scalb(middleExp);

        }

    }
}

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 a2 s . co  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
        );/*from   ww  w . ja v a 2 s.  co  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:dr.evomodel.epidemiology.casetocase.CaseToCaseTreeLikelihood.java

public double getInfectionTime(AbstractCase thisCase) {

    if (!recalculateCaseFlags[outbreak.getCaseIndex(thisCase)]) {
        return infectionTimes[outbreak.getCaseIndex(thisCase)];
    } else {//from   ww  w  .jav a 2  s.c o m
        if (thisCase.wasEverInfected()) {
            NodeRef child = ((PartitionedTreeModel) treeModel).getEarliestNodeInElement(thisCase);
            NodeRef parent = treeModel.getParent(child);

            if (parent != null) {

                double min = heightToTime(treeModel.getNodeHeight(parent));

                // Let the likelihood evaluate to zero due to culling dates if it must...

                double max = heightToTime(treeModel.getNodeHeight(child));

                return getInfectionTime(min, max, thisCase);
            } else {
                return getRootInfectionTime(getBranchMap());
            }
        } else {
            return Double.POSITIVE_INFINITY;
        }
    }
}

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 {//w  w  w .j a  v  a  2 s  .  c o m
        return val;
    }
}