Add smoother checks to Kalman unit tests

time-shift
Johannes Pfeifer 2016-06-16 15:54:00 +02:00 committed by Stéphane Adjemian (Hermes)
parent 7c96e22985
commit 69c5575e19
4 changed files with 111 additions and 3 deletions

View File

@ -123,19 +123,46 @@ fval_algo_0=oo_.likelihood_at_initial_parameters;
options_.lik_init=1;
estimation(kalman_algo=1,mode_file=fs2000_corr_ME_mode,mode_compute=0,order=1,datafile='../../fs2000/fsdat_simul',smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_1=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,1)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,1)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,1)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=3,mode_file=fs2000_corr_ME_mode,mode_compute=0,order=1,datafile='../../fs2000/fsdat_simul',smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_3=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,3)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,3)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,3)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse Multivariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=2,mode_file=fs2000_corr_ME_mode,mode_compute=0,datafile='../../fs2000/fsdat_simul',smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_2=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,2)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,2)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,2)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=4,mode_file=fs2000_corr_ME_mode,mode_compute=0,datafile='../../fs2000/fsdat_simul',smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_4=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,4)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,4)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,4)=cell2mat(struct2cell(oo_.SmoothedVariables));
if max(max(abs(SmoothedMeasurementErrors-repmat(SmoothedMeasurementErrors(:,:,1),1,1,4))))>1e-8
error('SmoothedMeasurementErrors do not match')
end
if max(max(abs(SmoothedShocks-repmat(SmoothedShocks(:,:,1),1,1,4))))>1e-8
error('SmoothedShocks do not match')
end
if max(max(abs(SmoothedVariables-repmat(SmoothedVariables(:,:,1),1,1,4))))>1e-8
error('SmoothedVariables do not match')
end
if max(abs([fval_algo_2,fval_algo_3,fval_algo_4]-fval_algo_1))>1e-6
error('Likelihoods do not match')
end
end

View File

@ -123,18 +123,45 @@ fval_algo_0=oo_.likelihood_at_initial_parameters;
options_.lik_init=1;
estimation(kalman_algo=1,mode_file=fs2000_corr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_corr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_1=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,1)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,1)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,1)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=3,mode_file=fs2000_corr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_corr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_3=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,3)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,3)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,3)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse Multivariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=2,mode_file=fs2000_corr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_corr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_2=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,2)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,2)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,2)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=4,mode_file=fs2000_corr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_corr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_4=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,4)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,4)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,4)=cell2mat(struct2cell(oo_.SmoothedVariables));
if max(max(abs(SmoothedMeasurementErrors-repmat(SmoothedMeasurementErrors(:,:,1),1,1,4))))>1e-8
error('SmoothedMeasurementErrors do not match')
end
if max(max(abs(SmoothedShocks-repmat(SmoothedShocks(:,:,1),1,1,4))))>1e-8
error('SmoothedShocks do not match')
end
if max(max(abs(SmoothedVariables-repmat(SmoothedVariables(:,:,1),1,1,4))))>1e-8
error('SmoothedVariables do not match')
end
if max(abs([fval_algo_2,fval_algo_3,fval_algo_4]-fval_algo_1))>1e-6
error('Likelihoods do not match')

View File

@ -137,19 +137,47 @@ fval_algo_0=oo_.likelihood_at_initial_parameters;
options_.lik_init=1;
estimation(kalman_algo=1,mode_file=fs2000_uncorr_ME_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_1=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,1)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,1)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,1)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=3,mode_file=fs2000_uncorr_ME_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_3=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,3)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,3)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,3)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse Multivariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=2,mode_file=fs2000_uncorr_ME_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_2=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,2)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,2)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,2)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=4,mode_file=fs2000_uncorr_ME_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_4=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,4)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,4)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,4)=cell2mat(struct2cell(oo_.SmoothedVariables));
if max(abs([fval_algo_2,fval_algo_3,fval_algo_4]-fval_algo_1))>1e-6
if max(max(abs(SmoothedMeasurementErrors-repmat(SmoothedMeasurementErrors(:,:,1),1,1,4))))>1e-8
error('SmoothedMeasurementErrors do not match')
end
if max(max(abs(SmoothedShocks-repmat(SmoothedShocks(:,:,1),1,1,4))))>1e-8
error('SmoothedShocks do not match')
end
if max(max(abs(SmoothedVariables-repmat(SmoothedVariables(:,:,1),1,1,4))))>1e-8
error('SmoothedVariables do not match')
end
if max(abs([fval_algo_1 fval_algo_2,fval_algo_3,fval_algo_4]-fval_algo_1))>1e-6
error('Likelihoods do not match')
end
end

View File

@ -120,18 +120,44 @@ fval_algo_0=oo_.likelihood_at_initial_parameters;
options_.lik_init=1;
estimation(kalman_algo=1,mode_file=fs2000_uncorr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_1=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,1)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,1)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,1)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=3,mode_file=fs2000_uncorr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_3=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,3)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,3)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,3)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse Multivariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=2,mode_file=fs2000_uncorr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_2=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,2)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,2)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,2)=cell2mat(struct2cell(oo_.SmoothedVariables));
%%Diffuse univariate Kalman Filter
options_.lik_init=1;
estimation(kalman_algo=4,mode_file=fs2000_uncorr_ME_missing_mode,mode_compute=0,order=1,datafile=fsdat_simul_uncorr_ME_missing,smoother,filter_decomposition,forecast = 8,filtered_vars,filter_step_ahead=[1,3],irf=20) m P c e W R k d y gy_obs;
fval_algo_4=oo_.likelihood_at_initial_parameters;
SmoothedMeasurementErrors(:,:,4)=cell2mat(struct2cell(oo_.SmoothedMeasurementErrors));
SmoothedShocks(:,:,4)=cell2mat(struct2cell(oo_.SmoothedShocks));
SmoothedVariables(:,:,4)=cell2mat(struct2cell(oo_.SmoothedVariables));
if max(max(abs(SmoothedMeasurementErrors-repmat(SmoothedMeasurementErrors(:,:,1),1,1,4))))>1e-8
error('SmoothedMeasurementErrors do not match')
end
if max(max(abs(SmoothedShocks-repmat(SmoothedShocks(:,:,1),1,1,4))))>1e-8
error('SmoothedShocks do not match')
end
if max(max(abs(SmoothedVariables-repmat(SmoothedVariables(:,:,1),1,1,4))))>1e-8
error('SmoothedVariables do not match')
end
if max(abs([fval_algo_2,fval_algo_3,fval_algo_4]-fval_algo_1))>1e-6
error('Likelihoods do not match')