Example usage for java.lang Double isFinite

List of usage examples for java.lang Double isFinite

Introduction

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

Prototype

public static boolean isFinite(double d) 

Source Link

Document

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

Usage

From source file:com.simiacryptus.mindseye.lang.Tensor.java

/**
 * Instantiates a new Tensor./*from  w  ww  .  j  a  va  2 s .  c  o  m*/
 *
 * @param data the data
 * @param dims the dims
 */
public Tensor(@Nullable final float[] data, @Nonnull final int... dims) {
    if (Tensor.length(dims) >= Integer.MAX_VALUE)
        throw new IllegalArgumentException();
    dimensions = Arrays.copyOf(dims, dims.length);
    strides = Tensor.getSkips(dims);
    if (null != data) {
        this.data = RecycleBin.DOUBLES.obtain(data.length);// Arrays.copyOf(data, data.length);
        Arrays.parallelSetAll(this.data, i -> {
            final double v = data[i];
            return Double.isFinite(v) ? v : 0;
        });
        assert Arrays.stream(this.data).allMatch(v -> Double.isFinite(v));
    }
    assert isValid();
    //assert (null == data || Tensor.length(dims) == data.length);
}

From source file:com.yahoo.druid.metriccollector.MetricCollectorResource.java

@LifecycleStart
public void start() {
    log.info("Starting thread to logAndClear number of events sent");
    loggingService.scheduleAtFixedRate(new Runnable() {
        final String feedDimName = "feedSource";

        @Override/*from  w w w . j  a  v  a  2s  .c om*/
        public void run() {
            try {
                ImmutableMap<String, EventCounter> eventsCounterMetrics = eventLogger.snapshotAndClear();
                if (eventsCounterMetrics.isEmpty()) {
                    log.info("Event Counter Metrics is Empty");
                }
                for (String clusterKey : eventsCounterMetrics.keySet()) {
                    final EventCounter eventCounter = eventsCounterMetrics.get(clusterKey);
                    emitter.emit(ServiceMetricEvent.builder().setDimension(feedDimName, clusterKey)
                            .build("metricCollector/lostEvents", eventCounter.getEventLost().longValue()));
                    if (eventCounter.getEventLost().longValue() > 0) {
                        log.error("Kafka Producer lost [%d] events from cluster [%s]",
                                eventCounter.getEventLost().longValue(), clusterKey);
                    }
                    emitter.emit(ServiceMetricEvent.builder().setDimension(feedDimName, clusterKey)
                            .build("metricCollector/sentEvents", eventCounter.getEventSent().longValue()));
                    emitter.emit(ServiceMetricEvent.builder().setDimension(feedDimName, clusterKey)
                            .build("metricCollector/eventsSize", eventCounter.getEventSize().longValue()));
                    log.info("Kafka Producer successfully sent [%d] events from cluster [%s]",
                            eventCounter.getEventSent().longValue(), clusterKey);

                    log.info(
                            "Total size of received events for cluster [%s] is [%d] bytes during a window of [%d] ms",
                            clusterKey, eventCounter.getEventSize().longValue(), logFrequency);
                }

                /* Information and documentation about kafka metrics's descriptions can be viewed at https://kafka.apache.org/082/ops.html */
                final Map<MetricName, ? extends Metric> kafkaMetrics = producer.metrics();
                for (Map.Entry<MetricName, ? extends Metric> metric : kafkaMetrics.entrySet()) {
                    double value = metric.getValue().value();
                    if (Double.isFinite(value)) {
                        emitter.emit(ServiceMetricEvent.builder()
                                .build("metricCollector/kafka/" + metric.getKey().name(), value));
                    } else {
                        log.debug("Could not emit metric [%s] since its value is NaN", metric.getKey().name());
                    }
                }
            } catch (Exception e) {
                log.error(e, "Got an exception at the logging thread");
            }
        }
    }, 1000, logFrequency, TimeUnit.MILLISECONDS);
}

From source file:edu.byu.nlp.crowdsourcing.measurements.classification.PANClassificationMeasurementModel.java

