Changeset 556

Show
Ignore:
Timestamp:
08/18/09 22:24:54 (15 years ago)
Author:
smidl
Message:

Initial implementation of discrete rectangular grid - will be a base for functions defined on a grid

Location:
library/bdm/stat
Files:
1 added
1 modified

Legend:

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

    r536 r556  
    1616 
    1717#include "../estim/mixtures.h" 
     18#include "discrete.h" 
    1819 
    1920namespace bdm { 
     
    131132                }; 
    132133        } 
    133         //! Rectangular support  each vector of XYZ specifies (begining-end) interval for each dimension. Same number of points, \c dimsize, in each dimension. 
    134         void set_support ( const Array<vec> &XYZ, const int dimsize ) { 
    135                 set_support ( XYZ, dimsize*ones_i ( XYZ.length() ) ); 
    136         } 
    137         //! Rectangular support  each vector of XYZ specifies (begining-end) interval for each dimension. \c gridsize specifies number of points is each dimension. 
    138         void set_support ( const Array<vec> &XYZ, const ivec &gridsize ) { 
    139                 int dim = XYZ.length();  //check with internal dim!! 
    140                 Npoints = prod ( gridsize ); 
     134        //! Set support points from rectangular grid 
     135        void set_support ( rectangular_support &Sup) { 
     136                Npoints = Sup.points(); 
    141137                eSmp.set_parameters ( Npoints, false ); 
    142138                Array<vec> &samples = eSmp._samples(); 
    143139                eSmp._w() = ones ( Npoints ) / Npoints; //unifrom size of bins 
    144140                //set samples 
    145                 ivec ind = zeros_i ( dim );    //indeces of dimensions in for cycle; 
    146                 vec smpi ( dim );          // ith sample 
    147                 vec steps = zeros ( dim );        // ith sample 
    148                 // first corner 
    149                 for ( int j = 0; j < dim; j++ ) { 
    150                         smpi ( j ) = XYZ ( j ) ( 0 ); /* beginning of the interval*/ 
    151                         it_assert ( gridsize ( j ) != 0.0, "Zeros in gridsize!" ); 
    152                         steps ( j ) = ( XYZ ( j ) ( 1 ) - smpi ( j ) ) / gridsize ( j ); 
    153                 } 
    154                 // fill samples 
    155                 for ( int i = 0; i < Npoints; i++ ) { 
    156                         // copy 
    157                         samples ( i ) = smpi; 
    158                         // go through all dimensions 
    159                         for ( int j = 0; j < dim; j++ ) { 
    160                                 if ( ind ( j ) == gridsize ( j ) - 1 ) { //j-th index is full 
    161                                         ind ( j ) = 0; //shift back 
    162                                         smpi ( j ) = XYZ ( j ) ( 0 ); 
    163  
    164                                         if ( i < Npoints - 1 ) { 
    165                                                 ind ( j + 1 ) ++; //increase the next dimension; 
    166                                                 smpi ( j + 1 ) += steps ( j + 1 ); 
    167                                                 break; 
    168                                         } 
    169  
    170                                 } else { 
    171                                         ind ( j ) ++; 
    172                                         smpi ( j ) += steps ( j ); 
    173                                         break; 
    174                                 } 
    175                         } 
     141                samples(0)=Sup.first_vec(); 
     142                for (int j=1; j < Npoints; j++ ) { 
     143                        samples ( j ) = Sup.next_vec(); 
    176144                } 
    177145        }