Changeset 557

Show
Ignore:
Timestamp:
08/19/09 01:41:23 (15 years ago)
Author:
smidl
Message:

egiw_1_2 test reimplemented using rectangular_support - similar can be done for general epdf_harness

Location:
library
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/discrete.h

    r556 r557  
    5959                                 
    6060                                //precompute steps 
     61                                steps.set_size(dim); 
    6162                                for ( int j = 0; j < dim; j++ ) { 
    6263                                        steps ( j ) = ( ranges ( j ) ( 1 ) - ranges(j)(0) ) / gridsizes ( j ); 
     
    8081                                        if ( actvec_ind ( j ) == gridsizes ( j ) - 1 ) { //j-th index is full 
    8182                                                actvec_ind ( j ) = 0; //shift back 
    82                                                 actvec ( j ) = ranges ( j ) ( 0 ); 
     83                                                actvec ( j ) = ranges ( j ) ( 0 ) + 0.5*steps(j); 
    8384 
    84                                                 if ( j+1<dim) { 
    85                                                         actvec_ind ( j + 1 ) ++; //increase the next dimension; 
    86                                                         actvec ( j + 1 ) += steps ( j + 1 ); 
    87                                                         break; 
    88                                                 } 
     85                                                //!  
     86                                                if ( j+1<dim) 
     87                                                        if (actvec_ind ( j + 1 )<gridsizes(j+1)-1){ 
     88                                                                actvec_ind ( j + 1 ) ++; //increase the next dimension; 
     89                                                                actvec ( j + 1 ) += steps ( j + 1 ); 
     90                                                                break; 
     91                                                        } 
    8992 
    9093                                        } else { 
     
    9598                                } 
    9699                                return actvec; 
    97                         } 
    98  
     100                        }  
     101                        //! Access function 
    99102                        int points() const {return Npoints;} 
     103                         
     104                        //! access function 
     105                        const vec& _steps() const {return steps;} 
    100106                         
    101107                        void from_setting (const Setting &set) { 
  • library/tests/egiw_test.cpp

    r493 r557  
    22#include "base/user_info.h" 
    33#include "stat/exp_family.h" 
     4#include "stat/discrete.h" 
    45#include "itpp_ext.h" 
    56#include "epdf_harness.h" 
     
    4445 
    4546        int n = 100; 
    46         vec rgr ( 3 ); 
    47  
    48         mat Tmp ( 2 * n, n ); 
    49  
    50         double summ = 0.0; 
    51         for ( int k = 0; k < n; k++ ) { // ALL b 
    52                 rgr ( 1 ) = 1 + k * ( 1.0 / n ) * 4.0; 
    53                 for ( int i = 0; i < 2*n; i++ ) { //ALL mu 
    54                         rgr ( 0 ) = -2 + i * ( 1.0 / n ) * 3.0; 
    55                         for ( int j = 0; j < n; j++ ) { // All sigma 
    56                                 rgr ( 2 ) = ( j + 1 ) * ( 1.0 / n ) * 2.0; 
    57  
    58                                 Tmp ( i, j ) = E.evallog ( rgr ); 
    59                         } 
    60                 } 
    61                 summ += sumsum ( exp ( Tmp ) ) / n / n / n * 3.0 * 2.0 * 4.0; 
     47        rectangular_support Sup; 
     48        Sup.set_parameters("{[-2.,4.], [1.,5.], [0.,2.]} ", n*ones_i(E.dimension())); 
     49         
     50        double summ = exp(E.evallog(Sup.first_vec())); 
     51        // sum all likelihood at all points of support 
     52        for ( int k = 1; k < Sup.points(); k++ ) { // ALL b 
     53                summ += exp (E.evallog(Sup.next_vec())); 
    6254        } 
    6355 
    64         CHECK_CLOSE ( 1.0, summ, 0.1 ); 
     56        CHECK_CLOSE ( 1.0, summ*prod(Sup._steps()), 0.01 ); 
    6557} 
    6658