gstlal-inspiral  1.9.2
 All Classes Namespaces Files Functions
Public Member Functions | Public Attributes | List of all members
stats.horizonhistory.NearestLeafTree Class Reference
Inheritance diagram for stats.horizonhistory.NearestLeafTree:
[legend]
Collaboration diagram for stats.horizonhistory.NearestLeafTree:
[legend]

Public Member Functions

def __init__
 
def __setitem__
 
def __getitem__
 
def __delitem__
 
def __bool__
 
def __iadd__
 
def keys
 
def values
 
def items
 
def min
 
def minkey
 
def max
 
def maxkey
 
def __contains__
 
def __len__
 
def __repr__
 
def functional_integral
 
def weighted_mean
 
def from_xml
 
def to_xml
 

Public Attributes

 tree
 

Detailed Description

A simple binary tree in which look-ups return the value of the
closest leaf.  Only float objects are supported for the keys and
values.  Look-ups raise KeyError if the tree is empty.

Example:

>>> x = NearestLeafTree()
>>> bool(x)
False
>>> x[100.0] = 120.
>>> bool(x)
True
>>> x[104.0] = 100.
>>> x[102.0] = 110.
>>> x[90.]
120.0
>>> x[100.999]
120.0
>>> x[101.001]
110.0
>>> x[200.]
100.0
>>> del x[104]
>>> x[200.]
110.0
>>> x.keys()
[100.0, 102.0]
>>> 102 in x
True
>>> 103 in x
False
>>> import sys
>>> x.to_xml(u"H1").write(sys.stdout) # doctest: +NORMALIZE_WHITESPACE
<Array Type="real_8" Name="H1:nearestleaftree:array">
    <Dim>2</Dim>
    <Dim>2</Dim>
    <Stream Type="Local" Delimiter=" ">
        100 102
        120 110
    </Stream>
</Array>

Definition at line 80 of file horizonhistory.py.

Constructor & Destructor Documentation

def stats.horizonhistory.NearestLeafTree.__init__ (   self,
  items = () 
)
Initialize a NearestLeafTree.

Example:

>>> x = NearestLeafTree()
>>> x = NearestLeafTree([(100., 120.), (104., 100.), (102., 110.)])
>>> y = {100.: 120., 104.: 100., 102.: 100.}
>>> x = NearestLeafTree(y.items())

Definition at line 124 of file horizonhistory.py.

Member Function Documentation

def stats.horizonhistory.NearestLeafTree.__bool__ (   self)
True if the tree is not empty, False otherwise.

Definition at line 243 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.__contains__ (   self,
  x 
)
True if a key in self equals x, False otherwise.

Definition at line 298 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.__delitem__ (   self,
  x 
)
Example:

>>> x = NearestLeafTree([(100., 0.), (150., 1.), (200., 0.)])
>>> del x[150.]
>>> x
NearestLeafTree([(100, 0), (200, 0)])
>>> del x[190.]
Traceback (most recent call last):
    ...
IndexError: 190.0
>>> del x[:]
>>> x
NearestLeafTree([])

Definition at line 200 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.__iadd__ (   self,
  other 
)
For every (key, value) pair in other, assign self[key]=value.

Definition at line 249 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.__len__ (   self)
The number of (key, value) pairs in self.

Definition at line 307 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.__setitem__ (   self,
  x,
  val 
)
Example:

>>> x = NearestLeafTree()
>>> x[100.:200.] = 0.
>>> x[150.] = 1.
>>> x
NearestLeafTree([(100, 0), (150, 1), (200, 0)])
>>> x[210:] = 5.
>>> x[:90] = 5.
>>> x
NearestLeafTree([(90, 5), (100, 0), (150, 1), (200, 0), (210, 5)])

Definition at line 141 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.functional_integral (   self,
  lohi,
  w = lambda f: f 
)
Given the function f(x) = self[x], compute

\int_{lo}^{hi} w(f(x)) dx

The arguments are the lo and hi bounds and the functional
w(f).  The default functional is w(f) = f.

Example:

>>> x = NearestLeafTree([(100., 0.), (150., 2.), (200., 0.)])
>>> x.functional_integral((130., 170.))
80.0
>>> x.functional_integral((100., 150.))
50.0
>>> x.functional_integral((300., 500.))
0.0
>>> x.functional_integral((100., 150.), lambda f: f**3)
200.0

Definition at line 316 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.max (   self)
Return the maximum value stored in the tree.  This is O(n).

Definition at line 282 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.maxkey (   self)
Return the maximum key stored in the tree.  This is O(1).

Definition at line 290 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.min (   self)
Return the minimum value stored in the tree.  This is O(n).

Definition at line 266 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.minkey (   self)
Return the minimum key stored in the tree.  This is O(1).

Definition at line 274 of file horizonhistory.py.

def stats.horizonhistory.NearestLeafTree.weighted_mean (   self,
  lohi,
  weight = lambda y: 1. 
)
Given the function f(x) = self[x], compute

\int_{lo}^{hi} w(f(x)) f(x) dx
------------------------------
   \int_{lo}^{hi} w(f(x)) dx

where w(y) is a weighting function.  The default weight
function is w(y) = 1.

If the numerator is identically 0 and the denominator is
also 0 then a value of 0 is returned rather than raising a
divide-by-0 error.

Example:

>>> x = NearestLeafTree([(100., 0.), (150., 2.), (200., 0.)])
>>> x.weighted_mean((130., 170.))
2.0
>>> x.weighted_mean((100., 150.))
1.0
>>> x.weighted_mean((300., 500.))
0.0
>>> x.weighted_mean((100., 150.), lambda x: x**3)
2.0

Definition at line 376 of file horizonhistory.py.


The documentation for this class was generated from the following file: