Example usage for java.lang Number doubleValue

List of usage examples for java.lang Number doubleValue

Introduction

In this page you can find the example usage for java.lang Number doubleValue.

Prototype

public abstract double doubleValue();

Source Link

Document

Returns the value of the specified number as a double .

Usage

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Integer> getZipf(final RandomNumberStream rng, final Number numberOfElements,
        final Number exponent) {
    final IntegerDistribution dist = new ZipfDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng),
            numberOfElements.intValue(), exponent.doubleValue());
    return new RandomNumberDistribution<Integer>() {
        @Override/*from w w  w  . j  a  va2s . c o m*/
        public Integer draw() {
            return dist.sample();
        }
    };
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getCauchy(final RandomNumberStream rng, final Number median,
        final Number scale) {
    final RealDistribution dist = new CauchyDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng),
            median.doubleValue(), scale.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override/*from   w  ww . j  a  v  a 2s  .  c om*/
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:net.myrrix.online.eval.ParameterOptimizer.java

/**
 * @return a {@link Map} between the values of the given {@link System} properties and the best value found
 *  during search/*from w w w .  j ava2s.c  om*/
 * @throws ExecutionException if an error occurs while calling {@code evaluator}; the cause is the
 *  underlying exception
 */
public Map<String, Number> findGoodParameterValues() throws ExecutionException {

    int numProperties = parameterRanges.size();
    String[] propertyNames = new String[numProperties];
    Number[][] parameterValuesToTry = new Number[numProperties][];
    int index = 0;
    for (Map.Entry<String, ParameterRange> entry : parameterRanges.entrySet()) {
        propertyNames[index] = entry.getKey();
        parameterValuesToTry[index] = entry.getValue().buildSteps(numSteps);
        index++;
    }

    int numTests = 1;
    for (Number[] toTry : parameterValuesToTry) {
        numTests *= toTry.length;
    }

    List<Pair<Double, String>> testResultLinesByValue = Lists.newArrayListWithCapacity(numTests);

    Map<String, Number> bestParameterValues = Maps.newHashMap();
    double bestValue = minimize ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;

    for (int test = 0; test < numTests; test++) {

        StringBuilder testResultLine = new StringBuilder();
        for (int prop = 0; prop < numProperties; prop++) {
            String property = propertyNames[prop];
            Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop);
            String propertyString = parameterValue.toString();
            log.info("Setting {}={}", property, propertyString);
            System.setProperty(property, propertyString);
            testResultLine.append('[').append(property).append('=').append(propertyString).append("] ");
        }

        Number evaluatorResult;
        try {
            evaluatorResult = evaluator.call();
        } catch (Exception e) {
            throw new ExecutionException(e);
        }
        if (evaluatorResult == null) {
            continue;
        }
        double testValue = evaluatorResult.doubleValue();
        testResultLine.append("= ").append(testValue);
        testResultLinesByValue.add(new Pair<Double, String>(testValue, testResultLine.toString()));
        log.info("{}", testResultLine);

        if (minimize ? testValue < bestValue : testValue > bestValue) {
            log.info("New best value {}", testValue);
            bestValue = testValue;
            for (int prop = 0; prop < numProperties; prop++) {
                String property = propertyNames[prop];
                Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop);
                bestParameterValues.put(property, parameterValue);
            }
        }

        Collections.sort(testResultLinesByValue, new Comparator<Pair<Double, String>>() {
            @Override
            public int compare(Pair<Double, String> a, Pair<Double, String> b) {
                if (a.getFirst() > b.getFirst()) {
                    return -1;
                }
                if (a.getFirst() < b.getFirst()) {
                    return 1;
                }
                return 0;
            }
        });

        for (Pair<Double, String> result : testResultLinesByValue) {
            log.info("{}", result.getSecond());
        }
        log.info("Best parameter values so far are {}", bestParameterValues);
    }

    log.info("Final best parameter values are {}", bestParameterValues);
    return bestParameterValues;
}

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

