Estimation DLL:
* finished test for DecisionRules * added new test for LUSolver * improved test for QRDecompositiontime-shift
parent
dcf10eba56
commit
30d9feb146
|
@ -134,6 +134,8 @@ ylwrap
|
|||
/mex/sources/estimation/libmat/tests/test-qr.exe
|
||||
/mex/sources/estimation/libmat/tests/test-gsd
|
||||
/mex/sources/estimation/libmat/tests/test-gsd.exe
|
||||
/mex/sources/estimation/libmat/tests/test-lu
|
||||
/mex/sources/estimation/libmat/tests/test-lu.exe
|
||||
|
||||
# Misc
|
||||
!/matlab/swz/c-code/Makefile
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
check_PROGRAMS = test-qr test-gsd
|
||||
check_PROGRAMS = test-qr test-gsd test-lu
|
||||
|
||||
test_qr_SOURCES = ../Matrix.cc ../Vector.cc ../QRDecomposition.cc test-qr.cc
|
||||
test_qr_LDADD = $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
|
||||
|
@ -7,3 +7,12 @@ test_qr_CPPFLAGS = -I.. -I../../../
|
|||
test_gsd_SOURCES = ../Matrix.cc ../Vector.cc ../GeneralizedSchurDecomposition.cc test-gsd.cc
|
||||
test_gsd_LDADD = $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
|
||||
test_gsd_CPPFLAGS = -I.. -I../../../
|
||||
|
||||
test_lu_SOURCES = ../Matrix.cc ../Vector.cc ../LUSolver.cc test-lu.cc
|
||||
test_lu_LDADD = $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
|
||||
test_lu_CPPFLAGS = -I.. -I../../../
|
||||
|
||||
check-local:
|
||||
./test-qr
|
||||
./test-gsd
|
||||
./test-lu
|
||||
|
|
|
@ -37,8 +37,8 @@ main(int argc, char **argv)
|
|||
mat::transpose(D);
|
||||
mat::transpose(E);
|
||||
|
||||
std::cout << "Matrix D: " << std::endl << D << std::endl;
|
||||
std::cout << "Matrix E: " << std::endl << E << std::endl;
|
||||
std::cout << "D =" << std::endl << D << std::endl;
|
||||
std::cout << "E =" << std::endl << E << std::endl;
|
||||
|
||||
GeneralizedSchurDecomposition GSD(n, 1.00001);
|
||||
|
||||
|
@ -47,9 +47,9 @@ main(int argc, char **argv)
|
|||
|
||||
GSD.compute(D, E, S, T, Z, sdim);
|
||||
|
||||
std::cout << "Matrix S: " << std::endl << S << std::endl;
|
||||
std::cout << "Matrix T: " << std::endl << T << std::endl;
|
||||
std::cout << "Matrix Z: " << std::endl << Z << std::endl;
|
||||
std::cout << "S =" << std::endl << S << std::endl;
|
||||
std::cout << "T =" << std::endl << T << std::endl;
|
||||
std::cout << "Z =" << std::endl << Z << std::endl;
|
||||
|
||||
Vector eig_real(n), eig_cmplx(n);
|
||||
GSD.getGeneralizedEigenvalues(eig_real, eig_cmplx);
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "BlasBindings.hh"
|
||||
#include "LUSolver.hh"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
size_t m = 4, n = 3;
|
||||
|
||||
double A_data[] = { -1, 2, 3,
|
||||
4, -5, 6,
|
||||
7, 8, -9 };
|
||||
double B_data[] = { 1, -3, 4, 5,
|
||||
-7, 9, 1, 7,
|
||||
-3, 4, 0, -2 };
|
||||
MatrixView A(A_data, n, n, n), B_prime(B_data, m, n, m);
|
||||
Matrix B(n, m);
|
||||
|
||||
mat::transpose(A);
|
||||
mat::transpose(B, B_prime);
|
||||
|
||||
std::cout << "A =" << std::endl << A << std::endl
|
||||
<< "B =" << std::endl << B << std::endl;
|
||||
|
||||
LUSolver LU(n);
|
||||
|
||||
LU.invMult("N", A, B);
|
||||
|
||||
std::cout << "A\\B =" << std::endl << B;
|
||||
|
||||
// Check this is the right result
|
||||
double C_data[] = { -1.0500, 1.3750, 0.0833, 0.6250,
|
||||
0.3000, -0.7500, 0.8333, 0.7500,
|
||||
-0.2167, -0.0417, 0.8056, 1.3750 };
|
||||
MatrixView C_prime(C_data, m, n, m);
|
||||
Matrix C(n, m);
|
||||
mat::transpose(C, C_prime);
|
||||
mat::sub(B, C);
|
||||
assert(mat::nrminf(B) < 1e-4);
|
||||
}
|
|
@ -26,7 +26,7 @@ int
|
|||
main(int argc, char **argv)
|
||||
{
|
||||
size_t m = 4, n = 3;
|
||||
Matrix S(m, n), Q(m), A(m, n), B(m);
|
||||
Matrix S(m, n), Q(m), A(m, n), B(m), S2(m, n);
|
||||
QRDecomposition QRD(m, n, m);
|
||||
|
||||
for (size_t i = 0; i < m; i++)
|
||||
|
@ -37,20 +37,30 @@ main(int argc, char **argv)
|
|||
|
||||
mat::set_identity(Q);
|
||||
|
||||
QRD.computeAndLeftMultByQ(S, "N", Q);
|
||||
S2 = S;
|
||||
QRD.computeAndLeftMultByQ(S2, "N", Q);
|
||||
|
||||
std::cout << "Matrix Q:" << std::endl << Q << std::endl;
|
||||
std::cout << "Q =" << std::endl << Q << std::endl;
|
||||
|
||||
blas::gemm("T", "N", 1.0, Q, Q, 0.0, B);
|
||||
|
||||
std::cout << "Matrix Q'*Q:" << std::endl << B << std::endl;
|
||||
std::cout << "Q'*Q =" << std::endl << B << std::endl;
|
||||
|
||||
for (size_t j = 0; j < n; j++)
|
||||
mat::col_set(S, j, j+1, m-j-1, 0);
|
||||
mat::col_set(S2, j, j+1, m-j-1, 0);
|
||||
|
||||
std::cout << "Matrix R:" << std::endl << S << std::endl;
|
||||
std::cout << "R =" << std::endl << S2 << std::endl;
|
||||
|
||||
blas::gemm("N", "N", 1.0, Q, S, 0.0, A);
|
||||
blas::gemm("N", "N", 1.0, Q, S2, 0.0, A);
|
||||
|
||||
std::cout << "Product Q*R:" << std::endl << A << std::endl;
|
||||
std::cout << "Q*R =" << std::endl << A << std::endl;
|
||||
|
||||
// Check values
|
||||
Matrix B2(m);
|
||||
mat::set_identity(B2);
|
||||
mat::sub(B2, B);
|
||||
assert(mat::nrminf(B2) < 1e-4);
|
||||
|
||||
mat::sub(A, S);
|
||||
assert(mat::nrminf(A) < 1e-4);
|
||||
}
|
||||
|
|
|
@ -3,3 +3,6 @@ check_PROGRAMS = test-dr
|
|||
test_dr_SOURCES = ../libmat/Matrix.cc ../libmat/Vector.cc ../libmat/QRDecomposition.cc ../libmat/GeneralizedSchurDecomposition.cc ../libmat/LUSolver.cc ../DecisionRules.cc test-dr.cc
|
||||
test_dr_LDADD = $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
|
||||
test_dr_CPPFLAGS = -I.. -I../libmat -I../../
|
||||
|
||||
check-local:
|
||||
./test-dr
|
||||
|
|
|
@ -153,5 +153,41 @@ main(int argc, char **argv)
|
|||
Vector eig_real(6), eig_cmplx(6);
|
||||
dr.getGeneralizedEigenvalues(eig_real, eig_cmplx);
|
||||
std::cout << "Eigenvalues (real part): " << eig_real
|
||||
<< "Eigenvalues (complex part): " << eig_cmplx;
|
||||
<< "Eigenvalues (complex part): " << eig_cmplx << std::endl
|
||||
<< "g_y = " << std::endl << g_y << std::endl
|
||||
<< "g_u = " << std::endl << g_u;
|
||||
|
||||
// Check the results for g_y
|
||||
double real_g_y_data[] = {
|
||||
0.005358267364601, 1.836717147430803, 0.837085806295838,
|
||||
0.038541607674354, 0.424582606909411, -0.318740381721598,
|
||||
0.941816659690247, 1.419061793291772, 1.419061793291773,
|
||||
-0.000000000000000, 0.950000000000000, 0.025000000000000,
|
||||
-0.012546516642830, 0.341714987626857, 0.341714987626861,
|
||||
0.000000000000000, 0.025000000000000, 0.950000000000000
|
||||
};
|
||||
|
||||
MatrixView real_g_y_prime(real_g_y_data, 3, 6, 3);
|
||||
Matrix real_g_y(6, 3);
|
||||
mat::transpose(real_g_y, real_g_y_prime);
|
||||
mat::sub(real_g_y, g_y);
|
||||
|
||||
assert(mat::nrminf(real_g_y) < 1e-13);
|
||||
|
||||
// Check the results for g_u
|
||||
double real_g_u_data[] = {
|
||||
1.911522267389459, 0.830839736432740,
|
||||
0.456074274269694, -0.347518145871938,
|
||||
1.455447993119765, 1.455447993119767,
|
||||
1.000000000000000, 0,
|
||||
0.350476910386520, 0.350476910386525,
|
||||
0, 1.000000000000000
|
||||
};
|
||||
|
||||
MatrixView real_g_u_prime(real_g_u_data, 2, 6, 2);
|
||||
Matrix real_g_u(6, 2);
|
||||
mat::transpose(real_g_u, real_g_u_prime);
|
||||
mat::sub(real_g_u, g_u);
|
||||
|
||||
assert(mat::nrminf(real_g_u) < 1e-13);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue