function [w_opt,S_n,et,MSE,omega_grid,MSE_omega] = simple_exp_smoothing_optimum(Z,S_0,omega_grid) % SIMPLE_EXP_SMOOTHING_OPTIUM - Find the optimum relaxation coefficient to use with simple exponential smoothing % % Inputs: % Z : the original sequence % S_0 : the initial smooth value (optional) % omega_grid : the grid of possible omega values to search over (optional) % % Outputs: % w_opt : the optimal value of omega the relaxation coefficient % S_n : the optimal smoothed sequence of z_n % et : the optimal one step-ahead residuals % MSE : the optimal mean square error % omega_grid : the grid of omegas searched over (will be the same if passed in) % MSE_omega : the in-sample mean square error for each value of omega in omega_grid % % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- if( nargin<3 ) % a reasonable default for the grid of omegas to search over omega_grid = linspace(0.1,0.99,100); end if( nargin<2 ) % a reasonable default for the initial value of the smooth S_0 = median(Z); end MSE_omega = zeros(1,length(omega_grid)); for ii=1:length(omega_grid), [ Ys, et, MSE_omega(ii) ] = simple_exp_smoothing( Z, omega_grid(ii), S_0 ); end [min_value,min_indx] = min( MSE_omega ); w_opt = omega_grid(min_indx); [ S_n, et, MSE ] = simple_exp_smoothing( Z, w_opt, S_0 );