Changeset 1015

Show
Ignore:
Timestamp:
05/27/10 23:08:07 (14 years ago)
Author:
smidl
Message:

UI for ldmat - use it in egiw

Location:
library/bdm
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/user_info.cpp

    r959 r1015  
    257257                        new_field = matrix ( i, j ); 
    258258                } 
     259} 
     260 
     261void UI::save ( const ldmat &matrix, Setting &element, const string &name ) { 
     262        Setting &set = ( name == "" ) ? element.add ( Setting::TypeGroup) 
     263        : element.add ( name, Setting::TypeGroup ); 
     264         
     265        save (matrix._L(), set, "L"); 
     266        save (matrix._D(), set, "D"); 
    259267} 
    260268 
     
    371379} 
    372380 
     381void UI::from_setting ( ldmat& matrix, const Setting &element ) { 
     382        if(element.exists("L")){ 
     383                UI::from_setting(matrix.__L(), element["L"]); 
     384        } 
     385        if(element.exists("D")){ 
     386                UI::from_setting(matrix.__D(), element["D"]); 
     387        } 
     388        matrix.validate(); 
     389} 
     390 
    373391void UI::from_setting ( vec &vector, const Setting &element ) { 
    374392        const SettingResolver link ( element ); 
  • library/bdm/base/user_info.h

    r959 r1015  
    2525#include "../shared_ptr.h" 
    2626#include "itpp/itbase.h" 
     27#include "../math/square_mat.h" 
     28#include "../math/chmat.h" 
    2729 
    2830using std::string; 
     
    302304        //! This method converts a Setting into a matrix 
    303305        static void from_setting ( mat& matrix, const Setting &element ); 
     306        //! This method converts a Setting into a ldmat 
     307        static void from_setting ( ldmat& matrix, const Setting &element ); 
    304308        //! This method converts a Setting into an integer vector 
    305309        static void from_setting ( ivec &vector, const Setting &element ); 
     
    550554        //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
    551555        static void save ( const mat &matrix, Setting &element, const string &name = "" ); 
    552  
     556         
     557        //! A matrix(of type mat) is stored in the new child Setting appended to the passed element 
     558        static void save ( const ldmat &matrix, Setting &element, const string &name = "" ); 
     559         
    553560        //! An integer vector (of type ivec) is stored in the new child Setting appended to the passed element 
    554561        static void save ( const ivec &vec, Setting &element, const string &name = "" ); 
  • library/bdm/math/square_mat.h

    r766 r1015  
    307307        } 
    308308 
    309         //! Access functions 
    310         const vec& _D() const { 
    311                 return D; 
    312         } 
    313         //! Access functions 
    314         const mat& _L() const { 
    315                 return L; 
    316         } 
     309//! Access functions 
     310const vec& _D() const { 
     311        return D; 
     312} 
     313//! Access functions 
     314const mat& _L() const { 
     315        return L; 
     316} 
     317//! Access functions 
     318vec& __D() { 
     319        return D; 
     320} 
     321//! Access functions 
     322mat& __L() { 
     323        return L; 
     324} 
     325void validate(){ 
     326        dim= L.rows(); 
     327} 
    317328 
    318329        //! add another ldmat matrix 
  • library/bdm/stat/exp_family.cpp

    r1013 r1015  
    2020void egiw::set_parameters ( int dimx0, ldmat V0, double nu0 ) { 
    2121        dimx = dimx0; 
    22         nPsi = V0.rows() - dimx; 
    23  
     22        nPsi = V0.rows()-dimx; 
    2423        V = V0; 
    2524        if ( nu0 < 0 ) { 
     
    323322                        nu = -1; 
    324323                } 
    325                 mat V; 
    326                 if ( !UI::get ( V, set, "V", UI::optional ) ) { 
    327                         vec dV; 
    328                         UI::get ( dV, set, "dV", UI::compulsory ); 
    329                         set_parameters ( dimx, ldmat ( dV ), nu ); 
    330  
    331                 } else { 
    332                         set_parameters ( dimx, V, nu ); 
     324                mat Vful; 
     325                if (!UI::get(V, set, "V", UI::optional)){ 
     326                        if ( !UI::get ( Vful, set, "V", UI::optional ) ) { 
     327                                vec dV; 
     328                                UI::get ( dV, set, "dV", UI::compulsory ); 
     329                                set_parameters ( dimx, ldmat ( dV ), nu ); 
     330 
     331                        } else { 
     332                                set_parameters ( dimx, Vful, nu ); 
     333                        } 
    333334                } 
    334335        } 
     
    337338                epdf::to_setting ( set ); 
    338339                UI::save ( dimx, set, "dimx" ); 
    339                 UI::save ( V.to_mat(), set, "V" ); 
     340                UI::save ( V, set, "V" ); 
    340341                UI::save ( nu, set, "nu" ); 
    341342        }; 
     
    343344void egiw::validate() { 
    344345        eEF::validate(); 
     346        nPsi = V.rows() - dimx; 
    345347        dim = dimx * ( dimx + nPsi );    
     348         
     349        if ( nu < 0 ) { 
     350                nu = 0.1 + nPsi + 2 * dimx + 2; // +2 assures finite expected value of R 
     351                // terms before that are sufficient for finite normalization 
     352        } 
    346353         
    347354            // check sizes, rvs etc. 
  • library/bdm/stat/exp_family.h

    r1013 r1015  
    443443        \code 
    444444        class = 'egiw'; 
    445         V     = [];               // square matrix 
    446         dV    = [];               // vector of diagonal of V (when V not given) 
    447         nu    = [];               // scalar \nu ((almost) degrees of freedom) 
     445        V.L     = [];             // L part of matrix V 
     446        V.D     = [];             // D part of matrix V 
     447        -or- V  = []              // full matrix V 
     448        -or- dV = [];               // vector of diagonal of V (when V not given) 
     449        nu      = [];               // scalar \nu ((almost) degrees of freedom) 
    448450                                                          // when missing, it will be computed to obtain proper pdf 
    449         dimx  = [];               // dimension of the wishart part 
     451        dimx    = [];               // dimension of the wishart part 
    450452        rv = RV({'name'})         // description of RV 
    451453        rvc = RV({'name'})        // description of RV in condition 
    452         log_level = 'tri';                // set the level of logged details 
    453454        \endcode 
    454455