| 1 |
debug = false; |
| 2 |
|
| 3 |
if ~debug |
| 4 |
source_dir = getenv('source_root'); |
| 5 |
addpath([source_dir filesep 'matlab']); |
| 6 |
dynare_config; |
| 7 |
addpath([source_dir filesep 'tests' filesep 'kalman' filesep 'likelihood']); |
| 8 |
end |
| 9 |
|
| 10 |
testFailed = 0; |
| 11 |
|
| 12 |
if ~debug |
| 13 |
skipline() |
| 14 |
disp('*** TESTING: test_kalman_mex.m ***'); |
| 15 |
end |
| 16 |
|
| 17 |
t0 = clock; |
| 18 |
|
| 19 |
dprintf('Test 1: No measurement error') |
| 20 |
|
| 21 |
Experience.Number0fObservedVariables = 10; |
| 22 |
Experience.SizeOfTheStateVector = 100; |
| 23 |
Experience.NumberOfStructuralShocks = 12; |
| 24 |
Experience.MeasurementErrors = 0; |
| 25 |
Experience.NumberOfPeriods = 300; |
| 26 |
Experience.Seed = 1; |
| 27 |
Experience.NumberOfSimulations = 100; |
| 28 |
Experience.Scale = 1; |
| 29 |
|
| 30 |
try |
| 31 |
flag = compare_kalman_mex(Experience); |
| 32 |
if (flag) |
| 33 |
testFailed = testFailed+1; |
| 34 |
if debug |
| 35 |
dprintf('MEX and MATLAB Kalman filters lead to different results') |
| 36 |
end |
| 37 |
end |
| 38 |
catch |
| 39 |
testFailed = testFailed+1; |
| 40 |
if debug |
| 41 |
dprintf('Comparison between MEX and MATLAB Kalman filters failed') |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
dprintf('Test 2: measurement error with diagonal variance-covariance matrix') |
| 46 |
Experience.MeasurementErrors = 1; |
| 47 |
|
| 48 |
try |
| 49 |
flag = compare_kalman_mex(Experience); |
| 50 |
if (flag) |
| 51 |
testFailed = testFailed+1; |
| 52 |
if debug |
| 53 |
dprintf('MEX and MATLAB Kalman filters lead to different results') |
| 54 |
end |
| 55 |
end |
| 56 |
catch |
| 57 |
testFailed = testFailed+1; |
| 58 |
if debug |
| 59 |
dprintf('Comparison between MEX and MATLAB Kalman filters failed') |
| 60 |
end |
| 61 |
end |
| 62 |
|
| 63 |
dprintf('Test 3: measurement error with general variance-covariance matrix') |
| 64 |
Experience.MeasurementErrors = 2; |
| 65 |
|
| 66 |
try |
| 67 |
flag = compare_kalman_mex(Experience); |
| 68 |
if (flag) |
| 69 |
testFailed = testFailed+1; |
| 70 |
if debug |
| 71 |
dprintf('MEX and MATLAB Kalman filters lead to different results') |
| 72 |
end |
| 73 |
end |
| 74 |
catch |
| 75 |
testFailed = testFailed+1; |
| 76 |
if debug |
| 77 |
dprintf('Comparison between MEX and MATLAB Kalman filters failed') |
| 78 |
end |
| 79 |
end |
| 80 |
|
| 81 |
|
| 82 |
if ~debug |
| 83 |
t1 = clock; |
| 84 |
fprintf('\n*** Elapsed time (in seconds): %.1f\n\n', etime(t1, t0)); |
| 85 |
quit(testFailed > 0) |
| 86 |
end |