[SciPy-user] piecewise linear approximation

Robert Kern robert.kern at gmail.com
Tue Feb 5 17:53:56 EST 2008


John Hunter wrote:
> I would like to do a piecewise linear approximation to a time series
> using the constraint that I can use at most N piecewise linear
> segments where the error between the piecewise approximation and the
> original time series in minimized.  N is an input to the algorithm.  I
> suspect this problem is solved somewhere (using scipy!), so am
> wondering if someone can point me to the light.

Not OOB, no. Most algorithms I am aware of (e.g. Douglas-Peucker) are 
constrained by the error rather than the number of segments. You might be able 
to find an algorithm that can be modified to do so in the references here 
(search in the page for "Piecewise Linear Approximation"; the first paper there 
is a good overview of several algorithms):

   http://appsrv.cse.cuhk.edu.hk/~mzhou/time%20series%20reading.htm

One approach would be to use one of these error-limited algorithms and relax the 
error constraint until you only use N or fewer segments.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco



More information about the SciPy-User mailing list