root/bdm/stat/libBM.h @ 279

Revision 279, 20.9 kB (checked in by smidl, 15 years ago)

Transition of pmsm and libKF

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief Bayesian Models (bm) that use Bayes rule to learn from observations
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#ifndef BM_H
14#define BM_H
15
16
17#include "../itpp_ext.h"
18#include <map>
19
20namespace bdm {
21using namespace itpp;
22using namespace std;
23
24//! Root class of BDM objects
25class bdmroot {
26public:
27        //! make sure this is a virtual object
28        virtual ~bdmroot() {}
29};
30
31typedef std::map<string, int> RVmap;
32extern ivec RV_SIZES;
33extern Array<string> RV_NAMES;
34
35//! Structure of RV (used internally), i.e. expanded RVs
36class str {
37public:
38        //! vector id ids (non-unique!)
39        ivec ids;
40        //! vector of times
41        ivec times;
42        //!Default constructor
43        str ( ivec ids0, ivec times0 ) :ids ( ids0 ),times ( times0 ) {
44                it_assert_debug ( times0.length() ==ids0.length(),"Incompatible input" );
45        };
46};
47
48/*!
49* \brief Class representing variables, most often random variables
50
51The purpose of this class is to decribe a vector of data. Such description is used for connecting various vectors between each other, see class datalink.
52
53The class is implemented using global variables to assure uniqueness of description:
54
55 In is a vector
56\dot
57digraph datalink {
58rankdir=LR;
59subgraph cluster0 {
60node [shape=record];
61label = "RV_MAP \n std::map<string,int>";
62map [label="{{\"a\"| \"b\" | \"c\"} | {<3> 3 |<1> 1|<2> 2}}"];
63color = "white"
64}
65subgraph cluster1{
66node [shape=record];
67label = "RV_NAMES";
68names [label="{<1> \"b\" | <2> \"c\" | <3>\"a\" }"];
69color = "white"
70}
71subgraph cluster2{
72node [shape=record];
73label = "RV_SIZES";
74labelloc = b;
75sizes [label="{<1>1 |<2> 4 |<3> 1}"];
76color = "white"
77}
78map:1 -> names:1;
79map:1 -> sizes:1;
80map:3 -> names:3;
81map:3 -> sizes:3;
82}
83\enddot
84*/
85
86class RV :public bdmroot {
87protected:
88        //! size of the data vector
89        int dsize;
90        //! number of individual rvs
91        int len;
92        //! Vector of unique IDs
93        ivec ids;
94        //! Vector of shifts from current time
95        ivec times;
96
97private:
98        //! auxiliary function used in constructor
99        void init ( Array<std::string> in_names, ivec in_sizes, ivec in_times );
100        int init ( const  string &name, int size );
101public:
102        //! \name Constructors
103        //!@{
104
105        //! Full constructor
106        RV ( Array<std::string> in_names, ivec in_sizes, ivec in_times ) {init ( in_names,in_sizes,in_times );};
107        //! Constructor with times=0
108        RV ( Array<std::string> in_names, ivec in_sizes ) {init ( in_names,in_sizes,zeros_i ( in_names.length() ) );};
109        //! Constructor with sizes=1, times=0
110        RV ( Array<std::string> in_names ) {init ( in_names,ones_i ( in_names.length() ),zeros_i ( in_names.length() ) );}
111        //! Constructor of empty RV
112        RV () :dsize ( 0 ),len ( 0 ),ids ( 0 ),times ( 0 ) {};
113        //! Constructor of a single RV with given id
114        RV ( string name, int sz, int tm=0 );
115        //!@}
116
117        //! \name Access functions
118        //!@{
119
120        //! Printing output e.g. for debugging.
121        friend std::ostream &operator<< ( std::ostream &os, const RV &rv );
122        int _dsize() const {return dsize;} ;
123        //! Recount size of the corresponding data vector
124        int countsize() const;
125        ivec cumsizes() const;
126        int length() const {return len;} ;
127        int id ( int at ) const{return ids ( at );};
128        int size ( int at ) const {return RV_SIZES ( ids(at) );};
129        int time ( int at ) const{return times ( at );};
130        std::string name ( int at ) const {return RV_NAMES ( ids(at) );};
131        void set_time ( int at, int time0 ) {times ( at ) =time0;};
132        //!@}
133
134        //TODO why not inline and later??
135
136        //! \name Algebra on Random Variables
137        //!@{
138
139        //! Find indices of self in another rv, \return ivec of the same size as self.
140        ivec findself ( const RV &rv2 ) const;
141        //! Compare if \c rv2 is identical to this \c RV
142        bool equal ( const RV &rv2 ) const;
143        //! Add (concat) another variable to the current one, \return true if all rv2 were added, false if rv2 is in conflict
144        bool add ( const RV &rv2 );
145        //! Subtract  another variable from the current one
146        RV subt ( const RV &rv2 ) const;
147        //! Select only variables at indeces ind
148        RV subselect ( const ivec &ind ) const;
149        //! Select only variables at indeces ind
150        RV operator() ( const ivec &ind ) const {return subselect ( ind );};
151        //! Select from data vector starting at di1 to di2
152        RV operator() ( int di1, int di2 ) const {
153                ivec sz=cumsizes();
154                int i1=0;
155                while ( sz ( i1 ) <di1 ) i1++;
156                int i2=i1;
157                while ( sz ( i2 ) <di2 ) i2++;
158                return subselect ( linspace ( i1,i2 ) );
159        };
160        //! Shift \c time shifted by delta.
161        void t ( int delta );
162        //!@}
163
164        //!\name Relation to vectors
165        //!@{
166
167        //! generate \c str from rv, by expanding sizes
168        str tostr() const;
169        //! when this rv is a part of bigger rv, this function returns indeces of self in the data vector of the bigger crv.
170        //! Then, data can be copied via: data_of_this = cdata(ind);
171        ivec dataind ( const RV &crv ) const;
172        //! generate mutual indeces when copying data betwenn self and crv.
173        //! Data are copied via: data_of_this(selfi) = data_of_rv2(rv2i)
174        void dataind ( const RV &rv2, ivec &selfi, ivec &rv2i ) const;
175        //! Minimum time-offset
176        int mint () const {return min ( times );};
177        //!@}
178
179};
180
181
182//! Concat two random variables
183RV concat ( const RV &rv1, const RV &rv2 );
184
185//!Default empty RV that can be used as default argument
186extern RV RV0;
187
188//! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv
189
190class fnc :public bdmroot {
191protected:
192        //! Length of the output vector
193        int dimy;
194public:
195        //!default constructor
196        fnc ( ) {};
197        //! function evaluates numerical value of \f$f(x)\f$ at \f$x=\f$ \c cond
198        virtual vec eval ( const vec &cond ) {
199                return vec ( 0 );
200        };
201
202        //! function substitutes given value into an appropriate position
203        virtual void condition ( const vec &val ) {};
204
205        //! access function
206        int _dimy() const{return dimy;}
207};
208
209class mpdf;
210
211//! Probability density function with numerical statistics, e.g. posterior density.
212
213class epdf :public bdmroot {
214protected:
215        //! dimension of the random variable
216        int dim;
217        //! Description of the random variable
218        RV rv;
219
220public:
221        /*! \name Constructors
222         Construction of each epdf should support two types of constructors:
223        \li empty constructor,
224        \li copy constructor,
225
226        The following constructors should be supported for convenience:
227        \li constructor followed by calling \c set_parameters()
228        \li constructor accepting random variables calling \c set_rv()
229
230         All internal data structures are constructed as empty. Their values (including sizes) will be set by method \c set_parameters(). This way references can be initialized in constructors.
231        @{*/
232        epdf() :dim ( 0 ),rv ( ) {};
233        epdf ( const epdf &e ) :dim ( e.dim ),rv ( e.rv ) {};
234        epdf ( const RV &rv0 ) {set_rv ( rv0 );};
235        void set_parameters ( int dim0 ) {dim=dim0;}
236        //!@}
237
238        //! \name Matematical Operations
239        //!@{
240
241        //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$
242        virtual vec sample () const {it_error ( "not implemneted" );return vec ( 0 );};
243        //! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$  from density \f$ f_x(rv)\f$
244        virtual mat sample_m ( int N ) const;
245        //! Compute log-probability of argument \c val
246        virtual double evallog ( const vec &val ) const {it_error ( "not implemneted" );return 0.0;};
247        //! Compute log-probability of multiple values argument \c val
248        virtual vec evallog_m ( const mat &Val ) const {
249                vec x ( Val.cols() );
250                for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evallog ( Val.get_col ( i ) ) ;}
251                return x;
252        }
253        //! Return conditional density on the given RV, the remaining rvs will be in conditioning
254        virtual mpdf* condition ( const RV &rv ) const  {it_warning ( "Not implemented" ); return NULL;}
255        //! Return marginal density on the given RV, the remainig rvs are intergrated out
256        virtual epdf* marginal ( const RV &rv ) const {it_warning ( "Not implemented" ); return NULL;}
257        //! return expected value
258        virtual vec mean() const {it_error ( "not implemneted" );return vec ( 0 );};
259        //! return expected variance (not covariance!)
260        virtual vec variance() const {it_error ( "not implemneted" );return vec ( 0 );};
261        //!@}
262
263        //! \name Connection to other classes
264        //! Description of the random quantity via attribute \c rv is optional.
265        //! For operations such as sampling \c rv does not need to be set. However, for \c marginalization
266        //! and \c conditioning \c rv has to be set. NB:
267        //! @{
268
269        //!Name its rv
270        void set_rv ( const RV &rv0 ) {rv = rv0; }//it_assert_debug(isnamed(),""); };
271        //! True if rv is assigned
272        bool isnamed() const {bool b= ( dim==rv._dsize() );return b;}
273        //! Return name (fails when isnamed is false)
274        const RV& _rv() const {it_assert_debug ( isnamed(),"" ); return rv;}
275        //!@}
276
277        //! \name Access to attributes
278        //! @{
279
280        //! Size of the random variable
281        int dimension() const {return dim;}
282        //!@}
283
284};
285
286
287//! Conditional probability density, e.g. modeling some dependencies.
288//TODO Samplecond can be generalized
289
290class mpdf : public bdmroot {
291protected:
292        //!dimension of the condition
293        int dimc;
294        //! random variable in condition
295        RV rvc;
296        //! pointer to internal epdf
297        epdf* ep;
298public:
299        //! \name Constructors
300        //! @{
301
302        mpdf ( ) :dimc ( 0 ),rvc ( ) {};
303        //! copy constructor does not set pointer \c ep - has to be done in offsprings!
304        mpdf ( const mpdf &m ) :dimc ( m.dimc ),rvc ( m.rvc ) {};
305        //!@}
306
307        //! \name Matematical operations
308        //!@{
309
310        //! 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
311        virtual vec samplecond ( const vec &cond ) {
312                this->condition ( cond );
313                vec temp= ep->sample();
314                return temp;
315        };
316        //! 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 \param ll is a return value of log-likelihood of the sample.
317        virtual mat samplecond_m ( const vec &cond, int N ) {
318                this->condition ( cond );
319                mat temp ( ep->dimension(),N ); vec smp ( ep->dimension() );
320                for ( int i=0;i<N;i++ ) {smp=ep->sample() ;temp.set_col ( i, smp );}
321                return temp;
322        };
323        //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond
324        virtual void condition ( const vec &cond ) {it_error ( "Not implemented" );};
325
326        //! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently.
327        virtual double evallogcond ( const vec &dt, const vec &cond ) {
328                double tmp; this->condition ( cond );tmp = ep->evallog ( dt );          it_assert_debug ( std::isfinite ( tmp ),"Infinite value" ); return tmp;
329        };
330
331        //! Matrix version of evallogcond
332        virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {this->condition ( cond );return ep->evallog_m ( Dt );};
333
334        //! \name Access to attributes
335        //! @{
336
337        RV _rv() {return ep->_rv();}
338        RV _rvc() {it_assert_debug ( isnamed(),"" ); return rvc;}
339        int dimension() {return ep->dimension();}
340        int dimensionc() {return dimc;}
341        epdf& _epdf() {return *ep;}
342        epdf* _e() {return ep;}
343        //!@}
344
345        //! \name Connection to other objects
346        //!@{
347        void set_rvc ( const RV &rvc0 ) {rvc=rvc0;}
348        void set_rv ( const RV &rv0 ) {ep->set_rv ( rv0 );}
349        bool isnamed() {return ( ep->isnamed() ) && ( dimc==rvc._dsize() );}
350        //!@}
351};
352
353/*! \brief DataLink is a connection between two data vectors Up and Down
354
355Up can be longer than Down. Down must be fully present in Up (TODO optional)
356See chart:
357\dot
358digraph datalink {
359        node [shape=record];
360        subgraph cluster0 {
361                label = "Up";
362        up [label="<1>|<2>|<3>|<4>|<5>"];
363                color = "white"
364}
365        subgraph cluster1{
366                label = "Down";
367                labelloc = b;
368        down [label="<1>|<2>|<3>"];
369                color = "white"
370}
371    up:1 -> down:1;
372    up:3 -> down:2;
373    up:5 -> down:3;
374}
375\enddot
376
377*/
378class datalink {
379protected:
380        //! Remember how long val should be
381        int downsize;
382        //! Remember how long val of "Up" should be
383        int upsize;
384        //! val-to-val link, indeces of the upper val
385        ivec v2v_up;
386public:
387        //! Constructor
388        datalink () {};
389        datalink ( const RV &rv, const RV &rv_up ) {set_connection ( rv,rv_up );};
390        //! set connection, rv must be fully present in rv_up
391        void set_connection ( const RV &rv, const RV &rv_up ) {
392                downsize = rv._dsize();
393                upsize = rv_up._dsize();
394                v2v_up= ( rv.dataind ( rv_up ) );
395
396                it_assert_debug ( v2v_up.length() ==downsize,"rv is not fully in rv_up" );
397        }
398        //! Get val for myself from val of "Up"
399        vec pushdown ( const vec &val_up ) {
400                it_assert_debug ( upsize==val_up.length(),"Wrong val_up" );
401                return get_vec ( val_up,v2v_up );
402        }
403        //! Fill val of "Up" by my pieces
404        void pushup ( vec &val_up, const vec &val ) {
405                it_assert_debug ( downsize==val.length(),"Wrong val" );
406                it_assert_debug ( upsize==val_up.length(),"Wrong val_up" );
407                set_subvector ( val_up, v2v_up, val );
408        }
409};
410
411//! data link between
412class datalink_m2e: public datalink {
413protected:
414        //! Remember how long cond should be
415        int condsize;
416        //!upper_val-to-local_cond link, indeces of the upper val
417        ivec v2c_up;
418        //!upper_val-to-local_cond link, ideces of the local cond
419        ivec v2c_lo;
420
421public:
422        //! Constructor
423        datalink_m2e ( const RV &rv,  const RV &rvc, const RV &rv_up ) :
424                        datalink ( rv,rv_up ), condsize ( rvc._dsize() ) {
425                //establish v2c connection
426                rvc.dataind ( rv_up, v2c_lo, v2c_up );
427        }
428        //!Construct condition
429        vec get_cond ( const vec &val_up ) {
430                vec tmp ( condsize );
431                set_subvector ( tmp,v2c_lo,val_up ( v2c_up ) );
432                return tmp;
433        }
434        void pushup_cond ( vec &val_up, const vec &val, const vec &cond ) {
435                it_assert_debug ( downsize==val.length(),"Wrong val" );
436                it_assert_debug ( upsize==val_up.length(),"Wrong val_up" );
437                set_subvector ( val_up, v2v_up, val );
438                set_subvector ( val_up, v2c_up, cond );
439        }
440};
441//!DataLink is a connection between mpdf and its superordinate (Up)
442//! This class links
443class datalink_m2m: public datalink_m2e {
444protected:
445        //!cond-to-cond link, indeces of the upper cond
446        ivec c2c_up;
447        //!cond-to-cond link, indeces of the local cond
448        ivec c2c_lo;
449public:
450        //! Constructor
451        datalink_m2m ( const RV &rv, const RV &rvc, const RV &rv_up, const RV &rvc_up ) :
452                        datalink_m2e ( rv, rvc, rv_up ) {
453                //establish c2c connection
454                rvc.dataind ( rvc_up, c2c_lo, c2c_up );
455                it_assert_debug ( c2c_lo.length() +v2c_lo.length() ==condsize, "cond is not fully given" );
456        }
457        //! Get cond for myself from val and cond of "Up"
458        vec get_cond ( const vec &val_up, const vec &cond_up ) {
459                vec tmp ( condsize );
460                set_subvector ( tmp,v2c_lo,val_up ( v2c_up ) );
461                set_subvector ( tmp,c2c_lo,cond_up ( c2c_up ) );
462                return tmp;
463        }
464        //! Fill
465
466};
467
468/*!
469@brief Class for storing results (and semi-results) of an experiment
470
471This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed.
472 */
473class logger : public bdmroot {
474protected:
475        //! RVs of all logged variables.
476        Array<RV> entries;
477        //! Names of logged quantities, e.g. names of algorithm variants
478        Array<string> names;
479public:
480        //!Default constructor
481        logger ( ) : entries ( 0 ),names ( 0 ) {}
482
483        //! returns an identifier which will be later needed for calling the \c logit() function
484        //! For empty RV it returns -1, this entry will be ignored by \c logit().
485        virtual int add ( const RV &rv, string name="" ) {
486                int id;
487                if ( rv._dsize() >0 ) {
488                        id=entries.length();
489                        names=concat ( names, name ); // diff
490                        entries.set_length ( id+1,true );
491                        entries ( id ) = rv;
492                }
493                else { id =-1;}
494                return id; // identifier of the last entry
495        }
496
497        //! log this vector
498        virtual void logit ( int id, const vec &v ) =0;
499
500        //! Shifts storage position for another time step.
501        virtual void step() =0;
502
503        //! Finalize storing information
504        virtual void finalize() {};
505
506        //! Initialize the storage
507        virtual void init() {};
508
509};
510
511/*! \brief Unconditional mpdf, allows using epdf in the role of mpdf.
512
513*/
514class mepdf : public mpdf {
515public:
516        //!Default constructor
517        mepdf ( const epdf* em ) :mpdf ( ) {ep=const_cast<epdf*> ( em );};
518        void condition ( const vec &cond ) {}
519};
520
521//!\brief Abstract composition of pdfs, will be used for specific classes
522//!this abstract class is common to epdf and mpdf
523class compositepdf {
524protected:
525        //!Number of mpdfs in the composite
526        int n;
527        //! Elements of composition
528        Array<mpdf*> mpdfs;
529public:
530        compositepdf ( Array<mpdf*> A0 ) : n ( A0.length() ), mpdfs ( A0 ) {};
531        //! find common rv, flag \param checkoverlap modifies whether overlaps are acceptable
532        RV getrv ( bool checkoverlap=false );
533        //! common rvc of all mpdfs is written to rvc
534        void setrvc ( const RV &rv, RV &rvc );
535};
536
537/*! \brief Abstract class for discrete-time sources of data.
538
539The class abstracts operations of: (i) data aquisition, (ii) data-preprocessing, (iii) scaling of data, and (iv) data resampling from the task of estimation and control.
540Moreover, for controlled systems, it is able to receive the desired control action and perform it in the next step. (Or as soon as possible).
541
542*/
543
544class DS : public bdmroot {
545protected:
546        int dtsize;
547        int utsize;
548        //!Description of data returned by \c getdata().
549        RV Drv;
550        //!Description of data witten by by \c write().
551        RV Urv; //
552        //! Remember its own index in Logger L
553        int L_dt, L_ut;
554public:
555        //! default constructors
556        DS() :Drv ( ),Urv ( ) {};
557        //! Returns full vector of observed data=[output, input]
558        virtual void getdata ( vec &dt ) {it_error ( "abstract class" );};
559        //! Returns data records at indeces.
560        virtual void getdata ( vec &dt, const ivec &indeces ) {it_error ( "abstract class" );};
561        //! Accepts action variable and schedule it for application.
562        virtual void write ( vec &ut ) {it_error ( "abstract class" );};
563        //! Accepts action variables at specific indeces
564        virtual void write ( vec &ut, const ivec &indeces ) {it_error ( "abstract class" );};
565
566        //! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system.
567        virtual void step() =0;
568
569        //! Register DS for logging into logger L
570        virtual void log_add ( logger &L ) {
571                it_assert_debug ( dtsize==Drv._dsize(),"" );
572                it_assert_debug ( utsize==Urv._dsize(),"" );
573
574                L_dt=L.add ( Drv,"" );
575                L_ut=L.add ( Urv,"" );
576        }
577        //! Register DS for logging into logger L
578        virtual void logit ( logger &L ) {
579                vec tmp ( Drv._dsize() +Urv._dsize() );
580                getdata ( tmp );
581                // d is first in getdata
582                L.logit ( L_dt,tmp.left ( Drv._dsize() ) );
583                // u follows after d in getdata
584                L.logit ( L_ut,tmp.mid ( Drv._dsize(), Urv._dsize() ) );
585        }
586        //!access function
587        virtual RV _drv() const {return concat ( Drv,Urv );}
588        //!access function
589        const RV& _urv() const {return Urv;}
590};
591
592/*! \brief Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.
593
594*/
595
596class BM :public bdmroot {
597protected:
598        //! Random variable of the data (optional)
599        RV drv;
600        //!Logarithm of marginalized data likelihood.
601        double ll;
602        //!  If true, the filter will compute likelihood of the data record and store it in \c ll . Set to false if you want to save computational time.
603        bool evalll;
604public:
605        //! \name Constructors
606        //! @{
607
608        BM () :ll ( 0 ),evalll ( false ) {};
609        BM ( const BM &B ) :  drv ( B.drv ), ll ( B.ll ), evalll ( B.evalll ) {}
610        //! Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!
611        //! Prototype: \code BM* _copy_(){return new BM(*this);} \endcode
612        virtual BM* _copy_ () {return NULL;};
613        //!@}
614
615        //! \name Mathematical operations
616        //!@{
617
618        /*! \brief Incremental Bayes rule
619        @param dt vector of input data
620        */
621        virtual void bayes ( const vec &dt ) = 0;
622        //! Batch Bayes rule (columns of Dt are observations)
623        virtual void bayesB ( const mat &Dt );
624        //! Evaluates predictive log-likelihood of the given data record
625        //! I.e. marginal likelihood of the data with the posterior integrated out.
626        virtual double logpred ( const vec &dt ) const{it_error ( "Not implemented" );return 0.0;}
627        //! Matrix version of logpred
628        vec logpred_m ( const mat &dt ) const{vec tmp ( dt.cols() );for ( int i=0;i<dt.cols();i++ ) {tmp ( i ) =logpred ( dt.get_col ( i ) );}return tmp;}
629
630        //!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$
631        virtual epdf* epredictor ( ) const {it_error ( "Not implemented" );return NULL;};
632        //!Constructs a conditional density 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t})
633        virtual mpdf* predictor ( ) const {it_error ( "Not implemented" );return NULL;};
634        //!@}
635
636        //! \name Access to attributes
637        //!@{
638
639        const RV& _drv() const {return drv;}
640        void set_drv ( const RV &rv ) {drv=rv;}
641        void set_rv ( const RV &rv ) {const_cast<epdf&> ( posterior() ).set_rv ( rv );}
642        double _ll() const {return ll;}
643        void set_evalll ( bool evl0 ) {evalll=evl0;}
644        virtual const epdf& posterior() const =0;
645        virtual const epdf* _e() const =0;
646        //!@}
647
648};
649
650/*!
651\brief Conditional Bayesian Filter
652
653Evaluates conditional filtering density \f$f(rv|rvc,data)\f$ for a given \c rvc which is specified in each step by calling function \c condition.
654
655This is an interface class used to assure that certain BM has operation \c condition .
656
657*/
658
659class BMcond :public bdmroot {
660protected:
661        //!dimension of the conditioning variable
662        int dimc;
663        //! Identificator of the conditioning variable
664        RV rvc;
665public:
666        //! Substitute \c val for \c rvc.
667        virtual void condition ( const vec &val ) =0;
668        //! Default constructor
669        BMcond ( ) :rvc ( ) {};
670        //! Destructor for future use
671        virtual ~BMcond() {};
672        //! access function
673        const RV& _rvc() const {return rvc;}
674};
675
676}; //namespace
677#endif // BM_H
Note: See TracBrowser for help on using the browser.