private void fitNuSigma2(State state, ClassificationMeasurementModelExpectations expectations) {
    double[][] nuSigma2 = state.getNuSigma2();

    for (int j = 0; j < state.getNumAnnotators(); j++) {
        double priorAlpha = getPriorAlpha(state, j), priorBeta = getPriorBeta(state, j);

        // each inverse gamma distributed sigma2_j has two variational parameters: shape (nuSigma2[j][0]) and scale (nuSigma2[j][1]).

        // posterior alpha
        nuSigma2[j][0] = (state.getStaticCounts().getPerAnnotatorMeasurementCounts().getCount(j) / 2.0)
                + priorAlpha;/*from w  w  w .j a  va2  s.com*/
        Preconditions.checkState(Double.isFinite(nuSigma2[j][0]));

        // posterior beta
        // error sum
        double errorSum = 0;
        for (MeasurementExpectation<Integer> expectation : expectations.getExpectationsForAnnotator(j)) {
            double tau_jk = expectation.getMeasurement().getValue();
            if (SCALE_MEASUREMENTS) {
                // empirical measurements are often already scaled between 0 and 1 
                // (because annotators aren't good at guessing what the normalizer should be)
                if (!state.getMeasurementsPreScaled()) {
                    double range = expectation.getRange().upperEndpoint()
                            - expectation.getRange().lowerEndpoint();
                    tau_jk = expectation.getMeasurement().getValue() / range; // scale the observation
                }
                expectation = ScaledMeasurementExpectation.from(expectation); // scale the expectation quantities
            }
            errorSum += Math.pow(tau_jk, 2);
            errorSum -= 2 * tau_jk * expectation.sumOfExpectedValuesOfSigma();
            errorSum += Math.pow(expectation.sumOfExpectedValuesOfSigma(), 2);
            errorSum -= expectation.piecewiseSquaredSumOfExpectedValuesOfSigma();
            errorSum += expectation.sumOfExpectedValuesOfSquaredSigma();
            Preconditions.checkState(Double.isFinite(errorSum));
        }

        nuSigma2[j][1] = priorBeta + (0.5 * errorSum);
        Preconditions.checkState(Double.isFinite(nuSigma2[j][1]));
    }
}

From source file:org.rhwlab.dispim.nucleus.NucleusData.java

public Ellipse2d ellipse(int xi, int yi, int zi, Coeff coef) {
    Array2DRowRealMatrix Q = new Array2DRowRealMatrix(3, 3);
    Q.setEntry(0, 0, coef.A);/* w w w.ja  v a2s  .  com*/
    Q.setEntry(1, 0, coef.B / 2);
    Q.setEntry(0, 1, coef.B / 2);
    Q.setEntry(1, 1, coef.C);
    Q.setEntry(2, 0, coef.D / 2);
    Q.setEntry(0, 2, coef.D / 2);
    Q.setEntry(2, 1, coef.E / 2);
    Q.setEntry(1, 2, coef.E / 2);
    Q.setEntry(2, 2, coef.F);
    EigenDecomposition ed = new EigenDecomposition(Q);
    double detQ = ed.getDeterminant();

    RealMatrix rm = new Array2DRowRealMatrix(2, 2);
    rm.setEntry(0, 0, coef.A);
    rm.setEntry(1, 1, coef.C);
    rm.setEntry(0, 1, coef.B / 2.0);
    rm.setEntry(1, 0, coef.B / 2.0);
    EigenDecomposition eigenDecomp = new EigenDecomposition(rm);
    double detA33 = eigenDecomp.getDeterminant();
    double[] eigenValues = eigenDecomp.getRealEigenvalues();
    //System.out.printf("Eigenvalues: %f,%f\n",eigenValues[0],eigenValues[1])        ;
    RealVector eigenvector0 = eigenDecomp.getEigenvector(0);
    Ellipse2d e = new Ellipse2d();
    double cot2theta = (coef.A - coef.C) / coef.B;
    if (Double.isFinite(cot2theta)) {
        double d = Math.sqrt(1.0 + cot2theta * cot2theta);
        double cos2theta = cot2theta / d;
        e.cosine = Math.sqrt((1.0 + cos2theta) / 2.0);
        e.sine = Math.sqrt((1.0 - cos2theta) / 2.0);
    } else {
        e.cosine = 1.0;
        e.sine = 0.0;
    }

    double dd = coef.B * coef.B - 4.0 * coef.A * coef.C;
    double xc = (2.0 * coef.C * coef.D - coef.B * coef.E) / dd;
    double yc = (2.0 * coef.A * coef.E - coef.B * coef.D) / dd;
    // System.out.printf("dd=%f,xc=%f,xcn=%f,yc=%f,ycn%f\n",dd,xc,xcn,yc,ycn);
    double[] ce = this.getCenter();
    e.x = ce[xi] + xc;
    e.y = ce[yi] + yc;

    //       double f = -detQ/detA33 * 2;
    double f = -detQ / detA33;
    double a = eigenValues[0] / f;
    double b = eigenValues[1] / f;
    if (a <= 0.0 || b <= 0.0) {
        return null;
    }
    e.a = 1.0 / Math.sqrt(a);
    e.b = 1.0 / Math.sqrt(b);
    //System.out.printf("detQ=%e,detA33=%e,f=%f,a=%e,b=%e\n",detQ,detA33,f,e.a,e.b);        
    //System.out.printf("eigenValues (%f,%f)\n",eigenValues[0],eigenValues[1]);
    e.cosine = eigenvector0.getEntry(0);
    e.sine = eigenvector0.getEntry(1);
    e.low[xi] = (long) (e.x - e.a);
    e.low[yi] = (long) (e.y - e.b);
    e.low[zi] = 0;
    e.high[xi] = (long) (e.x + e.a);
    e.high[yi] = (long) (e.y + e.b);
    e.high[zi] = 0;
    //System.out.printf("Ellipse: a=%f,b=%f,x=%f,y=%f\n", e.a,e.b,e.x,e.y);
    return e;
}

