指数平滑法,就可以理解成一种变种的加权移动平均法吧
α越大,表明最近的数据所占的权重就越大
一次指数平滑法
例题
clc,clearyt = [50 52 47 51 49 48 51 40 48 52 51 59]'; % 列向量n = length(yt);alpha = [0.2 0.5 0.8];m = length(alpha);yhat(1, [1:m]) = (yt(1) + yt(2))/2;for i = 2:nyhat(i, :) = alpha * yt(i - 1) + (1 - alpha) .* yhat(i-1, :);endyhaterr = sqrt(mean((repmat(yt, 1, m) - yhat).^2)) % 误差yhat1998 = alpha * yt(n) + (1 - alpha).*yhat(n, :) % 预测值
分析:
二次指数平滑法
例题如下
clc,clearformat long gyt = [676 825 774 716 940 1159 1384 1524 1668 1688 1958 2031 2234 2566 2820 3006 3093 3277 3514 3770 4107]';n = length(yt);alpha = 0.3;st1(1) = yt(1);st2(1) = yt(1);for i = 2:nst1(i) = alpha * yt(i) + (1 - alpha) * st1(i - 1);st2(i) = alpha * st1(i) + (1 - alpha) * st2(i - 1);endst1'st2'at = 2 * st1 - st2;at';bt = alpha/(1 - alpha) * (st1 - st2);bt';yhat = at + bt;yhat'yhat(end) % 1986年预测值pre = at + 2 * bt;pre(end) % 1987年预测值
三次指数平滑法
例题:
clc,clearformat long gyt = [20.04 20.06 25.72 34.61 51.77 55.92 80.65 131.11 148.58 162.67 232.26]';n = length(yt);alpha = 0.3;st0 = mean(yt(1:3));st1(1) = alpha * yt(1) + (1 - alpha) * st0;st2(1) = alpha * st1(1) + (1 - alpha) * st0;st3(1) = alpha * st2(1) + (1 - alpha) * st0; for i = 2:nst1(i) = alpha * yt(i) + (1 - alpha) * st1(i - 1);st2(i) = alpha * st1(i) + (1 - alpha) * st2(i - 1);st3(i) = alpha * st2(i) + (1 - alpha) * st3(i - 1);endst1'st2'st3'at = 3 * st1 - 3 * st2 + st3;bt = 0.5 * alpha/(1 - alpha)^2 * ((6 - 5 * alpha) * st1 - 2 * (5 - 4 * alpha) * st2 + (4 - 3 * alpha) * st3);ct = 0.5 * alpha^2 / (1 - alpha)^2 * (st1 - 2 * st2 + st3);yhat = at + bt + ct;yhat'plot(1:n, yt, 'D', 2:n, yhat(1: end-1), '*')legend('实际值', '预测值', 'Location', 'northwest')xishu = [ct(end), bt(end), at(end)];yhat1990 = polyval(xishu, 2)
本文参考的是司守奎,孙兆亮主编的数学建模算法与应用(第二版)