Public Member Functions | |
| def | __init__ |
| def | count |
| def | density |
| def | __str__ |
| def | __and__ |
| def | __or__ |
| def | __sub__ |
| def | protract |
| def | contract |
| def | shift |
A version of the segment class (see ligo.segments) that carries a
count of things. Arithmetic operations update the count by
interpreting the count as a uniform density of things throughout
the interval spanned by the segment. For example, the intersection
of two ratebins is the interval they have in common, and the
intersection's count is given by the sum of the densities of the
two multiplied by the size of the intersection.
The implementation does not enforce the use of numeric values for
boundaries and counts, but is unlikely to behave sensibly unless
numeric values are used. One will also encounter problems with
(semi-)open intervals due to the mean density being 0 for all
finite counts in such intervals, and undefined otherwise.
Negative counts are allowed, and in particular the subtraction
operation can yield a ratebin with a negative count if the density
in the ratebin being subtracted is sufficiently high. If this is a
concern, it is left as an excercise for the calling code to check
for this condition.
Some behaviour has been selected to accomodate the specific needs
of the intended application, and might not be sensible for general
use outside of that application. For example, if the count is None
then the density reported is 0, not None.
Like the segment class from which it is derived, ratebin objects
are immutable: neither the boundaries, nor the count, can be
modified after creation.
Example:
>>> # initialize from two boundary values without count
>>> x = ratebin(0, 10)
>>> x
None@[0,10)
>>> print(x.count)
None
>>> x.density # count of None --> density = 0, not None
0.0
>>> # initialize from two boundary values with count
>>> x = ratebin(0, 10, count = 5)
>>> x
5@[0,10)
>>> x.density
0.5
>>> # intialize from a sequence without count
>>> y = ratebin((5, 15))
>>> y
None@[5,15)
>>> # intialize from a sequence with count
>>> y = ratebin((5, 15), count = 2.5)
>>> y.density
0.25
>>> # initialize from a ratebin without count
>>> ratebin(y)
2.5@[5,15)
>>> # initialize from a ratebin with count
>>> ratebin(y, count = 5)
5@[5,15)
>>> # arithmetic examples
>>> x | y
7.5@[0,15)
>>> x + y
7.5@[0,15)
>>> (x + y).density
0.5
>>> x - y
3.75@[0,5)
>>> (x - y).density
0.75
>>> x & y
3.75@[5,10)
>>> (x & y).density
0.75
>>> x & x
10@[0,10)
>>> x
5@[0,10)
BUGS: comparisons and hash behaviour are inherited from the
segment class, specifically this means the count attribute is
ignored for the purpose of comparisons. For example, a set will
believe a ratebin object is already in the set if its boundaries
match those of a ratebin in the set, regardless of what their
counts are. A dictionary will do key look-up using the ratebin
boundaries, only.
Example:
>>> x = ratebin(0, 10, count = 5)
>>> s = set([x])
>>> y = ratebin(0, 10, count = 10)
>>> y in s
True
>>> y == x
True
>>> x
5@[0,10)
>>> y
10@[0,10)
>>> # x and y compare as equal, so d gets only one entry
>>> d = {x: "a", y: "b"}
>>> d
{5@[0,10): 'b'}
Definition at line 50 of file trigger_rate.py.
1.8.5