46 | | if ( support.rows() == 2 ) { |
47 | | int old_size = nbins.size(); |
48 | | if ( old_size < 2 ) { |
49 | | ivec new_nbins ( "100 100" ); |
50 | | for ( int i = 0; i < old_size; ++i ) { |
51 | | new_nbins ( i ) = nbins ( i ); |
52 | | } |
53 | | |
54 | | nbins = new_nbins; |
55 | | } |
56 | | |
57 | | check_support_mean(); |
58 | | check_support_integral(); |
| 45 | if ( support ) { // support is given |
| 46 | grid_fnc ep_disc; |
| 47 | ep_disc.set_support(*support); |
| 48 | ep_disc.set_values(*hepdf); |
| 49 | // ep_disc is discretized at support points |
| 50 | |
| 51 | double point_volume =prod(support->_steps()); |
| 52 | CHECK_CLOSE(1.0, sum(ep_disc._values())*point_volume, 0.01); |
| 53 | |
| 54 | vec pdf=ep_disc._values(); |
| 55 | pdf /=sum(pdf); // normalize |
| 56 | |
| 57 | vec mea=pdf(0) * support->first_vec(); |
| 58 | mat Remp=pdf(0) * outer_product(support->act_vec(), support->act_vec()); |
| 59 | |
| 60 | // run through all points |
| 61 | for (int i=1; i<support->points(); i++){ |
| 62 | mea += pdf(i)*support->next_vec(); |
| 63 | Remp += pdf(i) * outer_product(support->act_vec(), support->act_vec()); |
| 64 | } |
| 65 | CHECK_CLOSE(mean, mea, tolerance); |
| 66 | CHECK_CLOSE(R, Remp-outer_product(mea,mea), tolerance); |
114 | | void epdf_harness::check_support_mean() { |
115 | | vec xb = support.get_row ( 0 ); |
116 | | vec yb = support.get_row ( 1 ); |
117 | | |
118 | | vec actual; |
119 | | actual = num_mean2 ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); |
120 | | |
121 | | CHECK_CLOSE(mean, actual, tolerance); |
122 | | } |
123 | | |
124 | | void epdf_harness::check_support_integral() { |
125 | | vec xb = support.get_row ( 0 ); |
126 | | vec yb = support.get_row ( 1 ); |
127 | | |
128 | | double nc = normcoef ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); |
129 | | CHECK_CLOSE(1.0,nc,0.01); |
130 | | } |