| 1 |
/* |
| 2 |
* This file compares results from serial and parallel (PCT) Metropolis-Hastings estimations. |
| 3 |
* It checks if the x2 and logpo2 fields in the generated mat files are identical |
| 4 |
* between serial and parallel runs for different random seeds that were set |
| 5 |
* prior to the estimation command. |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright © 2026 Dynare Team |
| 10 |
* |
| 11 |
* This file is part of Dynare. |
| 12 |
* |
| 13 |
* Dynare is free software: you can redistribute it and/or modify |
| 14 |
* it under the terms of the GNU General Public License as published by |
| 15 |
* the Free Software Foundation, either version 3 of the License, or |
| 16 |
* (at your option) any later version. |
| 17 |
* |
| 18 |
* Dynare is distributed in the hope that it will be useful, |
| 19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
* GNU General Public License for more details. |
| 22 |
* |
| 23 |
* You should have received a copy of the GNU General Public License |
| 24 |
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. |
| 25 |
*/ |
| 26 |
|
| 27 |
@#include "folder/endovars.mod" // model is irrelevant |
| 28 |
@#include "_ls2003.inc" // as we are running only MATLAB code below |
| 29 |
|
| 30 |
@#define TESTS = ["start", "123", "default", "noseed"] |
| 31 |
|
| 32 |
if ~isoctave && matlab.internal.parallel.isPCTInstalled |
| 33 |
|
| 34 |
fprintf('\nTESTS BETWEEN SERIAL AND PCT ESTIMATIONS DONE IN OTHER MOD FILES:\n'); |
| 35 |
|
| 36 |
@#for t in TESTS |
| 37 |
serial_1 = load(['serial_mhblocks_1_@{t}/metropolis/serial_mhblocks_1_mh1_blck1.mat']); |
| 38 |
pct_1 = load(['pct_mhblocks_1_@{t}/metropolis/pct_mhblocks_1_mh1_blck1.mat']); |
| 39 |
|
| 40 |
if isequaln(serial_1.x2, pct_1.x2) && isequaln(serial_1.logpo2, pct_1.logpo2) |
| 41 |
fprintf('✅ single blocks in serial and pct are equal for seed set to @{t}!\n'); |
| 42 |
else |
| 43 |
error('❌ single blocks in serial and pct are not equal for seed set to @{t}!') |
| 44 |
end |
| 45 |
@#endfor |
| 46 |
|
| 47 |
@#for t in TESTS |
| 48 |
serial_1 = load(['serial_mhblocks_2_@{t}/metropolis/serial_mhblocks_2_mh1_blck1.mat']); |
| 49 |
serial_2 = load(['serial_mhblocks_2_@{t}/metropolis/serial_mhblocks_2_mh1_blck2.mat']); |
| 50 |
pct_1 = load(['pct_mhblocks_2_@{t}/metropolis/pct_mhblocks_2_mh1_blck1.mat']); |
| 51 |
pct_2 = load(['pct_mhblocks_2_@{t}/metropolis/pct_mhblocks_2_mh1_blck2.mat']); |
| 52 |
|
| 53 |
if isequaln(serial_1.x2, pct_1.x2) && isequaln(serial_1.logpo2, pct_1.logpo2) |
| 54 |
fprintf('✅ first blocks in serial and pct are equal for seed set to @{t}!\n'); |
| 55 |
else |
| 56 |
error('❌ first blocks in serial and pct are not equal for seed set to @{t}!') |
| 57 |
end |
| 58 |
if isequaln(serial_2.x2, pct_2.x2) && isequaln(serial_2.logpo2, pct_2.logpo2) |
| 59 |
fprintf('✅ second blocks in serial and pct are equal for seed set to @{t}!\n'); |
| 60 |
else |
| 61 |
error('❌ second blocks in serial and pct are not equal for seed set to @{t}!') |
| 62 |
end |
| 63 |
@#endfor |
| 64 |
fprintf('\n'); |
| 65 |
|
| 66 |
end |