> On 12 Apr 2020, at 13:53, Cédrick Béler <cdric...@gmail.com> wrote:
> 
> Beautiful ^^

I also like it.

But why the single letter variable names ? Why not:

SequenceableCollection>>#runningMeans: width
  | means sum index |
  means := Array new: self size - width + 1.
  sum := 0.
  1 to: width do: [ :each |
    sum := sum + (self at: each) ].
  index := 1.
  means at: index put: sum / width.
  width + 1 to: self size do: [ :each |
    sum := sum - (self at: index) + (self at: each).
    index := index + 1. 
    means at: index put: sum / width ].
  ^ means

A good comment, a correct initial bounds check and unit tests are also needed.

> I would vote for inclusion in the base image ?
> With your explanation as comments. 
> 
> I’ll play with it. 
> 
> Thanks 
> Cedrick
> 
>> Le 12 avr. 2020 à 12:19, Richard O'Keefe <rao...@gmail.com> a écrit :
>> 
>> 
>> I have coded and benchmarked 8 different running mean algorithms.
>> In the presence of inexact numbers it is not as accurate as
>> redoing the sums, but it's pretty close, and it's fast.
>> If "width" is not an integer or is out of range, an error
>> will be reported by #new: or #at:[put:].  It's based on Welford's
>> stable update.
>> 
>> Of course this approach does NOT work for trimmed or Winsorised
>> means or for medians or any kind of robust estimate of location.
>> 
>> SequenceableCollection
>>  methods for: 'summarising'
>>    runningMeans: width
>>      |a m d|
>>      a := Array new: self size - width + 1.
>>      m := 0.
>>      1 to: width do: [:i |
>>        m := (self at: i) + m].
>>      m := m / width.  
>>      d := 1.
>>      a at: d put: m.
>>      width + 1 to: self size do: [:i |
>>        m := ((self at: i) - (self at: d)) / width + m.
>>        d := d + 1. 
>>        a at: d put: m].
>>      ^a
>> 
>> 
>> 
>> 
>> 
> 


Reply via email to