Running mean is simple — just use convolution. I do things like this: $runningmean = $source->convolveND( ones($how_wide)/$how_wide, {bound=>’c’} );
Running median is harder since it’s not a linear operation and the median must be computed at each point. Since, like most interpreted vectorized languages, PDL is pessimal for memory access, you can do *much* better wth a C code. I don’t know of a 1-D running median operator in the distribution itself. However, there’s a 2-D running median, which you could use: $runningmedian = $source->(:,*1)->med2d(ones($how_wide,1))->(:,(0))->sever; That uses stupid index tricks to treat your 1-D array as a 2-D array, by giving it a dummy dimension in position 1. It’s not as efficient as a PP (compiled) running- median operator could be, but it’s far more efficient than the threading solution (since it will make good use of CPU cache unless $how_wide is enormous). Cheers, Craig > On Mar 1, 2016, at 9:06 AM, Pakhomov Yury <pakho...@inasan.ru> wrote: > > Hello all! > > How to write PDL efficient code for computing the moving average or > moving median? > > For example, I want to use the median filter width of 33 pixels for data: > > $x=sequence(1000); > $y=sin($x/10)+random($x)/10; > > For data of little size I can create new piddle size of (33,nelem($y)) > where each row contains a portion of data size of 33 which then I > include in "medover": > > $med=&medianPDL($y,33); > > sub medianPDL{ > my $pdl=shift; > my $win=shift; > my $tmp=zeroes($win,nelem($pdl)); > my $inds=yvals($tmp)-int($win/2)+xvals($tmp); > my $a=$inds->minimum; > $a->where($a>=0).=0; > $inds-=$a->dummy(0,$win); > my $b=$inds->maximum-$tmp->getdim(1)+1; > $b->where($b<0).=0; > $inds-=$b->dummy(0,$win); > > return $pdl->index($inds)->medover; > } > > ________________________________ > > May be exists a more efficient way to compute the moving average or > moving median? > > Yury > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > pdl-general mailing list > pdl-general@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pdl-general > ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 _______________________________________________ pdl-general mailing list pdl-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pdl-general