| 115 | | } |
| | 97 | void epdf_harness::check_support_mean() { |
| | 98 | vec xb = support.get_row ( 0 ); |
| | 99 | vec yb = support.get_row ( 1 ); |
| | 100 | |
| | 101 | int tc = 0; |
| | 102 | Array<vec> actual(CurrentContext::max_trial_count); |
| | 103 | do { |
| | 104 | vec emu = num_mean2 ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); |
| | 105 | actual( tc ) = emu; |
| | 106 | ++tc; |
| | 107 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 108 | !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) ); |
| | 109 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 110 | ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 111 | UnitTest::MemoryOutStream stream; |
| | 112 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; |
| | 113 | |
| | 114 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 115 | |
| | 116 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 117 | } |
| | 118 | } |
| | 119 | |
| | 120 | void epdf_harness::check_support_integral() { |
| | 121 | vec xb = support.get_row ( 0 ); |
| | 122 | vec yb = support.get_row ( 1 ); |
| | 123 | |
| | 124 | int tc = 0; |
| | 125 | Array<double> actual(CurrentContext::max_trial_count); |
| | 126 | do { |
| | 127 | double nc = normcoef ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); |
| | 128 | actual( tc ) = nc; |
| | 129 | ++tc; |
| | 130 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 131 | !UnitTest::AreClose ( 1.0, actual( tc - 1 ), tolerance ) ); |
| | 132 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 133 | ( !UnitTest::AreClose ( 1.0, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 134 | UnitTest::MemoryOutStream stream; |
| | 135 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; |
| | 136 | |
| | 137 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 138 | |
| | 139 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 140 | } |
| | 141 | } |
| | 142 | |
| | 143 | void epdf_harness::check_sample_mean() { |
| | 144 | // simplify overloading for Visual Studio |
| | 145 | vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); |
| | 146 | |
| | 147 | int tc = 0; |
| | 148 | Array<vec> actual(CurrentContext::max_trial_count); |
| | 149 | do { |
| | 150 | mat smp = hepdf->sample_m ( nsamples ); |
| | 151 | vec emu = smp * ones ( nsamples ) / nsamples; |
| | 152 | actual( tc ) = emu; |
| | 153 | ++tc; |
| | 154 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 155 | !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); |
| | 156 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 157 | ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { |
| | 158 | UnitTest::MemoryOutStream stream; |
| | 159 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; |
| | 160 | |
| | 161 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 162 | |
| | 163 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 164 | } |
| | 165 | } |
| | 166 | |
| | 167 | |
| | 168 | void epdf_harness::check_covariance() { |
| | 169 | int tc = 0; |
| | 170 | Array<mat> actual(CurrentContext::max_trial_count); |
| | 171 | do { |
| | 172 | mat smp = hepdf->sample_m ( nsamples ); |
| | 173 | vec emu = smp * ones ( nsamples ) / nsamples; |
| | 174 | mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); |
| | 175 | actual( tc ) = er; |
| | 176 | ++tc; |
| | 177 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 178 | !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); |
| | 179 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 180 | ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 181 | UnitTest::MemoryOutStream stream; |
| | 182 | stream << CurrentContext::format_context(__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual; |
| | 183 | |
| | 184 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 185 | |
| | 186 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 187 | } |
| | 188 | } |
| | 189 | |
| | 190 | void epdf_harness::check_cond_mean( mprod &mep ) { |
| | 191 | // simplify overloading for Visual Studio |
| | 192 | vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); |
| | 193 | |
| | 194 | int tc = 0; |
| | 195 | Array<vec> actual(CurrentContext::max_trial_count); |
| | 196 | do { |
| | 197 | mat smp = mep.samplecond ( vec ( 0 ), nsamples ); |
| | 198 | vec emu = sum ( smp, 2 ) / nsamples; |
| | 199 | actual( tc ) = emu; |
| | 200 | ++tc; |
| | 201 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 202 | !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); |
| | 203 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 204 | ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { |
| | 205 | UnitTest::MemoryOutStream stream; |
| | 206 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; |
| | 207 | |
| | 208 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 209 | |
| | 210 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 211 | } |
| | 212 | } |
| | 213 | |
| | 214 | void epdf_harness::check_cond_covariance( mprod &mep ) { |
| | 215 | int tc = 0; |
| | 216 | Array<mat> actual(CurrentContext::max_trial_count); |
| | 217 | do { |
| | 218 | mat smp = mep.samplecond ( vec ( 0 ), nsamples ); |
| | 219 | vec emu = sum ( smp, 2 ) / nsamples; |
| | 220 | mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); |
| | 221 | actual( tc ) = er; |
| | 222 | ++tc; |
| | 223 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 224 | !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); |
| | 225 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 226 | ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 227 | UnitTest::MemoryOutStream stream; |
| | 228 | stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; |
| | 229 | |
| | 230 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); |
| | 231 | |
| | 232 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 233 | } |
| | 234 | } |
| | 235 | |
| | 236 | } |