Changeset 102 for bdm/stat/libBM.h
- Timestamp:
- 05/12/08 17:34:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libBM.h
r96 r102 31 31 //! len = number of individual rvs 32 32 int len; 33 //! Vector of unique IDs 33 //! Vector of unique IDs 34 34 ivec ids; 35 35 //! Vector of sizes … … 42 42 private: 43 43 //! auxiliary function used in constructor 44 void init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times );44 void init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ); 45 45 public: 46 46 //! Full constructor which is called by the others 47 RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times );47 RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times ); 48 48 //! default constructor 49 49 RV ( ivec ids ); … … 63 63 //! Find indexes of another rv in self 64 64 ivec find ( RV rv2 ); 65 //! Compare if \c rv2 is identical to this \c RV 66 bool equal ( RV rv2 ) const; 65 67 //! Add (concat) another variable to the current one 66 void add (const RV &rv2 );68 void add ( const RV &rv2 ); 67 69 //! Add (concat) another variable to the current one 68 friend RV concat ( const RV &rv1, const RV &rv2 );70 friend RV concat ( const RV &rv1, const RV &rv2 ); 69 71 //! Subtract another variable from the current one 70 72 RV subt ( RV rv2 ); … … 79 81 80 82 //!access function 81 Array<std::string>& _names() {return names;};82 83 //!access function 84 int id (int at){return ids(at);};85 //!access function 86 int size (int at){return sizes(at);};87 //!access function 88 int time (int at){return times(at);};89 //!access function 90 std::string name (int at){return names(at);};83 Array<std::string>& _names() {return names;}; 84 85 //!access function 86 int id ( int at ) {return ids ( at );}; 87 //!access function 88 int size ( int at ) {return sizes ( at );}; 89 //!access function 90 int time ( int at ) {return times ( at );}; 91 //!access function 92 std::string name ( int at ) {return names ( at );}; 91 93 }; 92 94 … … 100 102 public: 101 103 //!default constructor 102 fnc (int dy):dimy(dy){};104 fnc ( int dy ) :dimy ( dy ) {}; 103 105 //! function evaluates numerical value of \f$f(x)\f$ at \f$x=\f$ \c cond 104 106 virtual vec eval ( const vec &cond ) { 105 107 return vec ( 0 ); 106 }; 108 }; 107 109 108 110 //! access function … … 131 133 //! Returns a sample, \f$x\f$ from density \f$epdf(rv)\f$ 132 134 virtual vec sample () const =0; 135 //! Returns N samples from density \f$epdf(rv)\f$ 136 virtual mat sampleN ( int N ) const; 133 137 //! Compute probability of argument \c val 134 virtual double eval ( const vec &val ) const {return exp (this->evalpdflog(val));};138 virtual double eval ( const vec &val ) const {return exp ( this->evalpdflog ( val ) );}; 135 139 136 140 //! Compute log-probability of argument \c val 137 141 virtual double evalpdflog ( const vec &val ) const =0; 138 142 139 //! return expected value 143 //! return expected value 140 144 virtual vec mean() const =0; 141 145 142 146 //! Destructor for future use; 143 147 virtual ~epdf() {}; … … 163 167 // virtual fnc moment ( const int order = 1 ); 164 168 //! 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 \param ll is a return value of log-likelihood of the sample. 165 virtual vec samplecond ( vec &cond, double &ll ) {this->condition(cond);vec temp= ep->sample();ll=ep->evalpdflog(temp);return temp;}; 169 virtual vec samplecond ( vec &cond, double &ll ) {this->condition ( cond );vec temp= ep->sample();ll=ep->evalpdflog ( temp );return temp;}; 170 //! Returns N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv \param ll is a return value of log-likelihood of the sample. 171 virtual mat samplecond ( vec &cond, vec &ll, int N ) { 172 this->condition ( cond ); 173 mat temp ( rv.count(),N ); vec smp ( rv.count() ); for ( int i=0;i<N;i++ ) {smp=ep->sample() ;temp.set_col ( i, smp );ll ( i ) =ep->evalpdflog ( smp );} 174 return temp; 175 }; 166 176 //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond 167 177 virtual void condition ( const vec &cond ) {}; 168 178 169 179 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. 170 virtual double evalcond ( const vec &dt, const vec &cond ) {this->condition(cond);return ep->eval(dt);};180 virtual double evalcond ( const vec &dt, const vec &cond ) {this->condition ( cond );return ep->eval ( dt );}; 171 181 172 182 //! Destructor for future use; … … 176 186 mpdf ( const RV &rv0, const RV &rvc0 ) :rv ( rv0 ),rvc ( rvc0 ) {}; 177 187 //! access function 178 RV _rvc() {return rvc;}179 //!access function 180 epdf& _epdf() {return *ep;}188 RV _rvc() {return rvc;} 189 //!access function 190 epdf& _epdf() {return *ep;} 181 191 }; 182 192 … … 230 240 231 241 //!Default constructor 232 BM (const RV &rv0) :rv(rv0), ll ( 0 ),evalll ( true ) {//Fixme: test rv242 BM ( const RV &rv0 ) :rv ( rv0 ), ll ( 0 ),evalll ( true ) {//Fixme: test rv 233 243 }; 234 244 … … 240 250 void bayes ( mat Dt ); 241 251 //! Returns a pointer to the epdf representing posterior density on parameters. Use with care! 242 virtual epdf& _epdf() =0;252 virtual epdf& _epdf() =0; 243 253 244 254 //! Destructor for future use; … … 267 277 virtual void condition ( const vec &val ) =0; 268 278 //! Default constructor 269 BMcond (RV &rv0):rvc(rv0){};279 BMcond ( RV &rv0 ) :rvc ( rv0 ) {}; 270 280 //! Destructor for future use 271 virtual ~BMcond() {};281 virtual ~BMcond() {}; 272 282 //! access function 273 283 const RV& _rvc() const {return rvc;}