From source file:ffx.potential.extended.ExtendedVariable.java

public ExtendedVariable(MultiResidue multiRes, double biasMag, double initialLambda) {
    index = esvIndexer++;//  w w  w .ja  v a  2 s .  c  o  m
    discrBiasBeta = Double.isFinite(biasOverride) ? biasOverride : biasMag;
    this.switchingFunction = new MultiplicativeSwitch(0.0, 1.0);
    setLambda(initialLambda);

    this.multiRes = multiRes;
    resOne = multiRes.getActive();
    termNode = resOne.getTerms();
    resZro = multiRes.getInactive().get(0);
    moleculeNumber = resOne.getAtomList().get(0).getMoleculeNumber();

    atomLists = new HashMap<>();
    atomsOneExtH = new ArrayList<>();
    atomsZroExtH = new ArrayList<>();
    atomsSharedExtH = new ArrayList<>();
    atomsUnsharedExtH = new ArrayList<>();
    atomsOneExtAll = new ArrayList<>();
    atomsZroExtAll = new ArrayList<>();
    bondedAllAtoms = new ArrayList<>();
    atomLists.put(AtomList.PMEVDW_ONE, atomsOneExtH);
    atomLists.put(AtomList.PMEVDW_ZRO, atomsZroExtH);
    atomLists.put(AtomList.PMEVDW_SHARED, atomsSharedExtH);
    atomLists.put(AtomList.PMEVDW_UNSHARED, atomsUnsharedExtH);
    atomLists.put(AtomList.BONDED_ONE, atomsOneExtAll);
    atomLists.put(AtomList.BONDED_ZRO, atomsZroExtAll);
    atomLists.put(AtomList.BONDED_ALL, bondedAllAtoms);

    if (ExtendedSystem.esvDecomposeBonded) {
        inplayDerivDecomp = new HashMap<>();
        backgroundDerivDecomp = new HashMap<>();
    } else {
        inplayDerivDecomp = null;
        backgroundDerivDecomp = null;
    }
}

From source file:ijfx.ui.filter.DefaultNumberFilter.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {//from  w w  w  . j  ava  2  s. c  om
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .mapToDouble(v -> v.doubleValue()).sorted().toArray();
    distribution.load(values);

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {

        serie.getData().addAll(data);
        areaChart.getData().clear();

        areaChart.getData().add(serie);

        updateSlider(min, max, finalBinNumber);
    });
}

From source file:de.bund.bfr.knime.nls.chart.ChartCreator.java

