| | 50 | void mpdf_harness::check_mean() { |
| | 51 | vec delta = make_close_tolerance ( variance, nsamples ); |
| | 52 | |
| | 53 | int tc = 0; |
| | 54 | Array<vec> actual(CurrentContext::max_trial_count); |
| | 55 | do { |
| | 56 | mat smp = hmpdf->samplecond_m ( cond, nsamples ); |
| | 57 | vec emu = smp * ones ( nsamples ) / nsamples; |
| | 58 | actual( tc ) = emu; |
| | 59 | ++tc; |
| | 60 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 61 | !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); |
| | 62 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 63 | ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { |
| | 64 | UnitTest::MemoryOutStream stream; |
| | 65 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; |
| | 66 | |
| | 67 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 68 | |
| | 69 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 70 | } |
| | 72 | |
| | 73 | void mpdf_harness::check_covariance() { |
| | 74 | int tc = 0; |
| | 75 | Array<mat> actual(CurrentContext::max_trial_count); |
| | 76 | do { |
| | 77 | mat smp = hmpdf->samplecond_m ( cond, nsamples ); |
| | 78 | vec emu = smp * ones ( nsamples ) / nsamples; |
| | 79 | mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); |
| | 80 | actual( tc ) = er; |
| | 81 | ++tc; |
| | 82 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 83 | !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); |
| | 84 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 85 | ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 86 | UnitTest::MemoryOutStream stream; |
| | 87 | stream << CurrentContext::format_context(__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual; |
| | 88 | |
| | 89 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 90 | |
| | 91 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 92 | } |
| | 93 | } |
| | 94 | |
| | 95 | } |