358 | | mpdf() : dimc(0), rvc() {}; |
359 | | //! copy constructor does not set pointer \c ep - has to be done in offsprings! |
360 | | mpdf(const mpdf &m) : dimc(m.dimc), rvc(m.rvc) {}; |
361 | | //!@} |
362 | | |
363 | | //! \name Matematical operations |
364 | | //!@{ |
365 | | |
366 | | //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv |
367 | | virtual vec samplecond(const vec &cond) { |
368 | | this->condition(cond); |
369 | | vec temp = ep->sample(); |
370 | | return temp; |
371 | | }; |
372 | | //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv |
373 | | virtual mat samplecond_m(const vec &cond, int N) { |
374 | | this->condition(cond); |
375 | | mat temp(ep->dimension(), N); |
376 | | vec smp(ep->dimension()); |
377 | | for (int i = 0; i < N; i++) {smp = ep->sample() ; temp.set_col(i, smp);} |
378 | | return temp; |
379 | | }; |
380 | | //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond |
381 | | virtual void condition(const vec &cond) {it_error("Not implemented");}; |
| 361 | mpdf():dimc(0), rvc() { } |
| 362 | |
| 363 | mpdf(const mpdf &m):dimc(m.dimc), rvc(m.rvc), shep(m.shep) { } |
| 364 | //!@} |
| 365 | |
| 366 | //! \name Matematical operations |
| 367 | //!@{ |
| 368 | |
| 369 | //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv |
| 370 | virtual vec samplecond(const vec &cond); |
| 371 | |
| 372 | //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv |
| 373 | virtual mat samplecond_m(const vec &cond, int N); |
| 374 | |
| 375 | //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond |
| 376 | virtual void condition(const vec &cond) {it_error("Not implemented");}; |
384 | | virtual double evallogcond(const vec &dt, const vec &cond) { |
385 | | double tmp; |
386 | | this->condition(cond); |
387 | | tmp = ep->evallog(dt); |
388 | | // it_assert_debug(std::isfinite(tmp), "Infinite value"); |
389 | | return tmp; |
390 | | }; |
391 | | |
392 | | //! Matrix version of evallogcond |
393 | | virtual vec evallogcond_m(const mat &Dt, const vec &cond) {this->condition(cond); return ep->evallog_m(Dt);}; |
394 | | //! Array<vec> version of evallogcond |
395 | | virtual vec evallogcond_m(const Array<vec> &Dt, const vec &cond) {this->condition(cond); return ep->evallog_m(Dt);}; |
396 | | |
397 | | //! \name Access to attributes |
398 | | //! @{ |
399 | | |
400 | | RV _rv() {return ep->_rv();} |
401 | | RV _rvc() {it_assert_debug(isnamed(), ""); return rvc;} |
402 | | int dimension() {return ep->dimension();} |
403 | | int dimensionc() {return dimc;} |
404 | | epdf& _epdf() {return *ep;} |
405 | | epdf* _e() {return ep;} |
406 | | //! Load from structure with elements: |
407 | | //! \code |
408 | | //! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable |
409 | | //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition |
410 | | //! // elements of offsprings |
411 | | //! } |
412 | | //! \endcode |
413 | | //!@} |
414 | | void from_setting(const Setting &set){ |
415 | | if (set.exists("rv")){ |
416 | | RV* r = UI::build<RV>(set,"rv"); |
417 | | set_rv(*r); |
418 | | delete r; |
419 | | } |
420 | | if (set.exists("rvc")){ |
421 | | RV* r = UI::build<RV>(set,"rvc"); |
422 | | set_rvc(*r); |
423 | | delete r; |
424 | | } |
425 | | } |
426 | | //!@} |
427 | | |
428 | | //! \name Connection to other objects |
429 | | //!@{ |
430 | | void set_rvc(const RV &rvc0) {rvc = rvc0;} |
431 | | void set_rv(const RV &rv0) {ep->set_rv(rv0);} |
432 | | bool isnamed() {return (ep->isnamed()) && (dimc == rvc._dsize());} |
433 | | //!@} |
| 379 | virtual double evallogcond(const vec &dt, const vec &cond); |
| 380 | |
| 381 | //! Matrix version of evallogcond |
| 382 | virtual vec evallogcond_m(const mat &Dt, const vec &cond); |
| 383 | |
| 384 | //! Array<vec> version of evallogcond |
| 385 | virtual vec evallogcond_m(const Array<vec> &Dt, const vec &cond); |
| 386 | |
| 387 | //! \name Access to attributes |
| 388 | //! @{ |
| 389 | |
| 390 | RV _rv() { return shep->_rv(); } |
| 391 | RV _rvc() { it_assert_debug(isnamed(), ""); return rvc; } |
| 392 | int dimension() { return shep->dimension(); } |
| 393 | int dimensionc() { return dimc; } |
| 394 | |
| 395 | epdf *e() { return shep.get(); } |
| 396 | |
| 397 | void set_ep(shared_ptr<epdf> ep) { shep = ep; } |
| 398 | |
| 399 | //! Load from structure with elements: |
| 400 | //! \code |
| 401 | //! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable |
| 402 | //! rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition |
| 403 | //! // elements of offsprings |
| 404 | //! } |
| 405 | //! \endcode |
| 406 | //!@} |
| 407 | void from_setting(const Setting &set); |
| 408 | //!@} |
| 409 | |
| 410 | //! \name Connection to other objects |
| 411 | //!@{ |
| 412 | void set_rvc(const RV &rvc0) { rvc = rvc0; } |
| 413 | void set_rv(const RV &rv0) { shep->set_rv(rv0); } |
| 414 | bool isnamed() { return (shep->isnamed()) && (dimc == rvc._dsize()); } |
| 415 | //!@} |