public JFreeChart createChart() throws ParseException {
    if (varX == null || varY == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }/* w  w w  . j  av a 2s  . co  m*/

    List<String> idsToPaint;

    if (selectAll) {
        idsToPaint = new ArrayList<>(plotables.keySet());
    } else {
        idsToPaint = selectedIds;
    }

    NumberAxis xAxis = new NumberAxis(transformX.getName(varX));
    NumberAxis yAxis = new NumberAxis(transformY.getName(varY));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    double usedMinX = Double.POSITIVE_INFINITY;
    double usedMaxX = Double.NEGATIVE_INFINITY;
    int index = 0;
    List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size());
    List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size());

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        if (plotable.isDataType()) {
            double[][] points = plotable.getDataPoints(varX, varY, transformX, transformY);

            if (points != null) {
                for (int i = 0; i < points[0].length; i++) {
                    usedMinX = Math.min(usedMinX, points[0][i]);
                    usedMaxX = Math.max(usedMaxX, points[0][i]);
                }
            }
        }

        if (plotable.isParamType()) {
            double minArg = transformX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX)));
            double maxArg = transformX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX)));

            if (Double.isFinite(minArg)) {
                usedMinX = Math.min(usedMinX, minArg);
            }

            if (Double.isFinite(maxArg)) {
                usedMaxX = Math.max(usedMaxX, maxArg);
            }
        }
    }

    if (!Double.isFinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (!Double.isFinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    xAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRangeIncludesZero(false);

    if (usedMinX == usedMaxX) {
        usedMinX -= 1.0;
        usedMaxX += 1.0;
    }

    if (useManualRange && minX < maxX && minY < maxY) {
        usedMinX = minX;
        usedMaxX = maxX;
        xAxis.setRange(new Range(minX, maxX));
        yAxis.setRange(new Range(minY, maxY));
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        plotable.setFunctionSteps(resolution);
        plotable.setInterpolator(interpolator);

        switch (plotable.getType()) {
        case DATA:
            plotData(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index));
            break;
        case FUNCTION:
            plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_FUNCTION:
            plotDataFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DIFF:
            plotDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case DATA_DIFF:
            plotDataDiff(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        default:
            throw new RuntimeException("Unknown type of plotable: " + plotable.getType());
        }

        index++;
    }

    if (minToZero && !useManualRange) {
        Range xRange = xAxis.getRange();
        Range yRange = yAxis.getRange();

        if (xRange.getUpperBound() <= 0.0 || yRange.getUpperBound() <= 0.0) {
            return null;
        }

        xAxis.setRange(new Range(0.0, xRange.getUpperBound()));
        yAxis.setRange(new Range(0.0, yRange.getUpperBound()));
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}

From source file:com.tussle.main.Utility.java

public static Collection<ProjectionVector> prunedProjections(Collection<ProjectionVector> vectors) {
    SortedSet<ProjectionVector> sortedVectors = new ConcurrentSkipListSet<>(
            Comparator.comparingDouble((ProjectionVector p) -> -p.magnitude()));
    sortedVectors.addAll(vectors);// w w w  .  j a  v a2 s. com
    if (isPruned(sortedVectors))
        return sortedVectors;
    double reduceMagnitude = 0;
    Iterator<ProjectionVector> i = sortedVectors.iterator();
    ProjectionVector p0 = i.next();
    ProjectionVector p1 = i.next();
    double cos0 = p0.xNorm();
    double sin0 = p0.yNorm();
    double cos1 = p1.xNorm();
    double sin1 = p1.yNorm();
    //zeroth on the right, first on the left
    if (cos0 * sin1 < cos1 * sin0) {
        double tmpcos = cos1;
        double tmpsin = sin1;
        cos1 = cos0;
        sin1 = sin0;
        cos0 = tmpcos;
        sin0 = tmpsin;
    }
    while (i.hasNext()) {
        ProjectionVector next = i.next();
        double nextcos = next.xNorm();
        double nextsin = next.yNorm();
        if (nextcos * sin0 >= cos0 * nextsin && cos1 * nextsin >= nextcos * sin1) {
            //Case 0: Within cross product bounds
        } else if (nextcos * sin0 >= cos0 * nextsin) {
            //Case 1: Over the left, extend those bounds
            cos1 = nextcos;
            sin1 = nextsin;
        } else if (cos1 * nextsin >= nextcos * sin1) {
            //Case 2: Over the right, extend those bounds
            cos0 = nextcos;
            sin0 = nextsin;
        } else {
            //Case 3: Opposite side, immediately return false
            reduceMagnitude = next.magnitude();
            break;
        }
    }
    //Now given reduceMagnitude, remove elements with lesser magnitude and
    //reduce the magnitude of remaining elements
    if (Double.isFinite(reduceMagnitude)) {
        for (Iterator<ProjectionVector> j = sortedVectors.iterator(); j.hasNext();) {
            ProjectionVector vec = j.next();
            if (vec.magnitude() <= reduceMagnitude)
                j.remove();
            else
                vec = new ProjectionVector(vec.xNorm(), vec.yNorm(), vec.magnitude() - reduceMagnitude);
        }
    }
    return sortedVectors;
}

From source file:org.rhwlab.variationalbayesian.GaussianMixture.java

static double[] normalizeLogP(double[] lnP) {
    double[] p = new double[lnP.length];

    // find the maximum
    double maxLnP = lnP[0];
    for (int i = 1; i < p.length; ++i) {
        if (lnP[i] > maxLnP) {
            maxLnP = lnP[i];//  ww  w. j a v  a 2s.  c  om
        }
    }

    // subtract the maximum and exponentiate
    // sum is guaranted to be >= 1.0;
    double sum = 0.0;
    for (int i = 0; i < p.length; ++i) {
        p[i] = Math.exp(lnP[i] - maxLnP);
        if (!Double.isFinite(p[i])) {
            p[i] = 0.0; // underflow occured
        }
        sum = sum + p[i];
    }

    // normalize sum to 1
    for (int i = 0; i < p.length; ++i) {
        p[i] = p[i] / sum;
    }
    return p;
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

public JFreeChart getChart(List<String> idsToPaint) throws ParseException, UnitException {
    if (varX == null || varY == null || varX.getName() == null || varY.getName() == null) {
        return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend);
    }/*from   w ww  .  jav  a  2 s.  c om*/

    NumberAxis xAxis = new NumberAxis(varX.getDisplayString());
    NumberAxis yAxis = new NumberAxis(varY.getDisplayString());
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    double usedMinX = Double.POSITIVE_INFINITY;
    double usedMaxX = Double.NEGATIVE_INFINITY;
    int index = 0;
    List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size());
    List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size());

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY
                || plotable.getType() == Plotable.Type.FUNCTION
                || plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) {
            double minArg = varX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX.getName())),
                    plotable.getUnits().get(varX.getName()));
            double maxArg = varX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX.getName())),
                    plotable.getUnits().get(varX.getName()));

            if (Double.isFinite(minArg)) {
                usedMinX = Math.min(usedMinX, minArg);
            }

            if (Double.isFinite(maxArg)) {
                usedMaxX = Math.max(usedMaxX, maxArg);
            }
        }

        if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY) {
            for (Map<String, Integer> choice : plotable.getAllChoices(varX.getName())) {
                double[][] points = plotable.getPoints(varX, varY, choice);

                if (points != null) {
                    for (int i = 0; i < points[0].length; i++) {
                        usedMinX = Math.min(usedMinX, points[0][i]);
                        usedMaxX = Math.max(usedMaxX, points[0][i]);
                    }
                }
            }
        }

        if (plotable.getType() == Plotable.Type.DATASET || plotable.getType() == Plotable.Type.DATASET_MANY) {
            double[][] points = plotable.getPoints(varX, varY);

            if (points != null) {
                for (int i = 0; i < points[0].length; i++) {
                    usedMinX = Math.min(usedMinX, points[0][i]);
                    usedMaxX = Math.max(usedMaxX, points[0][i]);
                }
            }
        }

        if (plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) {
            for (Double x : plotable.getSamples()) {
                if (x != null && Double.isFinite(x)) {
                    usedMinX = Math.min(usedMinX, x);
                    usedMaxX = Math.max(usedMaxX, x);
                }
            }
        }
    }

    if (Double.isInfinite(usedMinX)) {
        usedMinX = 0.0;
    }

    if (Double.isInfinite(usedMaxX)) {
        usedMaxX = 100.0;
    }

    if (varX.getName().equals(PmmUtils.TIME) || varX.getName().equals(PmmUtils.CONCENTRATION)) {
        usedMinX = Math.min(usedMinX, 0.0);
        xAxis.setAutoRangeIncludesZero(true);
    } else {
        xAxis.setAutoRangeIncludesZero(false);
    }

    if (varY.getName().equals(PmmUtils.TIME) || varY.getName().equals(PmmUtils.CONCENTRATION)) {
        yAxis.setAutoRangeIncludesZero(true);
    } else {
        yAxis.setAutoRangeIncludesZero(false);
    }

    if (usedMinX == usedMaxX) {
        usedMinX -= 1.0;
        usedMaxX += 1.0;
    }

    if (useManualRange && minX < maxX && minY < maxY) {
        usedMinX = minX;
        usedMaxX = maxX;
        xAxis.setRange(new Range(minX, maxX));
        yAxis.setRange(new Range(minY, maxY));
    }

    for (String id : idsToPaint) {
        Plotable plotable = plotables.get(id);

        if (plotable == null) {
            continue;
        }

        plotable.setFunctionSteps(resolution);

        switch (plotable.getType()) {
        case DATASET:
            plotDataSet(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index));
            break;
        case DATASET_MANY:
            plotDataSetStrict(plot, plotable, id);
            break;
        case FUNCTION:
            plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case FUNCTION_SAMPLE:
            plotFunctionSample(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case BOTH:
            plotBoth(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX,
                    usedMaxX);
            break;
        case BOTH_MANY:
            plotBothStrict(plot, plotable, id, usedMinX, usedMaxX);
            break;
        default:
            throw new RuntimeException("Unknown type of plotable: " + plotable.getType());
        }

        index++;
    }

    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend);
}