| 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 | |