- Timestamp:
- 06/19/09 11:43:48 (16 years ago)
- Location:
- library/bdm
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r384 r388 581 581 class compositepdf { 582 582 protected: 583 //!Number of mpdfs in the composite584 int n;585 583 //! Elements of composition 586 584 Array<mpdf*> mpdfs; 587 public: 588 compositepdf(Array<mpdf*> A0) : n(A0.length()), mpdfs(A0) {}; 585 bool owning_mpdfs; 586 public: 587 compositepdf():mpdfs(0){}; 588 compositepdf(Array<mpdf*> A0, bool own=false){set_elements(A0,own);}; 589 void set_elements(Array<mpdf*> A0, bool own=false) {mpdfs=A0;owning_mpdfs=own;}; 589 590 //! find common rv, flag \param checkoverlap modifies whether overlaps are acceptable 590 591 RV getrv(bool checkoverlap = false); 591 592 //! common rvc of all mpdfs is written to rvc 592 593 void setrvc(const RV &rv, RV &rvc); 594 ~compositepdf(){if (owning_mpdfs) for(int i=0;i<mpdfs.length();i++){delete mpdfs(i);}}; 593 595 }; 594 596 -
library/bdm/base/user_info.h
r384 r388 235 235 return instance; 236 236 } 237 //! VS: addition for root elements 238 template<class T> static T* build( const Setting &element ) 239 { 240 T* instance; 241 from_setting<T>( instance, element ); 242 return instance; 243 } 237 244 238 245 template<class T> static T* build( const Setting &element, const string &name ) -
library/bdm/mex/mex_parser.h
r384 r388 17 17 setAutoConvert(true); 18 18 } 19 19 UImxArray() : Config() { 20 setAutoConvert(true); 21 } 22 void addList(const mxArray *mxarray, const char* name){ 23 Setting & setting = this->getRoot(); //setting is a group 24 Setting & child = setting.add(name,Setting::TypeList); 25 fillList(child,mxarray); 26 } 20 27 private: 21 28 void storeNumeric(Setting &setting, const mxArray *value, string key = "") { -
library/bdm/stat/exp_family.h
r384 r388 155 155 156 156 }; 157 UIREGISTER(enorm<chmat>); 158 UIREGISTER(enorm<ldmat>); 159 UIREGISTER(enorm<fsqmat>); 160 157 161 158 162 /*! -
library/bdm/stat/merger.h
r384 r388 75 75 76 76 //!Empty constructor 77 merger_base () : compositepdf() {DBG =false;dbg_file=NULL;};77 merger_base () : compositepdf() {DBG = false;dbg_file = NULL;}; 78 78 //!Constructor from sources 79 merger_base (const Array<mpdf*> &S ) {set_sources (S);};80 //! Function setting the main internal structures 81 void set_sources (const Array<mpdf*> &Sources ) {82 compositepdf::set_elements (Sources );79 merger_base (const Array<mpdf*> &S, bool own=false) {set_sources (S,own);}; 80 //! Function setting the main internal structures 81 void set_sources (const Array<mpdf*> &Sources, bool own) { 82 compositepdf::set_elements (Sources,own); 83 83 //set sizes 84 84 dls.set_size (Sources.length()); … … 109 109 }; 110 110 } 111 //! Rectangular support each vector of XYZ specifies (begining-end) interval for each dimension. Same number of points, \c dimsize, in each dimension. 112 void set_support (const Array<vec> &XYZ, const int dimsize) { 113 set_support(XYZ,dimsize*ones_i(XYZ.length())); 114 } 115 //! Rectangular support each vector of XYZ specifies (begining-end) interval for each dimension. \c gridsize specifies number of points is each dimension. 116 void set_support (const Array<vec> &XYZ, const ivec &gridsize) { 117 int dim = XYZ.length(); //check with internal dim!! 118 Npoints = prod (gridsize); 119 eSmp.set_parameters (Npoints, false); 120 Array<vec> &samples = eSmp._samples(); 121 eSmp._w() = ones (Npoints) / Npoints; //unifrom size of bins 122 //set samples 123 ivec ind = zeros_i (dim); //indeces of dimensions in for cycle; 124 vec smpi (dim); // ith sample 125 vec steps =zeros(dim); // ith sample 126 // first corner 127 for (int j = 0; j < dim; j++) { 128 smpi (j) = XYZ (j) (0); /* beginning of the interval*/ 129 it_assert(gridsize(j)!=0.0,"Zeros in gridsize!"); 130 steps (j) = (smpi(j) - XYZ(j)(1))/gridsize(j); 131 } 132 // fill samples 133 int act_dim=0; //active dimension 134 for (int i = 0; i < Npoints; i++) { 135 // copy 136 samples(i) = smpi; 137 // go through all dimensions 138 for (int j = 0;j < dim;j++) { 139 if (ind (j) == gridsize (j) - 1) { //j-th index is full 140 ind (j) = 0; //shift back 141 smpi(j) = XYZ(j)(0); 142 143 ind (j + 1) ++; //increase the next dimension; 144 smpi(j+1) += steps(j+1); 145 146 if (ind (j + 1) < gridsize (j + 1) - 1) break; 147 } else { 148 ind (j) ++; 149 smpi(j) +=steps(j); 150 break; 151 } 152 } 153 } 154 } 111 155 //! set debug file 112 void set_debug_file (const string fname) { 113 if (DBG) delete dbg_file; 114 dbg_file = new it_file (fname); 156 void set_debug_file (const string fname) { 157 if (DBG) delete dbg_file; 158 dbg_file = new it_file (fname); 115 159 if (dbg_file) DBG = true; 116 160 } 117 161 //! Set internal parameters used in approximation 118 void set_method (MERGER_METHOD MTH, double beta0 =0.0) {119 METHOD = MTH; 162 void set_method (MERGER_METHOD MTH, double beta0 = 0.0) { 163 METHOD = MTH; 120 164 beta = beta0; 121 165 } 122 166 //! Set support points from a pdf by drawing N samples 123 void set_support(const epdf &overall, int N){ 124 it_assert_debug ( rv.equal ( overall._rv() ),"Incompatible parameter overall!" ); 125 eSmp.set_statistics(&overall,N); 126 Npoints=N; 127 } 128 167 void set_support (const epdf &overall, int N) { 168 eSmp.set_statistics (&overall, N); 169 Npoints = N; 170 } 171 129 172 //! Destructor 130 173 virtual ~merger_base() { … … 136 179 }; 137 180 //!@} 138 181 139 182 //! \name Mathematical operations 140 183 //!@{ 141 184 142 185 //!Merge given sources in given points 143 186 void merge () { 144 if (eSmp._w().length() ==0) {it_error("Empty support points use set_support" );} 187 validate(); 188 145 189 //check if sources overlap: 146 190 bool OK = true; … … 164 208 eSmp._w() = wtmp / sum (wtmp); 165 209 } else { 166 it_error("Sources are not compatible - use merger_mix"); 167 } 168 ; 210 it_error ("Sources are not compatible - use merger_mix"); 211 } 169 212 }; 170 213 … … 172 215 //! Merge log-likelihood values in points using method specified by parameter METHOD 173 216 vec merge_points (mat &lW); 174 175 217 218 176 219 //! sample from merged density 177 220 //! weight w is a … … 216 259 //! Access function 217 260 eEmp& _Smp() {return eSmp;} 218 261 262 //! load from setting 263 void from_setting (const Setting& set) { 264 // get support 265 // find which method to use 266 string meth_str; 267 UI::get<string> (meth_str, set, "method"); 268 if (!strcmp (meth_str.c_str(), "arithmetic")) 269 set_method (ARITHMETIC); 270 else { 271 if (!strcmp (meth_str.c_str(), "geometric")) 272 set_method (GEOMETRIC); 273 else if (!strcmp (meth_str.c_str(), "lognormal")) { 274 set_method (GEOMETRIC); 275 set.lookupValue( "beta",beta); 276 } 277 } 278 validate(); 279 } 280 281 void validate() { 282 it_assert (eSmp._w().length() > 0, "Empty support, use set_support()."); 283 it_assert (dim == eSmp._samples() (0).length(), "Support points and rv are not compatible!"); 284 it_assert (isnamed(),"mergers must be named"); 285 } 219 286 //!@} 220 287 }; 288 UIREGISTER(merger_base); 221 289 222 290 class merger_mix : public merger_base … … 234 302 //!@{ 235 303 merger_mix () {}; 236 merger_mix (const Array<mpdf*> &S ) {set_sources(S);};304 merger_mix (const Array<mpdf*> &S,bool own=false) {set_sources (S,own);}; 237 305 //! Set sources and prepare all internal structures 238 void set_sources (const Array<mpdf*> &S ) {239 merger_base::set_sources (S);306 void set_sources (const Array<mpdf*> &S, bool own) { 307 merger_base::set_sources (S,own); 240 308 Nsources = S.length(); 241 309 } 242 310 //! Set internal parameters used in approximation 243 void set_parameters (int Ncoms0 =10, double effss_coef0 = 0.5) {311 void set_parameters (int Ncoms0 = 10, double effss_coef0 = 0.5) { 244 312 Ncoms = Ncoms0; 245 313 effss_coef = effss_coef0; 246 314 } 247 315 //!@} 248 316 249 317 //! \name Mathematical operations 250 318 //!@{ 251 319 252 320 //!Merge values using mixture approximation 253 321 void merge (); … … 269 337 //! Access function 270 338 emix* proposal() {emix* tmp = Mix.epredictor(); tmp->set_rv (rv); return tmp;} 271 //! @} 339 //! from_settings 340 void from_settings(const Setting& set){ 341 merger_base::from_setting(set); 342 set.lookupValue("ncoms",Ncoms); 343 } 272 344 345 //! @} 346 273 347 }; 348 UIREGISTER(merger_mix); 274 349 275 350 }