| 346 | /*! Random Walk on Dirichlet |
| 347 | Using simple assignment |
| 348 | \f[ \beta = rvc / k + \beta_c \f] |
| 349 | hence, mean value = rvc, variance = (k+1)*mean*mean; |
| 350 | |
| 351 | The greater k is, the greater is the variance of the random walk; |
| 352 | |
| 353 | \f$ \beta_c \f$ is used as regularizing element to avoid corner cases, i.e. when one element of rvc is zero. |
| 354 | By default is it set to 0.1; |
| 355 | */ |
| 356 | |
| 357 | class mDirich: public mpdf_internal<eDirich> { |
| 358 | protected: |
| 359 | //! constant \f$ k \f$ of the random walk |
| 360 | double k; |
| 361 | //! cache of beta_i |
| 362 | vec &_beta; |
| 363 | //! stabilizing coefficient \f$ \beta_c \f$ |
| 364 | vec betac; |
| 365 | public: |
| 366 | mDirich(): mpdf_internal<eDirich>(), _beta(iepdf._beta()){}; |
| 367 | void condition (const vec &val) {_beta = val/k+betac; }; |
| 368 | /*! Create Dirichlet random walk |
| 369 | \f[ f(rv|rvc) = Di(rvc*k) \f] |
| 370 | from structure |
| 371 | \code |
| 372 | class = 'mDirich'; |
| 373 | k = 1; // multiplicative constant k |
| 374 | --- optional --- |
| 375 | rv = RV({'name'},size) // description of RV |
| 376 | beta0 = []; // initial value of beta |
| 377 | betac = []; // initial value of beta |
| 378 | \endcode |
| 379 | */ |
| 380 | void from_setting (const Setting &set) { |
| 381 | mpdf::from_setting (set); // reads rv and rvc |
| 382 | if (_rv()._dsize()>0){ |
| 383 | rvc = _rv().copy_t(-1); |
| 384 | } |
| 385 | vec beta0; |
| 386 | if (!UI::get (beta0, set, "beta0", UI::optional)){ |
| 387 | beta0 = ones(_rv()._dsize()); |
| 388 | } |
| 389 | if (!UI::get (betac, set, "betac", UI::optional)){ |
| 390 | betac = 0.1*ones(_rv()._dsize()); |
| 391 | } |
| 392 | _beta = beta0; |
| 393 | |
| 394 | UI::get (k, set, "k", UI::compulsory); |
| 395 | validate(); |
| 396 | } |
| 397 | void validate() { |
| 398 | iepdf.validate(); |
| 399 | bdm_assert(_beta.length()==betac.length(),"beta0 and betac are not compatible"); |
| 400 | if (_rv()._dsize()>0){ |
| 401 | bdm_assert( (_rv()._dsize()==dimension()) , "Size of rv does not match with beta"); |
| 402 | } |
| 403 | dimc = _beta.length(); |
| 404 | }; |
| 405 | }; |
| 406 | UIREGISTER(mDirich); |
| 407 | |