function [w_opt,S_n,beta_hats,et,MSE,omega_grid,MSE_omega] = locally_constant_indicator_model_optimum(Z,s,omega_grid) % LOCALLY_CONSTANT_INDICATOR_MODEL_OPTIUM - Find the optimum relaxation coefficient to use with a locally constant indicator model % % Inputs: % Z : the original sequence % s : the number of seasons % 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 % beta_hats : the optimal estimated beta's at each timestep % 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<2 ) % a reasonable default for the grid of omegas to search over omega_grid = linspace(0.1,0.99,100); end MSE_omega = zeros(1,length(omega_grid)); for ii=1:length(omega_grid), [ Ys, beta_hats, et, MSE_omega(ii) ] = locally_constant_indicator_model( Z, s, omega_grid(ii) ); end [min_value,min_indx] = min( MSE_omega ); w_opt = omega_grid(min_indx); [ S_n, beta_hats, et, MSE ] = locally_constant_indicator_model( Z, s, w_opt );