Changeset 621 for library/bdm/stat/exp_family.h
- Timestamp:
- 09/16/09 22:52:42 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/exp_family.h
r620 r621 134 134 enorm (const vec &mu, const sq_T &R) {set_parameters (mu, R);} 135 135 void set_parameters (const vec &mu, const sq_T &R); 136 /*! Create Normal density 137 \f[ f(rv) = N(\mu, R) \f] 138 from structure 139 \code 140 class = 'enorm<ldmat>', (OR) 'enorm<chmat>', (OR) 'enorm<fsqmat>'; 141 mu = []; // mean value 142 R = []; // variance, square matrix of appropriate dimension 143 \endcode 144 */ 136 145 void from_setting (const Setting &root); 137 146 void validate() { … … 247 256 double& _nu() {return nu;} 248 257 const double& _nu() const {return nu;} 258 /*! Create Gauss-inverse-Wishart density 259 \f[ f(rv) = GiW(V,\nu) \f] 260 from structure 261 \code 262 class = 'egiw'; 263 V = []; // square matrix 264 nu = []; // scalar \nu ((almost) degrees of freedom) 265 // when missing, it will be computed to obtain proper pdf 266 dimx = []; // dimension of the wishart part 267 rv = RV({'name'}) // description of RV 268 rvc = RV({'name'}) // description of RV in condition 269 \endcode 270 */ 271 249 272 void from_setting (const Setting &set) { 250 UI::get (nu, set, "nu", UI::compulsory); 273 epdf::from_setting(set); 274 if (!UI::get (nu, set, "nu", UI::compulsory)) {nu=-1;} 251 275 UI::get (dimx, set, "dimx", UI::compulsory); 252 276 mat V; 253 277 UI::get (V, set, "V", UI::compulsory); 254 278 set_parameters (dimx, V, nu); 255 shared_ptr<RV> rv = UI::build<RV> (set, "rv", UI::compulsory);256 set_rv (*rv);257 279 } 258 280 //!@} … … 401 423 vec variance() const {return elem_div (alpha, elem_mult (beta, beta)); } 402 424 403 //! Load from structure with elements: 404 //! \code 405 //! { alpha = [...]; // vector of alpha 406 //! beta = [...]; // vector of beta 407 //! rv = {class="RV",...} // description 408 //! } 409 //! \endcode 410 //!@} 425 /*! Create Gamma density 426 \f[ f(rv|rvc) = \Gamma(\alpha, \beta) \f] 427 from structure 428 \code 429 class = 'egamma'; 430 alpha = [...]; // vector of alpha 431 beta = [...]; // vector of beta 432 rv = RV({'name'}) // description of RV 433 \endcode 434 */ 411 435 void from_setting (const Setting &set) { 412 436 epdf::from_setting (set); // reads rv … … 511 535 vec mean() const {return (high -low) / 2.0;} 512 536 vec variance() const {return (pow (high, 2) + pow (low, 2) + elem_mult (high, low)) / 3.0;} 513 //! Load from structure with elements: 514 //! \code 515 //! { high = [...]; // vector of upper bounds 516 //! low = [...]; // vector of lower bounds 517 //! rv = {class="RV",...} // description of RV 518 //! } 519 //! \endcode 520 //!@} 537 /*! Create Uniform density 538 \f[ f(rv) = U(low,high) \f] 539 from structure 540 \code 541 class = 'euni' 542 high = [...]; // vector of upper bounds 543 low = [...]; // vector of lower bounds 544 rv = RV({'name'}); // description of RV 545 \endcode 546 */ 521 547 void from_setting (const Setting &set) { 522 548 epdf::from_setting (set); // reads rv and rvc … … 582 608 friend std::ostream &operator<< (std::ostream &os, mlnorm<sq_M, enorm> &ml); 583 609 610 /*! Create Normal density with linear function of mean value 611 \f[ f(rv|rvc) = N(A*rvc+const, R) \f] 612 from structure 613 \code 614 class = 'mlnorm<ldmat>', (OR) 'mlnorm<chmat>', (OR) 'mlnorm<fsqmat>'; 615 A = []; // matrix or vector of appropriate dimension 616 const = []; // vector of constant term 617 R = []; // square matrix of appropriate dimension 618 \endcode 619 */ 584 620 void from_setting (const Setting &set) { 585 621 mpdf::from_setting (set); … … 621 657 622 658 623 /*! UI for mgnorm624 625 The mgnorm is constructed from a structure with fields:659 /*! Create Normal density with given function of mean value 660 \f[ f(rv|rvc) = N( g(rvc), R) \f] 661 from structure 626 662 \code 627 system = { 628 type = "mgnorm"; 629 // function for mean value evolution 630 g = {type="fnc"; ... } 631 632 // variance 633 R = [1, 0, 634 0, 1]; 635 // --OR -- 636 dR = [1, 1]; 637 638 // == OPTIONAL == 639 640 // description of y variables 641 y = {type="rv"; names=["y", "u"];}; 642 // description of u variable 643 u = {type="rv"; names=[];} 644 }; 663 class = 'mgnorm'; 664 g.class = 'fnc'; // function for mean value evolution 665 g._fields_of_fnc = ...; 666 667 R = [1, 0; // covariance matrix 668 0, 1]; 669 --OR -- 670 dR = [1, 1]; // diagonal of cavariance matrix 671 672 rv = RV({'name'}) // description of RV 673 rvc = RV({'name'}) // description of RV in condition 645 674 \endcode 646 647 Result if648 675 */ 649 676 650 677 void from_setting (const Setting &set) { 678 mpdf::from_setting(set); 651 679 shared_ptr<fnc> g = UI::build<fnc> (set, "g", UI::compulsory); 652 680 … … 659 687 660 688 set_parameters (g, R); 689 validate(); 690 } 691 void validate() { 692 bdm_assert(g->dimension()==this->dimension(),"incompatible function"); 661 693 } 662 694 }; … … 741 773 742 774 void condition (const vec &val) {_beta = k / val;}; 743 //! Load from structure with elements: 744 //! \code 745 //! { alpha = [...]; // vector of alpha 746 //! k = 1.1; // multiplicative constant k 747 //! rv = {class="RV",...} // description of RV 748 //! rvc = {class="RV",...} // description of RV in condition 749 //! } 750 //! \endcode 751 //!@} 775 /*! Create Gamma density with conditional mean value 776 \f[ f(rv|rvc) = \Gamma(k, k/rvc) \f] 777 from structure 778 \code 779 class = 'mgamma'; 780 beta = [...]; // vector of initial alpha 781 k = 1.1; // multiplicative constant k 782 rv = RV({'name'}) // description of RV 783 rvc = RV({'name'}) // description of RV in condition 784 \endcode 785 */ 752 786 void from_setting (const Setting &set) { 753 787 mpdf::from_setting (set); // reads rv and rvc … … 877 911 }; 878 912 879 /*! UI for migamma_ref 880 881 The migamma_ref is constructed from a structure with fields: 913 914 /*! Create inverse-Gamma density with conditional mean value 915 \f[ f(rv|rvc) = i\Gamma(k, k/(rvc^l \circ ref^{(1-l)}) \f] 916 from structure 882 917 \code 883 system = { 884 type = "migamma_ref"; 885 ref = [1e-5; 1e-5; 1e-2 1e-3]; // reference vector 886 l = 0.999; // constant l 887 k = 0.1; // constant k 888 889 // == OPTIONAL == 890 // description of y variables 891 y = {type="rv"; names=["y", "u"];}; 892 // description of u variable 893 u = {type="rv"; names=[];} 894 }; 918 class = 'migamma_ref'; 919 ref = [1e-5; 1e-5; 1e-2 1e-3]; // reference vector 920 l = 0.999; // constant l 921 k = 0.1; // constant k 922 rv = RV({'name'}) // description of RV 923 rvc = RV({'name'}) // description of RV in condition 895 924 \endcode 896 897 Result if898 925 */ 899 926 void from_setting (const Setting &set); … … 914 941 \f] 915 942 943 Function from_setting loads mu and R in the same way as it does for enorm<>! 916 944 */ 917 945 class elognorm: public enorm<ldmat> … … 928 956 Mean value, \f$\mu\f$, is... 929 957 930 ==== Check == vv =931 Standard deviation of the random walk is proportional to one \f$k\f$-th the mean.932 This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$.933 934 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$.935 958 */ 936 959 class mlognorm : public mpdf_internal<elognorm> … … 961 984 }; 962 985 963 /*! UI for mlognorm964 965 The mlognorm is constructed from a structure with fields:986 /*! Create logNormal random Walk 987 \f[ f(rv|rvc) = log\mathcal{N}( \log(rvc)-0.5\log(k^2+1), k I) \f] 988 from structure 966 989 \code 967 system = { 968 type = "mlognorm"; 969 k = 0.1; // constant k 970 mu0 = [1., 1.]; 971 972 // == OPTIONAL == 973 // description of y variables 974 y = {type="rv"; names=["y", "u"];}; 975 // description of u variable 976 u = {type="rv"; names=[];} 977 }; 990 class = 'mlognorm'; 991 k = 0.1; // "variance" k 992 mu0 = 0.1; // Initial value of mean 993 rv = RV({'name'}) // description of RV 994 rvc = RV({'name'}) // description of RV in condition 978 995 \endcode 979 980 */ 996 */ 981 997 void from_setting (const Setting &set); 982 998