Show
Ignore:
Timestamp:
08/20/09 00:54:47 (15 years ago)
Author:
smidl
Message:

new object discrete_support, merger adapted to accept this input as well

Files:
1 modified

Legend:

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

    r565 r569  
    2323 
    2424        //! Rectangular support 
    25         //! Support ponits are located inbetween ranges! For example: 
     25        //! Support points are located inbetween ranges! For example: 
    2626        //! For ranges=[0,1] and gridsizes=[1] the support point is 0.5 
    2727        class rectangular_support: public root { 
     
    8989                                return ind; 
    9090                        }  
    91                         //! set the first corner to actvec 
     91                        //! set the first vector to corner and store result in actvec 
    9292                        const vec& first_vec(){ 
    9393                                for ( int j = 0; j < dim; j++ ) { 
     
    146146        UIREGISTER(rectangular_support); 
    147147         
     148        //! Discrete support with stored support points  
     149        class discrete_support: public root{ 
     150                protected: 
     151                        //! storage of support points 
     152                        Array<vec> Spoints; 
     153                        //! index in iterators 
     154                        int idx; 
     155                public: 
     156                        //! Default constructor 
     157                        discrete_support() : Spoints(0), idx(0){} 
     158                        //! Access function 
     159                        int points() const {return Spoints.length();} 
     160                        //! set the first vector to corner and store result in actvec 
     161                        const vec& first_vec(){bdm_assert_debug(Spoints.length()>0,"Empty support");idx=0; return Spoints(idx);} 
     162                        //! set next vector after calling first_vec() 
     163                        const vec& next_vec(){bdm_assert_debug(Spoints.length()>idx-1,"Out of support points"); return Spoints(++idx);} 
     164                         
     165                        /*! 
     166                        \code 
     167                          class = "discrete_support"; 
     168                          points = ( [1,2..], [2,2..], ...); // list of points 
     169                           === OR === 
     170                          epdf = {class="epdf_offspring",...}; // epdf rfom which to sample 
     171                          npoints = 100;                     // number of samples 
     172                        \endcode 
     173                        */ 
     174                        void from_setting (const Setting &set) { 
     175                                UI::get (Spoints, set, "points", UI::compulsory); 
     176                                if (points()<1){ 
     177                                        int npoints; 
     178                                        shared_ptr<epdf> ep= UI::build<epdf>(set, "epdf", UI::compulsory); 
     179                                        if (!UI::get(npoints,set,"npoints",UI::optional)){npoints=100;} 
     180                                         
     181                                        //sample 
     182                                        Spoints.set_size(npoints); 
     183                                        for(int i=0; i<points(); i++){Spoints(i)=ep->sample();} 
     184                                } 
     185                        } 
     186                        //! access function 
     187                        Array<vec> & _Spoints() {return Spoints;} 
     188        }; 
     189        UIREGISTER(discrete_support); 
     190         
    148191        class grid_fnc: public fnc{ 
    149192                protected: