Package peppy :: Package lib :: Module wordwrap :: Class OnlineConcaveMinima
[frames] | no frames]

Class OnlineConcaveMinima


Online concave minimization algorithm of Galil and Park.

OnlineConcaveMinima(Matrix,initial) creates a sequence of pairs
(self.value(j),self.index(j)), where
    self.value(0) = initial,
    self.value(j) = min { Matrix(i,j) | i < j } for j > 0,
and where self.index(j) is the value of j that provides the minimum.
Matrix(i,j) must be concave, in the same sense as for ConcaveMinima.

We never call Matrix(i,j) until value(i) has already been computed,
so that the Matrix function may examine previously computed values.
Calling value(i) for an i that has not yet been computed forces
the sequence to be continued until the desired index is reached.
Calling iter(self) produces a sequence of (value,index) pairs.

Matrix(i,j) should always return a value, rather than raising an
exception, even for j larger than the range we expect to compute.
If j is out of range, a suitable value to return that will not
violate concavity is Matrix(i,j) = -i.  It will not work correctly
to return a flag value such as None for large j, because the ties
formed by the equalities among such flags may violate concavity.

Instance Methods
 
__init__(self, Matrix, initial)
Initialize a OnlineConcaveMinima object.
 
__iter__(self)
Loop through (value,index) pairs.
 
value(self, j)
Return min { Matrix(i,j) | i < j }.
 
index(self, j)
Return argmin { Matrix(i,j) | i < j }.