- Timestamp:
- 08/12/09 16:47:33 (15 years ago)
- Location:
- library
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/CMakeLists.txt
r498 r508 2 2 3 3 SET(bdm_base base/bdmbase.cpp base/bdmbase.h base/datasources.cpp base/datasources.h base/loggers.cpp base/loggers.h) 4 SET(bdm_math math/square_mat.cpp math/square_mat.h math/chmat.cpp math/chmat.h math/functions.cpp math/functions.h) 4 SET(bdm_math math/square_mat.cpp math/square_mat.h 5 math/chmat.cpp math/chmat.h 6 math/functions.cpp math/functions.h) 5 7 SET(bdm_stat stat/exp_family.cpp stat/exp_family.h stat/emix.cpp stat/emix.h stat/merger.h stat/merger.cpp) 6 8 SET(bdm_estim estim/kalman.cpp estim/kalman.h estim/particles.cpp estim/particles.h estim/arx.cpp estim/arx.h estim/mixtures.cpp estim/mixtures.h) 7 SET(bdm_user_info base/libconfig/libconfigcpp.cc base/libconfig/grammar.c base/libconfig/libconfig.c base/libconfig/scanner.c base/user_info.cpp base/user_info.h ) 9 SET(bdm_ctrl design/ctrlbase.cpp design/ctrlbase.h) 10 SET(bdm_user_info base/libconfig/libconfigcpp.cc base/libconfig/grammar.c base/libconfig/libconfig.c base/libconfig/scanner.c 11 base/user_info.cpp base/user_info.h ) 8 12 SET(bdm_mex mex/mex_datasource.h mex/mex_parser.h mex/mex_logger.h ) 9 13 -
library/bdm/base/bdmbase.h
r507 r508 1 1 /*! 2 2 \file 3 \brief Ba yesian Models (bm) that use Bayes rule to learn from observations3 \brief Basic structures of probability calculus: random variables, probability densities, Bayes rule 4 4 \author Vaclav Smidl. 5 5 -
library/bdm/design/ctrlbase.cpp
r491 r508 1 #include <ctrlbase.h>1 #include "ctrlbase.h" 2 2 3 LQG::set_system_parameters(const mat &A0, const mat &B0, const mat &C0){ 3 namespace bdm{ 4 5 void LQG::set_system_parameters(const mat &A0, const mat &B0, const mat &C0){ 4 6 dimx = A0.rows(); 5 7 dimy = C0.rows(); … … 13 15 B=B0; 14 16 C=C0; 15 16 // set temporary stuff; 17 pr = concat_vertical( 18 concat_horizontal(B,A, zeros(dimx, dimu+dimy)), 19 concat_horizontal(zeros(dimu+dimy,dimu+dimx), eye(dimu+dimy))); 17 pr=zeros(dimx+dimu+dimy, dimu+dimx+dimu+dimy); 18 pr.set_submatrix(dimx, dimu+dimx, eye(dimu+dimy)); 19 } 20 21 void LQG::set_control_parameters(const mat &Qy0, const mat &Qu0, const vec y_req0, int horizon0){ 22 it_assert_debug ( Qy0.cols() == dimy, "LQG: wrong dimensions of Qy " ); 23 it_assert_debug ( Qu0.cols() == dimu, "LQG: wrong dimensions of Qu " ); 24 it_assert_debug ( y_req0.length() == dimy, "LQG: wrong dimensions of y_req " ); 25 26 Qy=Qy0; 27 Qu=Qu0; 28 y_req=y_req0; 29 horizon = horizon0; 30 prepare_qr(); 31 } 32 33 void LQG::prepare_qr(){ 34 // set parameter matrix 35 pr.set_submatrix(0,0,B); 36 pr.set_submatrix(0,dimu, A); 20 37 21 38 //penalization … … 24 41 qux.set_submatrix(0,dimx+dimu+dimy,Qu); 25 42 26 qyx=concat_horizontal(C,-eye(dimy),zeros(dimy,dimu)); 43 qyx=zeros(dimy, dimx+dimy+dimu); 44 qyx.set_submatrix(0,0,C); 45 qyx.set_submatrix(0,dimx,-eye(dimy)); 27 46 28 47 // 29 s=1e-5*eye( dimx+dimu+dimy);48 s=1e-5*eye(4);//dimx+dimu+dimy); 30 49 // parts of QR 31 50 hqy=Qy*qyx*pr; 32 51 33 52 // pre_qr 34 pre_qr = concat_vertical(s*pr, hqy, qux);35 53 pre_qr = concat_vertical(s*pr, concat_vertical(hqy, qux)); 54 post_qr = zeros(pre_qr.rows(), pre_qr.cols()); 36 55 } 56 57 } -
library/bdm/design/ctrlbase.h
r491 r508 11 11 */ 12 12 13 #include <bdmbase.h> 13 #include "../base/bdmbase.h" 14 15 namespace bdm{ 14 16 15 17 //! Base class of designers of control strategy … … 17 19 public: 18 20 //! Redesign control strategy 19 virtual redesign(){it_error("Not implemented"); };21 virtual void redesign(){it_error("Not implemented"); }; 20 22 //! apply control strategy to obtain control input 21 23 virtual vec apply(const vec &cond){it_error("Not implemented"); return vec(0);} 22 } 24 }; 23 25 24 26 //! Linear Quadratic Gaussian designer for constant penalizations and constant target … … 31 33 int dimu; 32 34 //! dimension of output 33 /int dimy;35 int dimy; 34 36 35 37 //! matrix A of the linear system … … 39 41 //! matrix C of the linear system 40 42 mat C; 41 //! expected value of x at time t42 vec xt;43 43 //! required value of the output y at time t (assumed constant) 44 44 vec y_req; … … 77 77 //! set system parameters from given matrices 78 78 void set_system_parameters(const mat &A, const mat &B, const mat &C); 79 //! set penalization matrices and control horizon 80 void set_control_parameters(const mat &Qy0, const mat &Qu0, const vec y_req0, int horizon0); 79 81 //! set system parameters from Kalman filter 80 void set_system_parameters(const Kalman &K); 81 //! set current state 82 void set_state(const vec &xt0){xt=xt0;}; 83 //! refresh temporary storage 84 //! function for future use which is called at each time td; 85 virtual update_state(){}; 82 // void set_system_parameters(const Kalman &K); 83 //! refresh temporary storage - inefficient can be improved 84 void prepare_qr(); 85 //! function for future use which is called at each time td; Should call prepare_qr()! 86 virtual void update_state(){}; 86 87 //! redesign one step of the 87 88 void ricatti_step(){ 88 89 pre_qr.set_submatrix(0,0,s*pr); 89 pre_qr.set_submatrix(dimx , dimu+dimx, -Qy*y_req);90 post_qr=qr(pre_qr);90 pre_qr.set_submatrix(dimx+dimu+dimy, dimu+dimx, -Qy*y_req); 91 if (!qr(pre_qr,post_qr)) it_warning("QR in LQG unstable"); 91 92 triu(post_qr); 92 93 // hn(m+1:2*m+n+r,m+1:2*m+n+r); 93 s=post_qr.get(dimu, 2*dimu+dimx+dimy , dimu, 2*dimu+dimx+dimy);94 s=post_qr.get(dimu, 2*dimu+dimx+dimy-1, dimu, 2*dimu+dimx+dimy-1); 94 95 }; 95 96 void redesign(){ … … 101 102 wsd=hn(1:m,1:m); 102 103 Lklq=-inv(wsd)*ws;*/ 103 L = -inv(post_qr.get(0,dimu-1, 0,dimu-1)) * post_qr.get(0,dimu , dimu, 2*dimu+dimx+dimy);104 L = -inv(post_qr.get(0,dimu-1, 0,dimu-1)) * post_qr.get(0,dimu-1, dimu, 2*dimu+dimx+dimy-1); 104 105 } 105 vec apply(const vec &state, const vec &ukm){vec pom=concat_vertical(state, ones(dimy,1), ukm); return L*pom;} 106 } 106 vec apply(const vec &state, const vec &ukm){vec pom=concat(state, ones(dimy), ukm); return L*pom;} 107 } ; 108 109 } // namespace -
library/bdm/itpp_ext.cpp
r477 r508 371 371 } 372 372 373 } 373 void triu(mat &A){ 374 for(int i=1;i<A.rows();i++) { // row cycle 375 for (int j=0; j<i; j++) {A(i,j)=0;} 376 } 377 } 378 } -
library/bdm/itpp_ext.h
r477 r508 100 100 //! implementation of digamma (psi) function 101 101 double psi ( double ); 102 103 //! implementation of matlab triu function 104 void triu(mat &A); 102 105 } 103 106 -
library/tests/CMakeLists.txt
r506 r508 7 7 link_directories (./unittest-cpp) 8 8 9 SET(testutil_src egiw_harness.cpp egiw_harness.h epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h mpdf_harness.cpp mpdf_harness.h square_mat_point.cpp square_mat_point.h test_util.cpp test_util.h) 9 SET(testutil_src egiw_harness.cpp egiw_harness.h epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h 10 mpdf_harness.cpp mpdf_harness.h square_mat_point.cpp square_mat_point.h test_util.cpp test_util.h) 10 11 11 12 add_library(testutil ${testutil_src}) … … 16 17 LINK_EXEC(square_mat_stress) 17 18 18 add_executable(square_mat_prep additive_generator.cpp additive_generator.h generator.cpp generator.h size_generator.cpp size_generator.h square_mat_prep.cpp) 19 add_executable(square_mat_prep additive_generator.cpp additive_generator.h generator.cpp generator.h 20 size_generator.cpp size_generator.h square_mat_prep.cpp) 19 21 target_link_libraries(square_mat_prep testutil) 20 22 LINK_EXEC(square_mat_prep) … … 39 41 # using UnitTest++ 40 42 add_executable(testsuite datalink_test.cpp egiw_test.cpp emix_test.cpp epdf_test.cpp loggers_test.cpp merger_test.cpp mpdf_test.cpp rv_test.cpp shared_ptr_test.cpp square_mat_test.cpp testsuite.cpp user_info_test.cpp) 43 mpdf_test.cpp rv_test.cpp shared_ptr_test.cpp square_mat_test.cpp testsuite.cpp user_info_test.cpp) 41 44 target_link_libraries(testsuite testutil unittest) 42 45 LINK_EXEC(testsuite)