[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #65245] movfun/movmean: scope for speed up wit
From: |
A.R. Burgers |
Subject: |
[Octave-bug-tracker] [bug #65245] movfun/movmean: scope for speed up with conv |
Date: |
Fri, 9 Feb 2024 09:31:07 -0500 (EST) |
Follow-up Comment #2, bug#65245 (group octave):
No, not so easy to integrate this in the current framework, just wanted to
have a record of the idea for the time being.
movstd and movvar also yield to this approach
np = 100;
nw = 13;
window = ones(1, nw);
a1 = rand(1, np);
a2 = a1 .^2;
a0 = ones(1, np);
count = conv(a0, window, 'same');
count1 = count - 1;
fc = @(x) conv(x, window, 'same');
conv_sum = fc(a1);
conv_mean = fc(a1) ./ count;
conv_var0 = (fc(a2) - conv_mean .* (2 * fc(a1) - nw * conv_mean)) ./ count1;
conv_var1 = (fc(a2) - conv_mean .* (2 * fc(a1) - nw * conv_mean)) ./ count;
conv_std0 = sqrt(conv_var0);
conv_std1 = sqrt(conv_var1);
mov_sum = movsum(a1, nw);
mov_mean = movmean(a1, nw);
mov_var0 = movvar(a1, nw);
mov_var1 = movvar(a1, nw, 1);
mov_std0 = movstd(a1, nw);
mov_std1 = movstd(a1, nw, 1);
assert(all(abs(mov_sum - conv_sum)) < 1.e-10);
assert(all(abs(mov_mean - conv_mean)) < 1.e-10);
assert(all(abs(mov_var0 - conv_var0)) < 1.e-10);
assert(all(abs(mov_var1 - conv_var1)) < 1.e-10);
assert(all(abs(mov_std0 - conv_std0)) < 1.e-10);
assert(all(abs(mov_std1 - conv_std1)) < 1.e-10);
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?65245>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/