uk.ac.starlink.ttools.plot2.layer
Class BinBag

java.lang.Object
  extended by uk.ac.starlink.ttools.plot2.layer.BinBag

public class BinBag
extends Object

Data model for a one-dimensional histogram. Linear and logarithmic axis scaling are supported.

Since:
8 Jan 2014
Author:
Mark Taylor

Nested Class Summary
static interface BinBag.Bin
          Describes the extent of a bin and the value it contains.
 
Constructor Summary
BinBag(boolean log, double binWidth, double binPhase, double point)
          Constructor.
 
Method Summary
 void addToBin(double point, double inc)
          Adds a value to the bin in which a given point falls.
 Iterator<double[]> barIterator(double lo, double hi)
          Iterates over all the bins defined by this bin bag in a given data interval.
 Iterator<BinBag.Bin> binIterator(boolean cumulative, Normalisation norm)
          Returns a sorted iterator over all bins with non-zero values.
 double getBinWidth()
          Returns the bin width used by this histogram model.
 boolean matches(boolean log, double binWidth, double binPhase)
          Indicates whether the bin boundaries used by this object are the same as a given bin set specification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinBag

public BinBag(boolean log,
              double binWidth,
              double binPhase,
              double point)
Constructor. Notional bin boundaries are for log=false:
   binWidth*(0+binPhase), binWidth*(1+binPhase), ...
 
and for log=true:
   binWidth**(0+binPhase), binWidth**(1+binPhase), ...
 

The point parameter is used internally to determine the zero point of the bins. In principle this should make no difference to behaviour, but in case that the data is situated a very long way from 1, setting it close to the actual data point locations may avoid rounding errors.

Parameters:
log - false for linear axis scaling, true for logarithmic
binWidth - width of each bin; this is additive for linear and multiplicative for logarithmic scaling
binPhase - determines sub-bin boundary shifts along axis, normally in range 0..1
point - representative point on axis near which bins are situated
Method Detail

addToBin

public void addToBin(double point,
                     double inc)
Adds a value to the bin in which a given point falls. Checking is performed; if the value is unsuitable (for instance infinite) it will be ignored.

Parameters:
point - axis coordinate
inc - value to accumulate onto bin value

binIterator

public Iterator<BinBag.Bin> binIterator(boolean cumulative,
                                        Normalisation norm)
Returns a sorted iterator over all bins with non-zero values.

Parameters:
cumulative - true for bins of a cumulative histogram
norm - normalisation mode
Returns:
sorted iterator over bins

barIterator

public Iterator<double[]> barIterator(double lo,
                                      double hi)
Iterates over all the bins defined by this bin bag in a given data interval. The contents of each bin, if any, are irrelevant to this operation.

Parameters:
lo - lower bound of interest
hi - upper bound of interest
Returns:
iterator in sequence over 2-element (low,high) bin range arrays that together cover the supplied (lo,hi) range

getBinWidth

public double getBinWidth()
Returns the bin width used by this histogram model. It's additive for linear and multiplicative for logarithmic.

Returns:
bin width

matches

public boolean matches(boolean log,
                       double binWidth,
                       double binPhase)
Indicates whether the bin boundaries used by this object are the same as a given bin set specification.

Parameters:
log - false for linear scaling, true for logarithmic
binWidth - width of each bin; this is additive for linear and multiplicative for logarithmic scaling
binPhase - determines sub-bin boundary shifts along axis normally in range 0..1
Returns:
true iff a BinBag constructed using the given parameters would have the same bin boundaries as this one


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.