/** Draws the visual representation of a single data item.
 *//*from www .  j av  a  2 s .co m*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairInfo, int pass) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    Shape entityArea = null;

    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    Number x1n = dataset.getX(series, item);
    Number y1n = dataset.getY(series, item);
    if (y1n == null || x1n == null) {
        return;
    }

    double x1 = x1n.doubleValue();
    double y1 = y1n.doubleValue();
    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    PlotOrientation orientation = plot.getOrientation();

    if (item > 0) {
        // get the previous data point...
        Number x0n = dataset.getX(series, item - 1);
        Number y0n = dataset.getY(series, item - 1);
        if (y0n != null && x0n != null) {
            double x0 = x0n.doubleValue();
            double y0 = y0n.doubleValue();

            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }

            if (orientation == PlotOrientation.HORIZONTAL) {
                line.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line.setLine(transX0, transY0, transX1, transY1);
            }

            if (y1n instanceof RangeInfo) {
                RangeInfo y1r = (RangeInfo) y1n;
                double transY1low = rangeAxis.valueToJava2D(y1r.getRangeLowerBound(false), dataArea,
                        yAxisLocation);
                double transY1high = rangeAxis.valueToJava2D(y1r.getRangeUpperBound(false), dataArea,
                        yAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1, transY1low, transX1, transY1high);

            } else if (x1n instanceof RangeInfo) {
                RangeInfo x1r = (RangeInfo) x1n;
                double transX1low = domainAxis.valueToJava2D(x1r.getRangeLowerBound(false), dataArea,
                        xAxisLocation);
                double transX1high = domainAxis.valueToJava2D(x1r.getRangeUpperBound(false), dataArea,
                        xAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1low, transY1, transX1high, transY1);

            } else if (line.intersects(dataArea)) {
                g2.draw(line);
            }
        }
    } else if (dataset.getItemCount(series) == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;
    }

    if (entities != null && (dataArea.contains(transX1, transY1) || entityArea != null)) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getLogNormal(final RandomNumberStream rng, final Number scale,
        final Number shape) {
    final RealDistribution dist = new LogNormalDistribution(
            RandomNumberStream.Util.asCommonsRandomGenerator(rng), scale.doubleValue(), shape.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override//from ww  w. jav  a  2 s.c  o  m
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:org.mongojack.internal.object.BsonObjectTraversingParser.java

@Override
public BigDecimal getDecimalValue() throws IOException {
    Number n = currentNumericNode();
    if (n instanceof BigDecimal) {
        return (BigDecimal) n;
    } else {/*from   ww w  .j a v a 2 s.  c  o  m*/
        return BigDecimal.valueOf(n.doubleValue());
    }
}

From source file:net.sf.eventgraphj.analysis.InverseDistanceCentralityScorer.java

/**
 * Calculates the score for the specified vertex. Returns {@code null} if
 * there are missing distances and such are not ignored by this instance.
 *///from w ww.  j a va2  s .  c o m
@Override
public Double getVertexScore(V v) {
    Double value = this.output.get(v);
    if (value != null) {
        if (value < 0) {
            return null;
        }
        return value;
    }

    Map<V, Number> v_distances = new HashMap<V, Number>(this.distance.getDistanceMap(v));
    if (this.ignore_self_distances) {
        v_distances.remove(v);
    }

    // if we don't ignore missing distances and there aren't enough
    // distances, output null (shortcut)
    if (!this.ignore_missing) {
        int num_dests = this.graph.getVertexCount() - (this.ignore_self_distances ? 1 : 0);
        if (v_distances.size() != num_dests) {
            this.output.put(v, -1.0);
            return null;
        }
    }

    Double sum = 0.0;
    int count = 0;
    for (V w : this.graph.getVertices()) {
        if (w.equals(v) && this.ignore_self_distances) {
            continue;
        }
        Number w_distance = v_distances.get(w);
        if (w_distance == null) {
            if (this.ignore_missing) {
                w_distance = Double.POSITIVE_INFINITY;// graph.getVertexCount();
            } else {
                this.output.put(v, -1.0);
                return null;
            }
        }
        sum += 1 / w_distance.doubleValue();
        count++;
    }
    value = sum;
    if (this.averaging && count > 0) {
        value /= count;
    }
    this.output.put(v, value);
    if (Double.isNaN(value)) {
        System.err.println(value);
    }
    // assert (!Double.isNaN(value));
    return value;
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getUniformReal(final RandomNumberStream rng, final Number lower,
        final Number upper) {
    final RealDistribution dist = new UniformRealDistribution(
            RandomNumberStream.Util.asCommonsRandomGenerator(rng), lower.doubleValue(), upper.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override//from www  .  j a  v  a  2s .  c om
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:org.jfree.data.xy.IntervalXYDelegate.java

/**
 * Returns the end value of the x-interval for an item within a series.
 *
 * @param series  the series index.//w  w  w .  j  a v a2 s. c  o  m
 * @param item  the item index.
 *
 * @return The end value of the x-interval (possibly <code>null</code>).
 *
 * @see #getEndXValue(int, int)
 */
public Number getEndX(int series, int item) {
    Number endX = null;
    Number x = this.dataset.getX(series, item);
    if (x != null) {
        endX = new Double(x.doubleValue() + ((1.0 - getIntervalPositionFactor()) * getIntervalWidth()));
    }
    return endX;
}

From source file:org.jfree.data.xy.IntervalXYDelegate.java

/**
 * Returns the start value of the x-interval for an item within a series.
 *
 * @param series  the series index./*  w w  w. j a  v a 2s. com*/
 * @param item  the item index.
 *
 * @return The start value of the x-interval (possibly <code>null</code>).
 *
 * @see #getStartXValue(int, int)
 */
public Number getStartX(int series, int item) {
    Number startX = null;
    Number x = this.dataset.getX(series, item);
    if (x != null) {
        startX = new Double(x.doubleValue() - (getIntervalPositionFactor() * getIntervalWidth()));
    }
    return startX;
}