Examples of HistogramBin


Examples of org.jfree.data.statistics.HistogramBin

        double lower = minimum;
        double upper;
        List<HistogramBin> binList = new ArrayList<HistogramBin>(bins);
        for (int i = 0; i < bins; i++) {
            HistogramBin bin;
            // make sure bins[bins.length]'s upper boundary ends at maximum
            // to avoid the rounding issue. the bins[0] lower boundary is
            // guaranteed start from min
            if (i == bins - 1) {
                bin = new HistogramBin(lower, maximum);
            } else {
                upper = minimum + (i + 1) * binWidth;
                bin = new HistogramBin(lower, upper);
                lower = upper;
            }
            binList.add(bin);
        }
        // fill the bins
        for (int i = 0; i < values.length; i++) {
            int binIndex = bins - 1;
            if (values[i] < maximum) {
                double fraction = (values[i] - minimum) / (maximum - minimum);
                if (fraction < 0.0) {
                    fraction = 0.0;
                }
                binIndex = (int) (fraction * bins);
                // rounding could result in binIndex being equal to bins
                // which will cause an IndexOutOfBoundsException - see bug
                // report 1553088
                if (binIndex >= bins) {
                    binIndex = bins - 1;
                }
            }
            HistogramBin bin = binList.get(binIndex);
            bin.incrementCount();
        }
        // generic map for each series
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("key", key);
        map.put("bins", binList);
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     */
    public void testEquals() {

        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = new HistogramBin(start, end);

        assertTrue(b1.equals(b2));
        assertTrue(b2.equals(b1));

    }
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     * Confirm that cloning works.
     */
    public void testCloning() {
        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = null;
        try {
            b2 = (HistogramBin) b1.clone();
        }
        catch (CloneNotSupportedException e) {
            System.err.println("Failed to clone.");
        }
        assertTrue(b1 != b2);
        assertTrue(b1.getClass() == b2.getClass());
        assertTrue(b1.equals(b2));
    }
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     */
    public void testSerialization() {

        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = null;

        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(b1);
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     */
    public void testEquals() {

        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = new HistogramBin(start, end);

        assertTrue(b1.equals(b2));
        assertTrue(b2.equals(b1));

    }
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     * Confirm that cloning works.
     */
    public void testCloning() {
        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = null;
        try {
            b2 = (HistogramBin) b1.clone();
        }
        catch (CloneNotSupportedException e) {
            System.err.println("Failed to clone.");
        }
        assertTrue(b1 != b2);
        assertTrue(b1.getClass() == b2.getClass());
        assertTrue(b1.equals(b2));
    }
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

     */
    public void testSerialization() {

        double start = 10.0;
        double end = 20.0;
        HistogramBin b1 = new HistogramBin(start, end);
        HistogramBin b2 = null;

        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(b1);
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

    double lower = minimum;
    double upper;
    List<HistogramBin> binList = new ArrayList<HistogramBin>(numOfBins);
    for (int i = 0; i < numOfBins; i++) {
      HistogramBin bin;
      // make sure bins[bins.length]'s upper boundary ends at maximum
      // to avoid the rounding issue. the bins[0] lower boundary is
      // guaranteed start from min
      if (i == numOfBins - 1) {
        bin = new HistogramBin(lower, maximum);
      } else {
        upper = minimum + (i + 1) * binWidth;
        bin = new HistogramBin(lower, upper);
        lower = upper;
      }
      binList.add(bin);
    }
    // fill the bins
    for (int i = 0; i < values.length; i++) {
      int binIndex = numOfBins - 1;
      if (values[i] < maximum) {
        double fraction = (values[i] - minimum) / (maximum - minimum);
        if (fraction < 0.0) {
          fraction = 0.0;
        }
        binIndex = (int) (fraction * numOfBins);
        if (binIndex >= numOfBins) {
          binIndex = numOfBins - 1;
        }
      }
      HistogramBin bin = (HistogramBin) binList.get(binIndex);
      bin.incrementCount();

    }
    // generic map for each series
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("key", key);
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

   * @throws IndexOutOfBoundsException
   *             if <code>series</code> is outside the specified range.
   */
  public Number getX(int series, int item) {
    List bins = getBins(series);
    HistogramBin bin = (HistogramBin) bins.get(item);
    double x = (bin.getStartBoundary() + bin.getEndBoundary()) / 2.;
    return new Double(x);
  }
View Full Code Here

Examples of org.jfree.data.statistics.HistogramBin

   * @throws IndexOutOfBoundsException
   *             if <code>series</code> is outside the specified range.
   */
  public Number getY(int series, int item) {
    List bins = getBins(series);
    HistogramBin bin = (HistogramBin) bins.get(item);
    double total = getTotal(series);
    double binWidth = getBinWidth(series);

    if (this.type == HistogramType.FREQUENCY) {
      return new Double(bin.getCount());
    } else if (this.type == HistogramType.RELATIVE_FREQUENCY) {
      return new Double(bin.getCount() / total);
    } else if (this.type == HistogramType.SCALE_AREA_TO_1) {
      return new Double(bin.getCount() / (binWidth * total));
    } else { // pretty sure this shouldn't ever happen
      throw new IllegalStateException();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.