Changeset 722
- Timestamp:
- 11/13/09 16:11:31 (15 years ago)
- Location:
- library/tests
- Files:
-
- 2 added
- 33 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/CMakeLists.txt
r717 r722 7 7 link_directories (./unittest-cpp) 8 8 9 SET(testutil_src epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h9 SET(testutil_src general_suite.cpp general_suite.h epdf_harness.cpp epdf_harness.h mat_checks.cpp mat_checks.h 10 10 pdf_harness.cpp pdf_harness.h square_mat_point.cpp square_mat_point.h test_util.cpp test_util.h) 11 11 -
library/tests/epdf_harness.cpp
r713 r722 28 28 UI::get ( variance, set, "variance", UI::compulsory ); 29 29 30 UI::get ( support, set, "support", UI::optional );31 UI::get ( nbins, set, "nbins", UI::optional );32 UI::get ( nsamples, set, "nsamples", UI::optional );33 UI::get ( R, set, "R", UI::optional );34 35 mrv = UI::build<RV> ( set, "marginal_rv", UI::optional );30 UI::get ( support, set, "support", UI::optional ); 31 UI::get ( nbins, set, "nbins", UI::optional ); 32 UI::get ( nsamples, set, "nsamples", UI::optional ); 33 UI::get ( R, set, "R", UI::optional ); 34 35 mrv = UI::build<RV> ( set, "marginal_rv", UI::optional ); 36 36 37 37 UI::get ( tolerance, set, "tolerance", UI::optional ); … … 74 74 mprod mEp ( aa ); 75 75 76 check_cond_mean (mEp);76 check_cond_mean ( mEp ); 77 77 if ( R.rows() > 0 ) { 78 check_cond_covariance ( mEp );78 check_cond_covariance ( mEp ); 79 79 } 80 80 81 81 // test of pdflog at zero 82 82 vec zero ( 0 ); 83 vec zeron =zeros ( hepdf->dimension() );83 vec zeron = zeros ( hepdf->dimension() ); 84 84 85 85 double lpz = hepdf->evallog ( zeron ); 86 double lpzc =mEp.evallogcond ( zeron, zero );86 double lpzc = mEp.evallogcond ( zeron, zero ); 87 87 CHECK_CLOSE_EX ( lpz, lpzc, tolerance ); 88 88 89 vec lpzv (1);90 lpzv (0) = lpz;89 vec lpzv ( 1 ); 90 lpzv ( 0 ) = lpz; 91 91 92 92 mat zero1n ( hepdf->dimension(), 1 ); … … 98 98 CHECK_CLOSE_EX ( lpzv, lpzv_act, tolerance ); 99 99 100 Array<vec> zeroa (3);101 lpzv = vec ( zeroa.size() );100 Array<vec> zeroa ( 3 ); 101 lpzv = vec ( zeroa.size() ); 102 102 for ( int i = 0; i < zeroa.size(); ++i ) { 103 zeroa (i) = zeron;104 lpzv (i) = lpz;103 zeroa ( i ) = zeron; 104 lpzv ( i ) = lpz; 105 105 } 106 106 … … 115 115 116 116 int tc = 0; 117 Array<vec> actual (CurrentContext::max_trial_count);117 Array<vec> actual ( CurrentContext::max_trial_count ); 118 118 do { 119 119 vec emu = num_mean2 ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); 120 actual ( tc ) = emu;121 ++tc; 122 } while ( ( tc < CurrentContext::max_trial_count ) && 123 !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) );124 if ( ( tc == CurrentContext::max_trial_count ) && 125 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {126 UnitTest::MemoryOutStream stream; 127 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual;128 129 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);130 131 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 132 120 actual ( tc ) = emu; 121 ++tc; 122 } while ( ( tc < CurrentContext::max_trial_count ) && 123 !UnitTest::AreClose ( mean, actual ( tc - 1 ), tolerance ) ); 124 if ( ( tc == CurrentContext::max_trial_count ) && 125 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 126 UnitTest::MemoryOutStream stream; 127 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 128 129 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 130 131 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 132 } 133 133 } 134 134 … … 138 138 139 139 int tc = 0; 140 Array<double> actual (CurrentContext::max_trial_count);140 Array<double> actual ( CurrentContext::max_trial_count ); 141 141 do { 142 142 double nc = normcoef ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); 143 actual ( tc ) = nc;144 ++tc; 145 } while ( ( tc < CurrentContext::max_trial_count ) && 146 !UnitTest::AreClose ( 1.0, actual( tc - 1 ), tolerance ) );147 if ( ( tc == CurrentContext::max_trial_count ) && 148 ( !UnitTest::AreClose ( 1.0, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {149 UnitTest::MemoryOutStream stream; 150 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual;151 152 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);153 154 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 155 143 actual ( tc ) = nc; 144 ++tc; 145 } while ( ( tc < CurrentContext::max_trial_count ) && 146 !UnitTest::AreClose ( 1.0, actual ( tc - 1 ), tolerance ) ); 147 if ( ( tc == CurrentContext::max_trial_count ) && 148 ( !UnitTest::AreClose ( 1.0, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 149 UnitTest::MemoryOutStream stream; 150 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 151 152 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 153 154 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 155 } 156 156 } 157 157 … … 160 160 161 161 int tc = 0; 162 Array<vec> actual (CurrentContext::max_trial_count);162 Array<vec> actual ( CurrentContext::max_trial_count ); 163 163 do { 164 164 mat smp = hepdf->sample_mat ( nsamples ); 165 165 vec emu = smp * ones ( nsamples ) / nsamples; 166 actual ( tc ) = emu;167 ++tc; 168 } while ( ( tc < CurrentContext::max_trial_count ) && 169 !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) );170 if ( ( tc == CurrentContext::max_trial_count ) && 171 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) {172 UnitTest::MemoryOutStream stream; 173 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual;174 175 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);176 177 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 178 166 actual ( tc ) = emu; 167 ++tc; 168 } while ( ( tc < CurrentContext::max_trial_count ) && 169 !UnitTest::AreClose ( mean, actual ( tc - 1 ), delta ) ); 170 if ( ( tc == CurrentContext::max_trial_count ) && 171 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 172 UnitTest::MemoryOutStream stream; 173 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << delta << " but was " << actual; 174 175 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 176 177 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 178 } 179 179 } 180 180 181 181 void epdf_harness::check_covariance() { 182 182 int tc = 0; 183 Array<mat> actual (CurrentContext::max_trial_count);183 Array<mat> actual ( CurrentContext::max_trial_count ); 184 184 do { 185 185 mat smp = hepdf->sample_mat ( nsamples ); 186 186 vec emu = smp * ones ( nsamples ) / nsamples; 187 187 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 188 actual ( tc ) = er;189 ++tc; 190 } while ( ( tc < CurrentContext::max_trial_count ) && 191 !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) );192 193 if ( ( tc == CurrentContext::max_trial_count ) && 194 ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {195 UnitTest::MemoryOutStream stream; 196 stream << CurrentContext::format_context (__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual;197 198 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);199 200 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 201 202 } 203 204 void epdf_harness::check_cond_mean ( mprod &mep ) {188 actual ( tc ) = er; 189 ++tc; 190 } while ( ( tc < CurrentContext::max_trial_count ) && 191 !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 192 193 if ( ( tc == CurrentContext::max_trial_count ) && 194 ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 195 UnitTest::MemoryOutStream stream; 196 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << R << " +/- " << tolerance << " but was " << actual; 197 198 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 199 200 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 201 } 202 } 203 204 void epdf_harness::check_cond_mean ( mprod &mep ) { 205 205 vec delta = make_close_tolerance ( variance, nsamples ); 206 206 207 207 int tc = 0; 208 Array<vec> actual (CurrentContext::max_trial_count);208 Array<vec> actual ( CurrentContext::max_trial_count ); 209 209 do { 210 210 mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 211 211 vec emu = sum ( smp, 2 ) / nsamples; 212 actual ( tc ) = emu;213 ++tc; 214 } while ( ( tc < CurrentContext::max_trial_count ) && 215 !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) );216 if ( ( tc == CurrentContext::max_trial_count ) && 217 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) {218 UnitTest::MemoryOutStream stream; 219 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual;220 221 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);222 223 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 224 225 } 226 227 void epdf_harness::check_cond_covariance ( mprod &mep ) {228 int tc = 0; 229 Array<mat> actual (CurrentContext::max_trial_count);212 actual ( tc ) = emu; 213 ++tc; 214 } while ( ( tc < CurrentContext::max_trial_count ) && 215 !UnitTest::AreClose ( mean, actual ( tc - 1 ), delta ) ); 216 if ( ( tc == CurrentContext::max_trial_count ) && 217 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 218 UnitTest::MemoryOutStream stream; 219 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << delta << " but was " << actual; 220 221 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 222 223 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 224 } 225 } 226 227 void epdf_harness::check_cond_covariance ( mprod &mep ) { 228 int tc = 0; 229 Array<mat> actual ( CurrentContext::max_trial_count ); 230 230 do { 231 231 mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 232 232 vec emu = sum ( smp, 2 ) / nsamples; 233 233 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 234 actual ( tc ) = er;235 ++tc; 236 } while ( ( tc < CurrentContext::max_trial_count ) && 237 !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) );238 if ( ( tc == CurrentContext::max_trial_count ) && 239 ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {240 UnitTest::MemoryOutStream stream; 241 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual;242 243 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);244 245 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 246 247 } 248 249 } 234 actual ( tc ) = er; 235 ++tc; 236 } while ( ( tc < CurrentContext::max_trial_count ) && 237 !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 238 if ( ( tc == CurrentContext::max_trial_count ) && 239 ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 240 UnitTest::MemoryOutStream stream; 241 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 242 243 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 244 245 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 246 } 247 } 248 249 } -
library/tests/epdf_harness.h
r706 r722 69 69 70 70 // assumes marginal_rv is valid 71 void check_cond_mean ( mprod &mep );71 void check_cond_mean ( mprod &mep ); 72 72 73 73 // assumes marginal_rv and R are valid 74 void check_cond_covariance ( mprod &mep );74 void check_cond_covariance ( mprod &mep ); 75 75 }; 76 UIREGISTER (epdf_harness);76 UIREGISTER ( epdf_harness ); 77 77 78 78 } -
library/tests/mat_checks.cpp
r706 r722 68 68 } 69 69 70 std::string CurrentContext::format_context (int ln) {70 std::string CurrentContext::format_context ( int ln ) { 71 71 std::stringstream ss; 72 72 ss << "error at " << config_name << '[' << index << ']'; 73 73 74 74 if ( ln >= 0 ) { 75 75 ss << ", harness line " << ln; 76 76 } 77 77 -
library/tests/mat_checks.h
r706 r722 81 81 __LINE__ (and it is included in the returned string). 82 82 */ 83 static std::string format_context ( int ln = -1 );83 static std::string format_context ( int ln = -1 ); 84 84 85 85 template<typename Expected, typename Actual> -
library/tests/pdf_harness.cpp
r713 r722 48 48 49 49 int tc = 0; 50 Array<vec> actual (CurrentContext::max_trial_count);50 Array<vec> actual ( CurrentContext::max_trial_count ); 51 51 do { 52 52 mat smp = hpdf->samplecond_mat ( cond, nsamples ); 53 53 vec emu = smp * ones ( nsamples ) / nsamples; 54 actual ( tc ) = emu;54 actual ( tc ) = emu; 55 55 ++tc; 56 56 } while ( ( tc < CurrentContext::max_trial_count ) && 57 !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) );57 !UnitTest::AreClose ( mean, actual ( tc - 1 ), delta ) ); 58 58 if ( ( tc == CurrentContext::max_trial_count ) && 59 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) {59 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 60 60 UnitTest::MemoryOutStream stream; 61 stream << CurrentContext::format_context (__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual;61 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << delta << " but was " << actual; 62 62 63 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);63 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 64 64 65 65 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 66 66 } 67 67 } 68 68 69 69 void pdf_harness::check_covariance() { 70 70 int tc = 0; 71 Array<mat> actual (CurrentContext::max_trial_count);71 Array<mat> actual ( CurrentContext::max_trial_count ); 72 72 do { 73 73 mat smp = hpdf->samplecond_mat ( cond, nsamples ); 74 74 vec emu = smp * ones ( nsamples ) / nsamples; 75 75 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 76 actual ( tc ) = er;76 actual ( tc ) = er; 77 77 ++tc; 78 78 } while ( ( tc < CurrentContext::max_trial_count ) && 79 !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) );79 !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 80 80 if ( ( tc == CurrentContext::max_trial_count ) && 81 ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {81 ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 82 82 UnitTest::MemoryOutStream stream; 83 stream << CurrentContext::format_context (__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual;83 stream << CurrentContext::format_context ( __LINE__ ) << "expected " << R << " +/- " << tolerance << " but was " << actual; 84 84 85 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), 0, false);85 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 86 86 87 87 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 88 88 } 89 89 } 90 90 -
library/tests/pdf_harness.h
r706 r722 52 52 void check_covariance(); 53 53 }; 54 UIREGISTER (pdf_harness);54 UIREGISTER ( pdf_harness ); 55 55 56 56 } -
library/tests/stresssuite/arx_elem_stress.cpp
r721 r722 11 11 ARX Ar; 12 12 Ar.set_statistics ( 1, V0, -1.0 ); 13 Ar.set_constant (true);13 Ar.set_constant ( true ); 14 14 Ar.validate(); 15 15 -
library/tests/stresssuite/arx_stress.cpp
r721 r722 29 29 ARX Ar; 30 30 Ar.set_statistics ( 1, V0, nu0 ); // Estimator 31 Ar.set_constant (false);31 Ar.set_constant ( false ); 32 32 Ar.validate(); 33 33 const epdf& f_thr = Ar.posterior(); // refrence to posterior of the estimator … … 52 52 Yt ( t ) = th * rgr + sqr * NorRNG(); 53 53 54 Ar.bayes ( vec_1 (Yt(t)), rgr );// Bayes rule54 Ar.bayes ( vec_1 ( Yt ( t ) ), rgr ); // Bayes rule 55 55 56 56 // Build predictor -
library/tests/stresssuite/kalman_QR_stress.cpp
r721 r722 70 70 KF_QR.set_parameters ( &evolQR, &evolQR, 100 ); 71 71 evolQR.condition ( "1 1 1" ); 72 egamma kfinit =egamma("10 10 10","1 1 1");73 KF_QR.set_statistics ( egamma ("10 10 10","1 1 1"), &KF );72 egamma kfinit = egamma ( "10 10 10", "1 1 1" ); 73 KF_QR.set_statistics ( egamma ( "10 10 10", "1 1 1" ), &KF ); 74 74 const epdf& mpost = KF_QR.posterior(); 75 75 const epdf& mposttr = KFtr.posterior(); -
library/tests/stresssuite/kalman_stress.cpp
r721 r722 63 63 KF.set_parameters ( A, B, C, D, chmat ( Q ), chmat ( R ) ); 64 64 KF.set_statistics ( mu0, chmat ( P0 ) ); //prediction! 65 KF.set_evalll (false);65 KF.set_evalll ( false ); 66 66 KF.validate(); 67 67 const epdf& KFep = KF.posterior(); … … 71 71 // FULL 72 72 KalmanFull KF2; 73 KF2.set_parameters ( A, B, C, D, Q, R);74 KF2.set_statistics (mu0, P0 );75 KF2.set_evalll (false);73 KF2.set_parameters ( A, B, C, D, Q, R ); 74 KF2.set_statistics ( mu0, P0 ); 75 KF2.set_evalll ( false ); 76 76 KF2.validate(); 77 77 mat Xt2 ( dimx, Ndat ); … … 85 85 KFE.set_parameters ( fxu, hxu, Q, R ); 86 86 KFE.set_statistics ( mu0, chmat ( P0 ) ); 87 KFE.set_evalll (false);87 KFE.set_evalll ( false ); 88 88 KFE.validate(); 89 89 const epdf& KFEep = KFE.posterior(); … … 98 98 tt.tic(); 99 99 for ( int t = 1; t < Ndat; t++ ) { 100 dt = Dt.get_col (t);101 KF.bayes ( dt.get (0,C.rows()-1), dt.get(C.rows(), dt.length()-1) );100 dt = Dt.get_col ( t ); 101 KF.bayes ( dt.get ( 0, C.rows() - 1 ), dt.get ( C.rows(), dt.length() - 1 ) ); 102 102 Xt.set_col ( t, KFep.mean() ); 103 103 } … … 106 106 tt.tic(); 107 107 for ( int t = 1; t < Ndat; t++ ) { 108 dt = Dt.get_col (t);109 KF2.bayes ( dt.get (0,C.rows()-1), dt.get(C.rows(), dt.length()-1) );108 dt = Dt.get_col ( t ); 109 KF2.bayes ( dt.get ( 0, C.rows() - 1 ), dt.get ( C.rows(), dt.length() - 1 ) ); 110 110 Xt2.set_col ( t, KF2.posterior().mean() ); 111 111 } … … 114 114 tt.tic(); 115 115 for ( int t = 1; t < Ndat; t++ ) { 116 dt = Dt.get_col (t);117 KFE.bayes ( dt.get (0,C.rows()-1), dt.get(C.rows(), dt.length()-1) );116 dt = Dt.get_col ( t ); 117 KFE.bayes ( dt.get ( 0, C.rows() - 1 ), dt.get ( C.rows(), dt.length() - 1 ) ); 118 118 XtE.set_col ( t, KFEep.mean() ); 119 119 } -
library/tests/stresssuite/mixtures_stress.cpp
r721 r722 101 101 // Add ones for constant coefficients 102 102 mat Data = concat_vertical ( Smp, ones ( 1, Smp.cols() ) ); 103 Post.bayes ( Data , empty_vec );103 Post.bayes ( Data , empty_vec ); 104 104 105 105 cout << "Posterior mixture:" << endl; -
library/tests/stresssuite/particle_stress.cpp
r721 r722 37 37 38 38 ivec ind; 39 emp.resample (ind);39 emp.resample ( ind ); 40 40 41 41 cout << ind << endl; -
library/tests/stresssuite/resample_stress.cpp
r721 r722 38 38 39 39 ivec ind; 40 emp.resample (ind);40 emp.resample ( ind ); 41 41 42 42 cout << ind << endl; -
library/tests/stresssuite/size_generator.cpp
r717 r722 5 5 using bdm::UI; 6 6 7 void size_generator::from_setting (const Setting &set) {8 UI::get ( sz, set, "size", UI::optional );9 UI::get ( step, set, "step", UI::optional );7 void size_generator::from_setting ( const Setting &set ) { 8 UI::get ( sz, set, "size", UI::optional ); 9 UI::get ( step, set, "step", UI::optional ); 10 10 } 11 11 -
library/tests/stresssuite/stresssuite.cpp
r721 r722 5 5 #include "itpp_ext.h" 6 6 #include <string.h> 7 #include "../general_suite.h" 7 8 8 using std::cout; 9 using std::cerr; 10 using std::endl; 11 12 using namespace itpp; 13 14 Array<const char *> selected_tests; 15 16 bool is_selected_test ( const UnitTest::Test *test ) { 17 bdm_assert_debug ( test, "NULL test" ); 18 19 if ( !selected_tests.length() ) { 20 return true; 21 } 22 23 for ( int i = 0; i < selected_tests.length(); ++i ) { 24 const char *n = test->m_details.testName; 25 bdm_assert_debug ( n, "NULL test name" ); 26 const char *sname = selected_tests ( i ); 27 bdm_assert_debug ( sname, "NULL selected test name" ); 28 if ( !strcmp ( n, sname ) ) { 29 return true; 30 } 31 } 32 33 return false; 34 } 9 using namespace UnitTest; 35 10 36 11 int main ( int argc, char const *argv[] ) { 37 12 if ( argc > 1 ) { 38 if ( !strcmp ( argv[1], "print" ) ) { 39 UnitTest::Test* curTest = UnitTest::Test::GetTestList().GetHead(); 40 41 while ( curTest != 0 ) { 42 const char *n = curTest->m_details.testName; 43 printf ( "%s\n", n ); 44 curTest = curTest->next; 45 } 46 return 0; 47 } else { 48 selected_tests.set_length ( argc - 1 ); 49 const char **param = argv + 1; 50 int i = 0; 51 while ( *param ) { 52 selected_tests ( i ) = *param; 53 ++i; 54 ++param; 55 } 56 } 13 if ( !strcmp ( argv[1], "print" ) ) 14 print_test_list(); 15 else 16 pick_selected_tests ( argc, argv ); 57 17 } else { 58 cout << endl << "STRESSSUITE - a program covering all BDM stress tests." << endl << endl 59 << argv[0] << " ....................................... run all stress tests" << endl 60 << argv[0] << " particular_test_1 particular_test_2 ... run selected stress tests" << endl 18 cout << endl << "STRESSSUITE - a program covering all BDM stress tests." << endl << endl 19 << argv[0] << " ....................................... run all stress tests" << endl 20 << argv[0] << " particular_test_1 particular_test_2 ... run selected stress tests" << endl 61 21 << argv[0] << " print ................................. print all the implemented stress tests" << endl; 62 22 } 63 23 64 itpp::RNG_randomize(); 65 66 UnitTest::TestReporterStdout reporter; 67 UnitTest::TestRunner runner ( reporter ); 68 return runner.RunTestsIf ( UnitTest::Test::GetTestList(), 69 0, 70 is_selected_test, 71 0 ); 24 return run_selected_tests(); 72 25 } -
library/tests/testsuite/LQG_test.cpp
r717 r722 5 5 using namespace bdm; 6 6 7 TEST (LQG_test) {7 TEST ( LQG_test ) { 8 8 LQG reg; 9 shared_ptr<StateSpace<fsqmat> > stsp =new StateSpace<fsqmat>;9 shared_ptr<StateSpace<fsqmat> > stsp = new StateSpace<fsqmat>; 10 10 // 2 x 1 x 1 11 stsp-> set_parameters (eye(2), ones(2,1), ones(1,2), ones(1,1), /* Q,R */ eye(2), eye(1));12 reg.set_system (stsp); // A, B, C13 reg.set_control_parameters (eye(1), eye(1), vec_1(1.0), 6); //Qy, Qu, horizon11 stsp-> set_parameters ( eye ( 2 ), ones ( 2, 1 ), ones ( 1, 2 ), ones ( 1, 1 ), /* Q,R */ eye ( 2 ), eye ( 1 ) ); 12 reg.set_system ( stsp ); // A, B, C 13 reg.set_control_parameters ( eye ( 1 ), eye ( 1 ), vec_1 ( 1.0 ), 6 ); //Qy, Qu, horizon 14 14 15 15 reg.redesign(); 16 double reg_apply =reg.ctrlaction("0.5, 1.1","0.0")(0); /*convert vec to double*/17 CHECK_CLOSE (reg_apply, -0.248528137234392, 0.0001);16 double reg_apply = reg.ctrlaction ( "0.5, 1.1", "0.0" ) ( 0 ); /*convert vec to double*/ 17 CHECK_CLOSE ( reg_apply, -0.248528137234392, 0.0001 ); 18 18 } 19 19 20 TEST (to_state_test) {20 TEST ( to_state_test ) { 21 21 mlnorm<fsqmat> ml; 22 mat A ="1.1, 2.3";23 ml.set_parameters (A, vec_1(1.3), eye(1));24 RV yr =RV("y",1);25 RV ur =RV("u",1);26 ml.set_rv (yr);27 yr.t_plus (-1);28 ml.set_rvc (concat(yr, ur));29 30 shared_ptr<StateCanonical > Stsp =new StateCanonical;31 Stsp->connect_mlnorm (ml);32 33 /* results from 22 mat A = "1.1, 2.3"; 23 ml.set_parameters ( A, vec_1 ( 1.3 ), eye ( 1 ) ); 24 RV yr = RV ( "y", 1 ); 25 RV ur = RV ( "u", 1 ); 26 ml.set_rv ( yr ); 27 yr.t_plus ( -1 ); 28 ml.set_rvc ( concat ( yr, ur ) ); 29 30 shared_ptr<StateCanonical > Stsp = new StateCanonical; 31 Stsp->connect_mlnorm ( ml ); 32 33 /* results from 34 34 [A,B,C,D]=tf2ss([2.3 0],[1 -1.1]) 35 35 */ 36 CHECK_CLOSE_EX (Stsp->_A().get_row(0), vec("1.1"), 0.0001);37 CHECK_CLOSE_EX (Stsp->_C().get_row(0), vec("2.53"), 0.0001);38 CHECK_CLOSE_EX (Stsp->_D().get_row(0), vec("2.30"), 0.0001);36 CHECK_CLOSE_EX ( Stsp->_A().get_row ( 0 ), vec ( "1.1" ), 0.0001 ); 37 CHECK_CLOSE_EX ( Stsp->_C().get_row ( 0 ), vec ( "2.53" ), 0.0001 ); 38 CHECK_CLOSE_EX ( Stsp->_D().get_row ( 0 ), vec ( "2.30" ), 0.0001 ); 39 39 } 40 40 41 TEST (to_state_arx_test) {41 TEST ( to_state_arx_test ) { 42 42 mlnorm<fsqmat> ml; 43 mat A ="1.1, 2.3";44 ml.set_parameters (A, vec_1(1.3), eye(1));45 RV yr =RV("y",1);46 RV ur =RV("u",1);47 ml.set_rv (yr);48 yr.t_plus (-1);49 ml.set_rvc (concat(yr, ur));50 51 shared_ptr<StateFromARX> Stsp =new StateFromARX;52 Stsp->connect_mlnorm (ml);53 54 /* results from 43 mat A = "1.1, 2.3"; 44 ml.set_parameters ( A, vec_1 ( 1.3 ), eye ( 1 ) ); 45 RV yr = RV ( "y", 1 ); 46 RV ur = RV ( "u", 1 ); 47 ml.set_rv ( yr ); 48 yr.t_plus ( -1 ); 49 ml.set_rvc ( concat ( yr, ur ) ); 50 51 shared_ptr<StateFromARX> Stsp = new StateFromARX; 52 Stsp->connect_mlnorm ( ml ); 53 54 /* results from 55 55 [A,B,C,D]=tf2ss([2.3 0],[1 -1.1]) 56 56 */ … … 58 58 } 59 59 60 TEST (arx_LQG_test){60 TEST ( arx_LQG_test ) { 61 61 mlnorm<fsqmat> ml; 62 mat A ="1.81, -.8189, .00468, .00438";63 ml.set_parameters (A, vec_1(0.0), 0.00001*eye(1));64 RV yr =RV("y",1);65 RV ur =RV("u",1);66 RV rgr = yr.copy_t (-1);67 rgr.add (yr.copy_t(-2));68 rgr.add (yr.copy_t(-2));69 rgr.add (ur.copy_t(-2));70 rgr.add (ur.copy_t(-1));71 72 ml.set_rv (yr);73 ml.set_rvc (rgr);62 mat A = "1.81, -.8189, .00468, .00438"; 63 ml.set_parameters ( A, vec_1 ( 0.0 ), 0.00001*eye ( 1 ) ); 64 RV yr = RV ( "y", 1 ); 65 RV ur = RV ( "u", 1 ); 66 RV rgr = yr.copy_t ( -1 ); 67 rgr.add ( yr.copy_t ( -2 ) ); 68 rgr.add ( yr.copy_t ( -2 ) ); 69 rgr.add ( ur.copy_t ( -2 ) ); 70 rgr.add ( ur.copy_t ( -1 ) ); 71 72 ml.set_rv ( yr ); 73 ml.set_rvc ( rgr ); 74 74 ml.validate(); 75 76 shared_ptr<StateCanonical > Stsp =new StateCanonical;77 Stsp->connect_mlnorm (ml);78 75 76 shared_ptr<StateCanonical > Stsp = new StateCanonical; 77 Stsp->connect_mlnorm ( ml ); 78 79 79 LQG L; 80 L.set_system (Stsp);81 L.set_control_parameters (eye(1), eye(1), vec_1(0.0), 100);80 L.set_system ( Stsp ); 81 L.set_control_parameters ( eye ( 1 ), eye ( 1 ), vec_1 ( 0.0 ), 100 ); 82 82 L.validate(); 83 83 84 84 L.redesign(); 85 cout << L.to_string() <<endl;85 cout << L.to_string() << endl; 86 86 } -
library/tests/testsuite/arx_straux_test.cpp
r717 r722 8 8 UIFile F ( "arx_straux_test.cfg" ); 9 9 10 Setting &tests =F.getRoot() ["tests"];11 for ( int i =0;i<tests.getLength(); i++ ) {10 Setting &tests = F.getRoot() ["tests"]; 11 for ( int i = 0; i < tests.getLength(); i++ ) { 12 12 mat A; 13 13 mat B; 14 14 ivec o1_ok; 15 UI::get ( A, tests[i],"A",UI::compulsory );16 UI::get ( B, tests[i],"B",UI::compulsory );17 UI::get ( o1_ok, tests[i],"o1",UI::compulsory );15 UI::get ( A, tests[i], "A", UI::compulsory ); 16 UI::get ( B, tests[i], "B", UI::compulsory ); 17 UI::get ( o1_ok, tests[i], "o1", UI::compulsory ); 18 18 19 19 //when updateing matrices do not forget to update CHECK_EQUAL below!!! 20 20 21 ldmat Ld0 ( 3 ); Ld0.ldform ( A,ones ( A.rows() ) ); 22 ldmat Ld1 ( 3 ); Ld1.ldform ( A+B,ones ( A.rows() ) ); 21 ldmat Ld0 ( 3 ); 22 Ld0.ldform ( A, ones ( A.rows() ) ); 23 ldmat Ld1 ( 3 ); 24 Ld1.ldform ( A + B, ones ( A.rows() ) ); 23 25 24 26 … … 27 29 int nrep = 5; // nrep: number of random repetions of structure estimation 28 30 double lambda = 0.9; 29 int k =2;31 int k = 2; 30 32 31 33 //[strout, rgrsout, statistics] = … … 33 35 // order_k); 34 36 Array<str_aux> o2; 35 ivec o1 = straux1 ( Ld1, 20, Ld0, 10, belief, nbest, nrep, lambda, k, o2 );37 ivec o1 = straux1 ( Ld1, 20, Ld0, 10, belief, nbest, nrep, lambda, k, o2 ); 36 38 37 39 //o1 is messed up in matlab's straux -
library/tests/testsuite/datalink_test.cpp
r717 r722 91 91 RV a = RV ( "{dl_a }" ); 92 92 RV b = RV ( "{dlb }" ); 93 RV ab =concat(a,b);93 RV ab = concat ( a, b ); 94 94 RV aa = a; 95 a.t_plus (-1);96 aa.add (a);95 a.t_plus ( -1 ); 96 aa.add ( a ); 97 97 98 98 99 99 datalink_buffered dl; 100 dl.set_connection ( concat (aa,b), ab);100 dl.set_connection ( concat ( aa, b ), ab ); 101 101 102 102 vec val_up ( "1 2" ); 103 dl.step (val_up);104 val_up ="3 4";105 106 103 dl.step ( val_up ); 104 val_up = "3 4"; 105 106 107 107 vec p = dl.pushdown ( val_up ); 108 108 vec exp_p = " 3, 1, 4 "; -
library/tests/testsuite/datasource_test.cpp
r717 r722 7 7 8 8 TEST ( EpdfDS_test ) { 9 UIFile uif ("epdfds.cfg");9 UIFile uif ( "epdfds.cfg" ); 10 10 11 shared_ptr<EpdfDS> ds =UI::build<EpdfDS>(uif, "ds");12 13 vec mean = zeros (2);14 vec dt = zeros (2);15 for ( int i=0; i<100; i++){11 shared_ptr<EpdfDS> ds = UI::build<EpdfDS> ( uif, "ds" ); 12 13 vec mean = zeros ( 2 ); 14 vec dt = zeros ( 2 ); 15 for ( int i = 0; i < 100; i++ ) { 16 16 ds->step(); 17 ds->getdata (dt);17 ds->getdata ( dt ); 18 18 mean += dt; 19 19 } 20 CHECK_CLOSE_EX ( vec_2(1.0,2.0) ,mean/100, 1e-2);20 CHECK_CLOSE_EX ( vec_2 ( 1.0, 2.0 ) , mean / 100, 1e-2 ); 21 21 } 22 22 23 23 TEST ( PdfDS_test ) { 24 UIFile uif ("pdfds.cfg");24 UIFile uif ( "pdfds.cfg" ); 25 25 26 shared_ptr<PdfDS> ds =UI::build<PdfDS>(uif, "ds", UI::compulsory);27 28 vec dt = zeros (2);29 vec ut ="1.0";30 ds->write (ut);31 for ( int i=0; i<100; i++){26 shared_ptr<PdfDS> ds = UI::build<PdfDS> ( uif, "ds", UI::compulsory ); 27 28 vec dt = zeros ( 2 ); 29 vec ut = "1.0"; 30 ds->write ( ut ); 31 for ( int i = 0; i < 100; i++ ) { 32 32 ds->step(); 33 33 } 34 ds->getdata (dt);35 CHECK_CLOSE ( -0.2 , dt (0), 1e-4);34 ds->getdata ( dt ); 35 CHECK_CLOSE ( -0.2 , dt ( 0 ), 1e-4 ); 36 36 37 ut ="2.0";38 ds->write (ut);39 for ( int i=0; i<100; i++){37 ut = "2.0"; 38 ds->write ( ut ); 39 for ( int i = 0; i < 100; i++ ) { 40 40 ds->step(); 41 41 } 42 ds->getdata (dt);43 CHECK_CLOSE ( -0.4 , dt (0), 1e-4);42 ds->getdata ( dt ); 43 CHECK_CLOSE ( -0.4 , dt ( 0 ), 1e-4 ); 44 44 } 45 45 46 TEST (StateDS_test){47 RV y ("y",1);48 RV u ("u",1);49 RV x ("x",2);50 46 TEST ( StateDS_test ) { 47 RV y ( "y", 1 ); 48 RV u ( "u", 1 ); 49 RV x ( "x", 2 ); 50 51 51 shared_ptr<mlnorm<fsqmat> > IM = new mlnorm<fsqmat>; 52 IM->set_parameters (mat("1 2 0.5; 0 1 0.3"), zeros(2), fsqmat(1e-10*eye(2)));53 IM->set_rv (x);54 IM->set_rvc (concat(x.copy_t(-1), u));52 IM->set_parameters ( mat ( "1 2 0.5; 0 1 0.3" ), zeros ( 2 ), fsqmat ( 1e-10*eye ( 2 ) ) ); 53 IM->set_rv ( x ); 54 IM->set_rvc ( concat ( x.copy_t ( -1 ), u ) ); 55 55 IM->validate(); 56 56 57 57 shared_ptr<mlnorm<fsqmat> > OM = new mlnorm<fsqmat>; 58 OM->set_parameters (mat("1 0"), zeros(1), fsqmat(1e-10*eye(1)));59 OM->set_rv (y);60 OM->set_rvc (x);58 OM->set_parameters ( mat ( "1 0" ), zeros ( 1 ), fsqmat ( 1e-10*eye ( 1 ) ) ); 59 OM->set_rv ( y ); 60 OM->set_rvc ( x ); 61 61 OM->validate(); 62 62 63 63 StateDS sds; 64 sds.set_parameters (IM,OM);64 sds.set_parameters ( IM, OM ); 65 65 sds.validate(); 66 67 for ( int t=1; t<10;t++){68 sds.write (vec_1(double(t)));66 67 for ( int t = 1; t < 10; t++ ) { 68 sds.write ( vec_1 ( double ( t ) ) ); 69 69 sds.step(); 70 70 } 71 71 72 vec dt; sds.getdata(dt); 73 CHECK_CLOSE(vec("94.5, 94.5, 13.5, 9"), dt, 1e-2); 72 vec dt; 73 sds.getdata ( dt ); 74 CHECK_CLOSE ( vec ( "94.5, 94.5, 13.5, 9" ), dt, 1e-2 ); 74 75 } -
library/tests/testsuite/egiw_test.cpp
r717 r722 45 45 int n = 100; 46 46 rectangular_support Sup; 47 Sup.set_parameters ("{[-2.,4.], [1.,5.], [0.,2.]} ", n*ones_i(E.dimension()));48 49 double summ = exp (E.evallog(Sup.first_vec()));47 Sup.set_parameters ( "{[-2.,4.], [1.,5.], [0.,2.]} ", n*ones_i ( E.dimension() ) ); 48 49 double summ = exp ( E.evallog ( Sup.first_vec() ) ); 50 50 // sum all likelihood at all points of support 51 51 for ( int k = 1; k < Sup.points(); k++ ) { // ALL b 52 summ += exp ( E.evallog(Sup.next_vec()));52 summ += exp ( E.evallog ( Sup.next_vec() ) ); 53 53 } 54 54 55 CHECK_CLOSE ( 1.0, summ*prod (Sup._steps()), 0.01 );55 CHECK_CLOSE ( 1.0, summ*prod ( Sup._steps() ), 0.01 ); 56 56 } 57 57 -
library/tests/testsuite/emix_test.cpp
r721 r722 13 13 static void check_mean ( emix &distrib_obj, int nsamples, const vec &mean, double tolerance ); 14 14 15 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance );15 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ); 16 16 17 17 TEST ( emix_test ) { … … 46 46 pdf_ptr Ac = E1->condition ( y ); 47 47 48 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *> ( Ac.get() );49 CHECK (wacnd);48 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *> ( Ac.get() ); 49 CHECK ( wacnd ); 50 50 if ( wacnd ) { 51 51 CHECK_CLOSE ( mat ( "-0.349953" ), wacnd->_A(), epsilon ); … … 83 83 84 84 mat observedR ( "0.740142 -0.259015; -0.259015 1.0302" ); 85 check_covariance ( M2, N, observedR, 2.0 );85 check_covariance ( M2, N, observedR, 2.0 ); 86 86 87 87 epdf_ptr Mg = M2.marginal ( y ); … … 97 97 static void check_mean ( emix &distrib_obj, int nsamples, const vec &mean, double tolerance ) { 98 98 int tc = 0; 99 Array<vec> actual (CurrentContext::max_trial_count);99 Array<vec> actual ( CurrentContext::max_trial_count ); 100 100 do { 101 101 mat smp = distrib_obj.sample_mat ( nsamples ); 102 102 vec emu = sum ( smp, 2 ) / nsamples; 103 actual ( tc ) = emu;103 actual ( tc ) = emu; 104 104 ++tc; 105 105 } while ( ( tc < CurrentContext::max_trial_count ) && 106 !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) );106 !UnitTest::AreClose ( mean, actual ( tc - 1 ), tolerance ) ); 107 107 if ( ( tc == CurrentContext::max_trial_count ) && 108 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {108 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 109 109 UnitTest::MemoryOutStream stream; 110 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), __LINE__);110 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), __LINE__ ); 111 111 stream << "Expected " << mean << " +/- " << tolerance << " but was " << actual; 112 112 … … 115 115 } 116 116 117 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ) {117 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ) { 118 118 int tc = 0; 119 Array<mat> actual (CurrentContext::max_trial_count);119 Array<mat> actual ( CurrentContext::max_trial_count ); 120 120 do { 121 121 mat smp = distrib_obj.sample_mat ( nsamples ); 122 122 vec emu = sum ( smp, 2 ) / nsamples; 123 123 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 124 actual ( tc ) = er;124 actual ( tc ) = er; 125 125 ++tc; 126 126 } while ( ( tc < CurrentContext::max_trial_count ) && 127 !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) );127 !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 128 128 if ( ( tc == CurrentContext::max_trial_count ) && 129 ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {129 ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 130 130 UnitTest::MemoryOutStream stream; 131 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), __LINE__);131 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), __LINE__ ); 132 132 stream << "Expected " << R << " +/- " << tolerance << " but was " << actual; 133 133 134 134 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 135 135 } 136 136 } -
library/tests/testsuite/epdf_test.cpp
r717 r722 76 76 } 77 77 78 TEST (dirich_test){78 TEST ( dirich_test ) { 79 79 epdf_harness::test_config ( "edirich.cfg" ); 80 80 } -
library/tests/testsuite/logger_test.cpp
r721 r722 22 22 } 23 23 24 int sz = static_cast<int> (st.st_size);24 int sz = static_cast<int> ( st.st_size ); 25 25 if ( sz != st.st_size ) { 26 26 std::string msg = fname; -
library/tests/testsuite/merger_test.cpp
r717 r722 47 47 48 48 vec exp_f1 ( "-7.51551 -7.02066 " 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 CHECK_CLOSE (exp_f1, l_f1, epsilon);49 "-6.54622 -6.09219 " 50 "-5.65856 -5.24534 " 51 "-4.85252 -4.48011 -4.1281 " 52 "-3.7965 -3.48531 -3.19452 " 53 "-2.92414 -2.67417 -2.4446 -2.23544 -2.04668 " 54 "-1.87833 -1.73039 -1.60285 -1.49572 -1.40899 -1.34267 -1.29676 -1.27125 -1.26615 -1.28145 -1.31717 -1.37328 -1.4498 -1.54673 -1.66407 -1.80181 -1.95996 " 55 "-2.13851 -2.33747 -2.55683 -2.79661 " 56 "-3.05678 -3.33737 -3.63836 -3.95975 " 57 "-4.30155 -4.66376 " 58 "-5.04638 -5.4494 -5.87282 " 59 "-6.31665 -6.78089 " 60 "-7.26554 -7.77059 " 61 "-8.29604 -8.84191 " 62 "-9.40818 -9.99485 " 63 "-10.6019 " 64 "-11.2294 -11.8773 " 65 "-12.5456 " 66 "-13.2343 -13.9434 " 67 "-14.6729 " 68 "-15.4229 " 69 "-16.1932 -16.9839 " 70 "-17.7951 " 71 "-18.6266 " 72 "-19.4786 " 73 "-20.3509 " 74 "-21.2437 " 75 "-22.1569 " 76 "-23.0905 " 77 "-24.0444 " 78 "-25.0188 " 79 "-26.0136 " 80 "-27.0288 " 81 "-28.0644 " 82 "-29.1205 " 83 "-30.1969 " 84 "-31.2937 " 85 "-32.4109 " 86 "-33.5486 " 87 "-34.7066 " 88 "-35.8851 " 89 "-37.0839 " 90 "-38.3032 " 91 "-39.5429 " 92 "-40.8029 " 93 "-42.0834 " 94 "-43.3843 " 95 "-44.7056 " 96 "-46.0473 " 97 "-47.4094 " 98 "-48.7919 " 99 "-50.1948 " 100 "-51.6182 " 101 "-53.0619 " 102 "-54.526 " 103 "-56.0106 " 104 "-57.5155" ); 105 CHECK_CLOSE ( exp_f1, l_f1, epsilon ); 106 106 107 107 vec exp_f2 ( "-13.3202 -13.0192 " 108 109 110 111 112 113 114 115 116 117 118 119 120 CHECK_CLOSE (exp_f2, l_f2, epsilon);108 "-12.7223 -12.4295 -12.1408 " 109 "-11.8561 -11.5755 -11.299 -11.0266 " 110 "-10.7582 -10.494 -10.2338 " 111 "-9.97772 -9.7257 -9.47777 -9.23391 " 112 "-8.99414 -8.75845 -8.52684 -8.29931 -8.07587 " 113 "-7.8565 -7.64122 -7.43002 -7.22289 -7.01985 " 114 "-6.82089 -6.62602 -6.43522 -6.2485 -6.06587 " 115 "-5.88732 -5.71284 -5.54245 -5.37614 -5.21392 -5.05577 " 116 "-4.9017 -4.75172 -4.60581 -4.46399 -4.32625 -4.19259 -4.06301 " 117 "-3.93752 -3.8161 -3.69876 -3.58551 -3.47634 -3.37125 -3.27024 -3.17331 -3.08046 " 118 "-2.99169 -2.90701 -2.8264 -2.74988 -2.67744 -2.60908 -2.5448 -2.4846 -2.42849 -2.37645 -2.3285 -2.28462 -2.24483 -2.20912 -2.17749 -2.14994 -2.12648 -2.10709 -2.09179 -2.08056 -2.07342 -2.07036 -2.07138 -2.07648 -2.08566 -2.09893 -2.11627 -2.1377 -2.16321 -2.1928 -2.22647 -2.26422 -2.30605 -2.35196 -2.40196 -2.45603 -2.51419 -2.57643 -2.64275 -2.71315 -2.78763 -2.8662 -2.94884 " 119 "-3.03557 -3.12637 -3.22126 -3.32023" ); 120 CHECK_CLOSE ( exp_f2, l_f2, epsilon ); 121 121 122 122 vec exp_m2 ( "-7.95304 -7.47281 -7.01175 " 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 CHECK_CLOSE (exp_m2, m2, epsilon);123 "-6.56987 -6.14716 " 124 "-5.74362 -5.35927 " 125 "-4.99408 -4.64808 -4.32125 -4.01359 " 126 "-3.72511 -3.45581 -3.20568 " 127 "-2.97473 -2.76295 -2.57035 -2.39692 -2.24267 -2.1076 " 128 "-1.9917 -1.89498 -1.81743 -1.75905 -1.71986 -1.69984 -1.69899 -1.71732 -1.75483 -1.81151 -1.88736 -1.9824 " 129 "-2.0966 -2.22999 -2.38255 -2.55428 -2.74519 -2.95528 " 130 "-3.18454 -3.43298 -3.70059 -3.98738 " 131 "-4.2008 -4.10829 -4.0211 " 132 "-3.93921 -3.86263 -3.79137 -3.72542 -3.66478 -3.60945 -3.55944 -3.51473 -3.47534 -3.44126 -3.41249 -3.38903 -3.37088 -3.35805 -3.35053 -3.34831 -3.35141 -3.35983 -3.37355 -3.39259 -3.41693 -3.44659 -3.48156 -3.52185 -3.56744 -3.61835 -3.67457 -3.73609 -3.80294 -3.87509 -3.95255 " 133 "-4.03533 -4.12342 -4.21682 -4.31553 -4.41955 -4.52889 -4.64353 -4.76349 -4.88876 " 134 "-5.01934 -5.15524 -5.29644 -5.44296 -5.59479 -5.75193 -5.91438 " 135 "-6.08214 -6.25522 -6.4336 -6.6173 -6.80631 " 136 "-7.00064 -7.20027 -7.40522" ); 137 CHECK_CLOSE ( exp_m2, m2, epsilon ); 138 138 } 139 139 … … 142 142 143 143 shared_ptr<merger_base> mb = 144 144 UI::build<merger_base> ( in, "Merger", UI::compulsory ); 145 145 146 146 pdf_array sources; … … 148 148 mb->set_sources ( sources ); 149 149 150 shared_ptr<rectangular_support> support = 151 152 mb->set_support ( *support );150 shared_ptr<rectangular_support> support = 151 UI::build<rectangular_support> ( in, "Support", UI::compulsory ); 152 mb->set_support ( *support ); 153 153 154 154 mb->merge(); -
library/tests/testsuite/randun_test.cpp
r717 r722 5 5 using namespace itpp; 6 6 7 TEST(test_randun) {7 TEST ( test_randun ) { 8 8 // matlab output obtained by 9 9 // >>clear all 10 10 // >>randun(10); 11 vec matlab_out=" 0.695964974209650, 0.083321541586575, 0.385149445564090, 0.206731595660901, 0.537928272754852, 0.960480190795139, 0.790566693893898, 0.054424274738144, 0.708785523990535, 0.558301708920999";11 vec matlab_out = " 0.695964974209650, 0.083321541586575, 0.385149445564090, 0.206731595660901, 0.537928272754852, 0.960480190795139, 0.790566693893898, 0.054424274738144, 0.708785523990535, 0.558301708920999"; 12 12 13 13 //ASSUMING randun was not used yet! 14 vec x = randun(10);15 CHECK_CLOSE(matlab_out, x, 1e-6);16 14 vec x = randun ( 10 ); 15 CHECK_CLOSE ( matlab_out, x, 1e-6 ); 16 } 17 17 -
library/tests/testsuite/rectangular_support_test.cpp
r717 r722 20 20 CHECK_EQUAL ( 200, rs.points() ); 21 21 22 vec v = rs.get_vec ( ivec ( "1 2" ) );23 CHECK_CLOSE ( vec ( "0.15 -0.75" ), v, epsilon );22 vec v = rs.get_vec ( ivec ( "1 2" ) ); 23 CHECK_CLOSE ( vec ( "0.15 -0.75" ), v, epsilon ); 24 24 } 25 25 -
library/tests/testsuite/rv_test.cpp
r717 r722 8 8 TEST ( rv_test ) { 9 9 RV::clear_all(); 10 10 11 11 RV a = RV ( "{a_in_test_rv }", "3" ); 12 12 CHECK ( a.equal ( a ) ); … … 133 133 CHECK_EQUAL ( exp_bi[i], bi ( i ) ); 134 134 } 135 135 136 136 // check uniqueness 137 RV join=a; 138 join.add(b); 139 RV tmp=a; tmp.t_plus(1); 140 join.add(tmp); 141 tmp=b; tmp.t_plus(-1); 142 join.add(tmp); 143 144 CHECK_EQUAL(unique(join._ids()), vec_2(a.id(0), b.id(0))); // find only ids of a and b 145 CHECK_EQUAL(unique_complement(join._ids(), vec_1(a.id(0))), vec_1(b.id(0))); // complemnet of a in previous is b 137 RV join = a; 138 join.add ( b ); 139 RV tmp = a; 140 tmp.t_plus ( 1 ); 141 join.add ( tmp ); 142 tmp = b; 143 tmp.t_plus ( -1 ); 144 join.add ( tmp ); 145 146 CHECK_EQUAL ( unique ( join._ids() ), vec_2 ( a.id ( 0 ), b.id ( 0 ) ) ); // find only ids of a and b 147 CHECK_EQUAL ( unique_complement ( join._ids(), vec_1 ( a.id ( 0 ) ) ), vec_1 ( b.id ( 0 ) ) ); // complemnet of a in previous is b 146 148 147 149 //test if unique names work 148 RV uniq1 ("y",1);149 RV uniq2 ("y",1);150 151 CHECK_EQUAL (uniq1.id(0), uniq2.id(0));152 150 RV uniq1 ( "y", 1 ); 151 RV uniq2 ( "y", 1 ); 152 153 CHECK_EQUAL ( uniq1.id ( 0 ), uniq2.id ( 0 ) ); 154 153 155 // check scalarname 154 CHECK_EQUAL ("a_in_test_rv_2", abc.scalarname(2));155 CHECK_EQUAL ("b_in_test_rv_0", abc.scalarname(3));156 CHECK_EQUAL ( "a_in_test_rv_2", abc.scalarname ( 2 ) ); 157 CHECK_EQUAL ( "b_in_test_rv_0", abc.scalarname ( 3 ) ); 156 158 } -
library/tests/testsuite/shared_ptr_test.cpp
r717 r722 93 93 bdm::shared_ptr<Foo> empty; 94 94 try { 95 Foo x (*empty);95 Foo x ( *empty ); 96 96 CHECK ( false ); 97 97 } catch ( std::runtime_error &exc ) { -
library/tests/testsuite/testsuite.cpp
r721 r722 5 5 #include "itpp_ext.h" 6 6 #include <string.h> 7 #include "../general_suite.h" 7 8 8 using std::cout; 9 using std::cerr; 10 using std::endl; 11 12 using namespace itpp; 13 14 Array<const char *> selected_tests; 15 16 bool is_selected_test ( const UnitTest::Test *test ) { 17 bdm_assert_debug ( test, "NULL test" ); 18 19 if ( !selected_tests.length() ) { 20 return true; 21 } 22 23 for ( int i = 0; i < selected_tests.length(); ++i ) { 24 const char *n = test->m_details.testName; 25 bdm_assert_debug ( n, "NULL test name" ); 26 const char *sname = selected_tests ( i ); 27 bdm_assert_debug ( sname, "NULL selected test name" ); 28 if ( !strcmp ( n, sname ) ) { 29 return true; 30 } 31 } 32 33 return false; 34 } 9 using namespace UnitTest; 35 10 36 11 int main ( int argc, char const *argv[] ) { 37 12 if ( argc > 1 ) { 38 if ( !strcmp ( argv[1], "print" ) ) { 39 UnitTest::Test* curTest = UnitTest::Test::GetTestList().GetHead(); 40 41 while ( curTest != 0 ) { 42 const char *n = curTest->m_details.testName; 43 printf ( "%s\n", n ); 44 curTest = curTest->next; 45 } 46 return 0; 47 } else { 48 selected_tests.set_length ( argc - 1 ); 49 const char **param = argv + 1; 50 int i = 0; 51 while ( *param ) { 52 selected_tests ( i ) = *param; 53 ++i; 54 ++param; 55 } 56 } 13 if ( !strcmp ( argv[1], "print" ) ) 14 print_test_list(); 15 else 16 pick_selected_tests ( argc, argv ); 57 17 } else { 58 cout << endl << "TESTSUITE - a program covering all BDM unit tests." << endl << endl 59 << argv[0] << " ....................................... run all unit tests" << endl 60 << argv[0] << " particular_test_1 particular_test_2 ... run selected unit tests" << endl 18 cout << endl << "TESTSUITE - a program covering all BDM unit tests." << endl << endl 19 << argv[0] << " ....................................... run all unit tests" << endl 20 << argv[0] << " particular_test_1 particular_test_2 ... run selected unit tests" << endl 61 21 << argv[0] << " print ................................. print all the implemented unit tests" << endl; 62 22 } 63 23 64 itpp::RNG_randomize(); 65 66 UnitTest::TestReporterStdout reporter; 67 UnitTest::TestRunner runner ( reporter ); 68 return runner.RunTestsIf ( UnitTest::Test::GetTestList(), 69 0, 70 is_selected_test, 71 0 ); 24 return run_selected_tests(); 72 25 } -
library/tests/testsuite/user_info_test.cpp
r721 r722 33 33 } 34 34 35 string to_string() const {35 string to_string() const { 36 36 return name; 37 37 } … … 61 61 } 62 62 63 string to_string() const {63 string to_string() const { 64 64 stringstream stream; 65 65 stream << number; … … 77 77 string manufacturer; 78 78 79 Transport() : year ( 1900 ), manufacturer( "unknown" ) {79 Transport() : year ( 1900 ), manufacturer ( "unknown" ) { 80 80 } 81 81 82 82 Transport ( int year, string manufacturer ) : 83 year ( year ), manufacturer ( manufacturer ) {83 year ( year ), manufacturer ( manufacturer ) { 84 84 } 85 85 … … 128 128 } 129 129 130 string to_string() const {130 string to_string() const { 131 131 stringstream stream; 132 132 stream << "A car made in " << year << " by " << manufacturer << ", having " << kilometers << " kilometers on the clock."; … … 163 163 int elights; 164 164 if ( UI::get ( elights, set, "electricLights", UI::optional ) ) { 165 165 electricLights = !!elights; 166 166 } 167 167 … … 178 178 } 179 179 180 string to_string() const {180 string to_string() const { 181 181 stringstream stream; 182 182 stream << "a bike made in " << year << " by " << manufacturer; -
library/tests/tutorial/arx_simple.cpp
r682 r722 9 9 ARX Ar; 10 10 Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 11 Ar.set_constant (true);11 Ar.set_constant ( true ); 12 12 Ar.validate(); 13 13 // forgetting is default: 1.0 -
library/tests/tutorial/kalman_simple.cpp
r679 r722 23 23 // Estimation loop 24 24 for ( int i = 0; i < 100; i++ ) { 25 KF.bayes ( randn ( dy ), randn( du ) );25 KF.bayes ( randn ( dy ), randn ( du ) ); 26 26 } 27 27 //print results