From 1c5c7f3fbf13c5d7dfd8cfebf6255b102ad0bace Mon Sep 17 00:00:00 2001 From: George Perendia Date: Fri, 7 May 2010 16:55:44 +0100 Subject: [PATCH 1/4] Estimation DLL: adding LapackBindings.hh --- .../estimation/libmat/LapackBindings.hh | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 mex/sources/estimation/libmat/LapackBindings.hh diff --git a/mex/sources/estimation/libmat/LapackBindings.hh b/mex/sources/estimation/libmat/LapackBindings.hh new file mode 100644 index 000000000..f9a0f465b --- /dev/null +++ b/mex/sources/estimation/libmat/LapackBindings.hh @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 Dynare Team + * + * This file is part of Dynare. + * + * Dynare is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Dynare is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Dynare. If not, see . + */ + +#ifndef _LAPACK_BINDINGS_HH +#define _LAPACK_BINDINGS_HH + +#include + +#include "Vector.hh" +#include "Matrix.hh" + +namespace lapack +{ + // calc Cholesky Decomposition (Mat A, char "U"pper/"L"ower) + template + inline int + choleskyDecomp(Mat A, const char *UL) + { + assert(A.getCols() == A.getRows()); + lapack_int lpinfo = 0; + lapack_int lrows = A.getRows(); + lapack_int ldl = A.getLd(); + dpotrf(UL, &lrows, A.getData(), &ldl, &lpinfo); + int info = (int) lpinfo; + return info; + } + + + /** + * "DSTEQR computes all eigenvalues and, optionally, eigenvectors of a sym- + * metric tridiagonal matrix using the implicit QL or QR method. The eigen- + * vectors of a full or band symmetric matrix can also be found if DSYTRD or + * DSPTRD or DSBTRD has been used to reduce this matrix to tridiagonal form." + */ + + +} // End of namespace + +#endif From 775a1f64719c8210415b86e0cd070167a38cd499 Mon Sep 17 00:00:00 2001 From: George Perendia Date: Fri, 7 May 2010 17:09:51 +0100 Subject: [PATCH 2/4] Estimation DLL: updating test function --- mex/sources/estimation/tests/testInitKalman.cc | 4 ++-- mex/sources/estimation/tests/testKalman.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mex/sources/estimation/tests/testInitKalman.cc b/mex/sources/estimation/tests/testInitKalman.cc index c261f9b71..0f34007b1 100644 --- a/mex/sources/estimation/tests/testInitKalman.cc +++ b/mex/sources/estimation/tests/testInitKalman.cc @@ -128,7 +128,7 @@ main(int argc, char **argv) double lyapunov_tol = 1e-16; int info = 0; - const MatrixView + const MatrixConstView dataView(&lyapunov_tol, 1, 1, 1); // dummy Matrix yView(dataView.getRows(),dataView.getCols()); // dummy @@ -144,7 +144,7 @@ main(int argc, char **argv) std::cout << "Initialize KF with Q: " << std::endl << Q << std::endl; - initializeKalmanFilter.initialize(steadyState, deepParams, R, Q, RQRt, T, Pstar, Pinf, + initializeKalmanFilter.initialize(steadyStateVW, deepParams, R, Q, RQRt, T, Pstar, Pinf, penalty, dataView, yView, info); std::cout << "Matrix T: " << std::endl << T << std::endl; diff --git a/mex/sources/estimation/tests/testKalman.cc b/mex/sources/estimation/tests/testKalman.cc index b240a1bce..7db171f6b 100644 --- a/mex/sources/estimation/tests/testKalman.cc +++ b/mex/sources/estimation/tests/testKalman.cc @@ -119,7 +119,7 @@ main(int argc, char **argv) int info = 0; Matrix yView(nobs,192); // dummy yView.setAll(0.2); - const MatrixView dataView(yView, 0, 0, nobs, yView.getCols() ); // dummy + const MatrixConstView dataView(yView, 0, 0, nobs, yView.getCols() ); // dummy Vector vll(yView.getCols()); VectorView vwll(vll,0,vll.getSize()); @@ -130,7 +130,7 @@ main(int argc, char **argv) varobs_arg, riccati_tol, lyapunov_tol, info); size_t start=0, period=0; - double ll=kalman.compute(dataView, steadyState, Q, H, deepParams, + double ll=kalman.compute(dataView, steadyStateVW, Q, H, deepParams, vwll, start, period, penalty, info); std::cout << "ll: " << std::endl << ll << std::endl; From 6f11442c7b54dc94be442715048f1bb676200d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 7 May 2010 18:18:24 +0200 Subject: [PATCH 3/4] Estimation DLL: fix to testModelSolution --- mex/sources/estimation/tests/testModelSolution.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mex/sources/estimation/tests/testModelSolution.cc b/mex/sources/estimation/tests/testModelSolution.cc index 3a6ad7e61..20709a049 100644 --- a/mex/sources/estimation/tests/testModelSolution.cc +++ b/mex/sources/estimation/tests/testModelSolution.cc @@ -39,7 +39,7 @@ main (int argc, char** argv) std::vector zeta_mixed_arg; std::vector zeta_static_arg; double qz_criterium=1.0+1.0e-9; - Vector steadyState(n_endo), deepParams(npar); + Vector deepParams(npar); double dYSparams [] = { 1.0110, 2.2582, 0.4477, 1.0000, @@ -66,8 +66,7 @@ main (int argc, char** argv) VectorView modParamsVW (dparams, npar,1); deepParams=modParamsVW; - VectorView steadyStateVW(dYSparams,n_endo,1); - steadyState=steadyStateVW; + VectorView steadyState(dYSparams,n_endo,1); std::cout << "Vector deepParams: " << std::endl << deepParams << std::endl; std::cout << "Matrix vCov: " << std::endl << vCov << std::endl; std::cout << "Vector steadyState: " << std::endl << steadyState << std::endl; From 891ad2256464580b1a831b3508c1a82b1e1c66d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 12 May 2010 11:50:27 +0200 Subject: [PATCH 4/4] Macro-processor: integer ranges with lower bound greater than upper bound are now empty (for consistency with MATLAB) --- preprocessor/macro/MacroValue.cc | 6 ------ preprocessor/macro/MacroValue.hh | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/preprocessor/macro/MacroValue.cc b/preprocessor/macro/MacroValue.cc index d21180756..98833caba 100644 --- a/preprocessor/macro/MacroValue.cc +++ b/preprocessor/macro/MacroValue.cc @@ -325,12 +325,6 @@ IntMV::new_range(MacroDriver &driver, const MacroValue *mv1, const MacroValue *m int v2 = mv2i->value; vector result; - if (v2 < v1) - { - int x = v2; - v2 = v1; - v1 = x; - } for (; v1 <= v2; v1++) result.push_back(v1); return new ArrayMV(driver, result); diff --git a/preprocessor/macro/MacroValue.hh b/preprocessor/macro/MacroValue.hh index 52b566f4c..e379a6026 100644 --- a/preprocessor/macro/MacroValue.hh +++ b/preprocessor/macro/MacroValue.hh @@ -153,7 +153,7 @@ public: //! Creates a integer range /*! Arguments must be of type IntMV. Returns an integer array containing all integers between mv1 and mv2. - If mv2 < mv1, constructs the range in decreasing order. + If mv2 < mv1, returns an empty range (for consistency with MATLAB). */ static const MacroValue *new_range(MacroDriver &driver, const MacroValue *mv1, const MacroValue *mv2) throw (TypeError); };