Re: Efficient Running Median

2010-01-23 Thread Bearophile
Very nice. I have added a comment at the bottom, using a circular queue instead of a deque may be faster. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient Running Median

2010-01-22 Thread Aahz
In article 497af344-31b5-4d1a-9b1a-c3d82feb3...@j5g2000yqm.googlegroups.com, Raymond Hettinger pyt...@rcn.com wrote: The performance of an IndexableSkiplist is similar to a B+tree but the implementation in pure python is much simpler. Nice! Can you summarize why IndexableSkipList is simpler?

Efficient Running Median

2010-01-15 Thread Raymond Hettinger
I've updated the running median recipe to use a new algorithm with O (log n) updates for a large sliding window traversing a data stream. See http://code.activestate.com/recipes/576930/ The engine is a new collection class called IndexableSkiplist. It is like a regular skiplist as detailed at

Re: efficient running median

2009-10-26 Thread denis
Based on Perreault + Hebert, here's python code for a rather different algorithm: - for quantized e.g. 8-bit data - runs faster for wider windows / slowly changing medians - no heaps, no trees: the only import is numpy, and even that's not essential

Re: efficient running median

2009-10-20 Thread denis
Yet another link: http://en.wikipedia.org/wiki/Median_filter -- Perreault + Hebert, Median Filtering in Constant Time, nice 6-page paper + 400 lines well-documented C code: http://nomis80.org/ctmf.html (for 2d images, dropping to 1d must be possible :) They're also in opencv, which I haven't

Re: efficient running median

2009-10-19 Thread denis
Folks, approximate medians -- would you settle for 49 - 51 % ? -- open up new possibilities, and there's quite a lot of work on that, for huuuge datasets. A class of problems: from a data stream X1 X2 ... you want, every so often, a histogram / quantile summary / distribution estimator such

Re: efficient running median

2009-10-15 Thread Raymond Hettinger
[Janto Dreijer] I found a PDF by Soumya D. Mohanty entitled Efficient Algorithm for computing a Running Median (2003) by Googling. It has code snippets at the end, but it's not going to be a simple cut-and-paste job. It will take some work figuring out the missing parts. See

Re: efficient running median

2009-10-15 Thread Janto Dreijer
On Oct 15, 12:41 pm, Raymond Hettinger pyt...@rcn.com wrote: [Janto Dreijer] I found a PDF by Soumya D. Mohanty entitled Efficient Algorithm for computing a Running Median (2003) by Googling. It has code snippets at the end, but it's not going to be a simple cut-and-paste job. It will

Re: efficient running median

2009-10-14 Thread Hendrik van Rooyen
On Tuesday, 13 October 2009 17:22:55 Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is

Re: efficient running median

2009-10-14 Thread sturlamolden
On 14 Okt, 00:03, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: Obviously to run in O(log n) you must have already built the tree. You don't need a tree. Quickselect is a partial quicksort. But my memory served me badly, quickselect is O(n). --

Re: efficient running median

2009-10-14 Thread Janto Dreijer
On Oct 13, 6:33 pm, Paul Rubin http://phr...@nospam.invalid wrote: Janto Dreijer jan...@gmail.com writes: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). Is that

Re: efficient running median

2009-10-14 Thread Janto Dreijer
On Oct 13, 7:37 pm, Ethan Furman et...@stoneleaf.us wrote: Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the

Re: efficient running median

2009-10-14 Thread Janto Dreijer
On Oct 14, 12:13 am, Paul Rubin http://phr...@nospam.invalid wrote: Janto Dreijer jan...@gmail.com writes: Well, I don't have a lot of theoretical reasoning behind wanting to use a median filter. I have some experience applying it to images with very good results, so that was the first

Re: efficient running median

2009-10-14 Thread Peter Otten
Janto Dreijer wrote: On Oct 13, 6:12 pm, Peter Otten __pete...@web.de wrote: Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive

Re: efficient running median

2009-10-14 Thread Janto Dreijer
On Oct 14, 4:53 pm, Peter Otten __pete...@web.de wrote: Some numbers: 10.197 seconds for running_median_scipy_medfilt 25.043 seconds for running_median_python 13.040 seconds for running_median_python_msort 14.280 seconds for running_median_python_scipy_median 4.024 seconds for

Re: efficient running median

2009-10-14 Thread Ethan Furman
Janto Dreijer wrote: On Oct 13, 7:37 pm, Ethan Furman et...@stoneleaf.us wrote: Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive

efficient running median

2009-10-13 Thread Janto Dreijer
I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is unfortunately too slow as my sliding windows are quite large

Re: efficient running median

2009-10-13 Thread Peter Otten
Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is unfortunately too slow as my

Re: efficient running median

2009-10-13 Thread Dave Angel
Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is unfortunately too slow as my sliding

Re: efficient running median

2009-10-13 Thread Ethan Furman
Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median of a sliding window) is unfortunately too slow as my sliding

Re: efficient running median

2009-10-13 Thread Dale Dalrymple
On Oct 13, 8:22 am, Janto Dreijer jan...@gmail.com wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). ... Any suggestions? For a reference try: Comparison

Re: efficient running median

2009-10-13 Thread Daniel Stutzbach
On Tue, Oct 13, 2009 at 10:22 AM, Janto Dreijer jan...@gmail.com wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). In the past, I've used the following

Re: efficient running median

2009-10-13 Thread Paul Rubin
sturlamolden sturlamol...@yahoo.no writes: The obvious way to compute a running median involves a tree structure so you can quickly insert and delete elements, and find the median. That would be asymtotically O(n log n) but messy to implement. QuickSelect will find the median in O(log n)

Re: efficient running median

2009-10-13 Thread Steven D'Aprano
On Tue, 13 Oct 2009 12:59:47 -0700, Paul Rubin wrote: sturlamolden sturlamol...@yahoo.no writes: The obvious way to compute a running median involves a tree structure so you can quickly insert and delete elements, and find the median. That would be asymtotically O(n log n) but messy to

Re: efficient running median

2009-10-13 Thread Raymond Hettinger
On Oct 13, 11:57 am, sturlamolden sturlamol...@yahoo.no wrote: On 13 Okt, 18:33, Paul Rubin http://phr...@nospam.invalid wrote: The obvious way to compute a running median involves a tree structure so you can quickly insert and delete elements, and find the median. That would be

Re: efficient running median

2009-10-13 Thread Janto Dreijer
On Oct 13, 6:12 pm, Peter Otten __pete...@web.de wrote: Janto Dreijer wrote: I'm looking for code that will calculate the running median of a sequence, efficiently. (I'm trying to subtract the running median from a signal to correct for gradual drift). My naive attempt (taking the median