Changeset 569

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:
5 modified

Legend:

Unmodified
Added
Removed
  • applications/bdmtoolbox/mex/merger.cpp

    r568 r569  
    9393        } 
    9494        catch (UIException &e) { 
    95                 shared_ptr<epdf> g0 = UI::build<epdf> (Cfg, "Support"); 
    96                 Merger->set_support (*g0, 100); 
     95                shared_ptr<discrete_support> DisSup = UI::build<discrete_support> (Cfg, "Support"); 
     96                Merger->set_support (*DisSup); 
    9797        } 
    9898// COMPUTE RESULTS 
  • applications/bdmtoolbox/tutorial/merging/merge_grid.m

    r568 r569  
    4848 
    4949% 2D support 
    50 type=0; 
     50type=1; 
    5151if type==0 
    5252    support2.class='rectangular_support'; 
     
    5454    support2.gridsizes=[10,10]; 
    5555else 
    56     support2=struct('pdf',... 
    57             struct('class','enorm<ldmat>','mu',[1,2],'R',[2 0; 0 2])); 
    58     support2.nsamples=[100]; 
     56    support2.class='discrete_support'; 
     57    support2.epdf= struct('class','enorm<ldmat>','mu',[1,2],'R',[2 0; 0 2]); 
     58    support2.npoints=[100]; 
    5959end     
    6060 
     
    6363 
    6464if type==0 
    65     X=zeros(support2.nbins(1)); 
    66     Y=zeros(support2.nbins(1)); 
    67     Z=zeros(support2.nbins(1)); 
     65    X=zeros(support2.gridsizes(1)); 
     66    Y=zeros(support2.gridsizes(1)); 
     67    Z=zeros(support2.gridsizes(1)); 
    6868 
    6969    X(:)=vy2.support(1,:); 
  • 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: 
  • library/bdm/stat/exp_family.h

    r565 r569  
    11451145                //! Set sample 
    11461146                void set_parameters (int n0, bool copy = true) {n = n0; w.set_size (n0, copy);samples.set_size (n0, copy);}; 
     1147                //! Set samples 
     1148                void set_parameters (const Array<vec> &Av) { 
     1149                        bdm_assert_debug(Av.size()>0,"Empty samples");  
     1150                        n = Av.size();  
     1151                        epdf::set_parameters(Av(0).length()); 
     1152                        w=1/n*ones(n); 
     1153                        samples=Av; 
     1154                }; 
    11471155                //! Potentially dangerous, use with care. 
    11481156                vec& _w()  {return w;}; 
  • library/bdm/stat/merger.h

    r565 r569  
    143143                        samples ( j ) = Sup.next_vec(); 
    144144                } 
     145        } 
     146        //! Set support points from dicrete grid 
     147        void set_support ( discrete_support &Sup) { 
     148                Npoints = Sup.points(); 
     149                eSmp.set_parameters(Sup._Spoints()); 
    145150        } 
    146151        //! set debug file