Thanks George
One of the first thing that we need to establish is whether identical basic matrix operations take much longer in the C++ implementation than in Matlab and, if that it is the case, why.
- Indeed, and as a significant part of the overall parcel of updating P,
one needs to invert the updated F too :
100000 loops of small model KF 4x4 F matrix inversion: iF = inv(F); Fmx_inv_time = 2.2530
100000 loops of the corresponding core KF 8x8 P matrix update: P1 = T*(P-K*P(mf,:))*transpose(T)+QQ; Pupdt_time = 3.4450
(and also, 100000 loops of the preceding K = P(:,mf)*iF; Kupdt_time = 0.5910)
How do these operations compare with Matlab on your machine?
The convergence of P exploited in Matlab Dynare KFs (which does not require further update of P and K and inversion of F ), can improve greatly performance of KF.
e.g.: running Matlab Dynare KF with 57x57 system matrix in 1000 loop 1000 of usual matlabKF_time = 337.1650
and then using P recursively in the loop with a modified kalman_filter.m which returns P too (therefore, utilising P convergence and avoiding its update for the most of the remaining 999 loops): 1000 of recursive: Matlab_rec_KF_time = 11.7060
- And, although the convergence of P in Matlab KF did not take place for
the large sw_euro model which had total run much closer to the C++KF (see 3 below), as today's check show, the convergence did however take place very early in the Matlab KF running the small model I initially tested (at step t=3!!!) so it certainly did affect and, judging from the above results, rather greatly contribute to the very much faster KF loops we experienced running Matlab KF versus C++ KF in the initial tests with the same small model (C++ KF does yet not take advantage of convergence and the comparative results were even)!!!
OK, we forget the first comparison on the small model, because C++ and Matlab didn't use the same algorithm (no convergence monitorinig in C++).
Matlab is still faster by 45% on the medium size model. We should focus on explaining this difference and we don't need to bring monitoring the convegence of the filter for this particular example.
Could you please upload on SVN the code that you use for profiling?
Best
Michel
Best regards
George