Show
Ignore:
Timestamp:
07/31/09 15:17:20 (15 years ago)
Author:
vbarta
Message:

moved test of marginal & condition to epdf_harness

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/epdf_harness.cpp

    r461 r462  
    33#include "base/user_info.h" 
    44#include "stat/exp_family.h" 
     5#include "stat/emix.h" 
    56#include "mat_checks.h" 
    67#include "test_util.h" 
    78#include "UnitTest++.h" 
     9#include <memory> 
    810 
    911namespace bdm { 
     
    4749    } 
    4850 
     51    if (set.exists("marginal_rv")) { 
     52        mrv = shared_ptr<RV>(UI::build<RV>(set, "marginal_rv")); 
     53    } 
     54 
    4955    if (set.exists("tolerance")) { 
    5056        UI::get(tolerance, set, "tolerance"); 
     
    7379        } 
    7480 
    75         CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
    76         CHECK_CLOSE_EX(1.0, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
     81        CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), tolerance); 
     82        CHECK_CLOSE_EX(1.0, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), tolerance); 
    7783    } 
    7884 
     
    8591        CHECK_CLOSE_EX(R, er, tolerance); 
    8692    } 
     93 
     94    if (mrv.get()) { 
     95        RV crv = hepdf->_rv().subt(*mrv); 
     96        shared_ptr<epdf> m = hepdf->marginal(*mrv); 
     97        shared_ptr<mpdf> c = hepdf->condition(crv); 
     98        mepdf mm(m); 
     99 
     100        Array<mpdf *> aa(2); 
     101        aa(0) = c.get(); 
     102        aa(1) = &mm; 
     103        mprod mEp(aa); 
     104 
     105        int n = nsamples; 
     106        mat smp = mEp.samplecond(vec(0), n); 
     107        vec emu = sum(smp, 2) / n; 
     108        CHECK_CLOSE_EX(mean, emu, tolerance); 
     109 
     110        if (R.rows() > 0) { 
     111            mat er = (smp * smp.T()) / n - outer_product(emu, emu); 
     112            CHECK_CLOSE_EX(R, er, tolerance); 
     113        } 
     114 
     115        // test of pdflog at zero 
     116        vec zero(0); 
     117        vec zeron(hepdf->dimension()); 
     118        for (int i = 0; i < zeron.size(); ++i) { 
     119            zeron(i) = 0; 
     120        } 
     121 
     122        CHECK_CLOSE_EX(hepdf->evallog(zeron), mEp.evallogcond(zeron, zero), tolerance); 
     123    } 
    87124} 
    88125