From db0e417da028ae2d30d59bf21303d74f762c6165 Mon Sep 17 00:00:00 2001 From: schristophe Date: Wed, 10 Jun 2026 19:58:35 +0200 Subject: [PATCH] Optimize calculation of 2-sample mean in MF_steps_ahead Previous implementation uses a 2nd order linear recurrence relation to compute the 2-sample mean predictor at a given time index. It is replaced by the closed-form solution that is faster to compute. --- Operations/MF_steps_ahead.m | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Operations/MF_steps_ahead.m b/Operations/MF_steps_ahead.m index 3a62355f9..7c8bd2102 100644 --- a/Operations/MF_steps_ahead.m +++ b/Operations/MF_steps_ahead.m @@ -165,15 +165,8 @@ % (3) *** Sliding mean 2 *** % A sliding mean of length 2 - sm2p = zeros(N-i-1,1); - for j = 1:N-i-1 - seeds = yy(j:j+1); - for k = 1:i % average with itself this many times - p = mean(seeds); - seeds = [seeds(2),p]; - end - sm2p(j) = p; - end + weights = [1 + (-1)^(i+1)/2^i; 2 + (-1)^i/2^i] ./ 3; + sm2p = [yy(1:N-i-1), yy(2:N-i)] * weights; mres = yy(i+2:end) - sm2p; sm2.rmserrs(i) = sqrt(mean(mres.^2));