root/bdm/estim/arx.cpp @ 170

Revision 170, 2.5 kB (checked in by smidl, 16 years ago)

Mixtures of EF and related changes to libEF and BM

Line 
1#include "arx.h"
2
3using namespace itpp;
4
5void ARX::bayes ( const vec &dt, const double w ) {
6        double lnc;
7
8        if ( frg<1.0 ) {
9                est.pow ( frg );
10                if ( evalll ) {
11                        last_lognc = est.lognc();
12                }
13        }
14        V.opupdt ( dt,w );
15        nu+=w;
16
17        if ( evalll ) {
18                lnc = est.lognc();
19                ll = lnc - last_lognc;
20                last_lognc = lnc;
21        }
22}
23
24double ARX::logpred ( const vec &dt ) const {
25        egiw pred ( est );
26        ldmat &V=pred._V();
27        double &nu=pred._nu();
28
29        double lll;
30
31        if ( frg<1.0 ) {
32                pred.pow ( frg );
33                lll = pred.lognc();
34        }
35        else 
36                if(evalll){lll=last_lognc;}else{lll=pred.lognc();}
37
38        V.opupdt ( dt,1.0 );
39        nu+=1.0;
40
41        return pred.lognc()-lll;
42}
43
44BM* ARX::_copy_ ( bool changerv) {
45        ARX* Tmp=new ARX ( *this );
46        if ( changerv ) {Tmp->rv.newids(); Tmp->est._renewrv(Tmp->rv);}
47        return Tmp;
48}
49
50void ARX::set_statistics ( const BMEF* B0 ) {
51        const ARX* A0=dynamic_cast<const ARX*> ( B0 );
52
53        it_assert_debug ( V.rows() ==A0->V.rows(),"ARX::set_statistics Statistics  differ" );
54        set_parameters ( A0->V,A0->nu );
55}
56/*! \brief Return the best structure
57@param Eg a copy of GiW density that is being examined
58@param Eg0 a copy of prior GiW density before estimation
59@param Egll likelihood of the current Eg
60@param indeces current indeces
61\return best likelihood in the structure below the given one
62*/
63double egiw_bestbelow ( egiw Eg, egiw Eg0, double Egll, ivec &indeces ) { //parameter Eg is a copy!
64        ldmat Vo = Eg._V(); //copy
65        ldmat Vo0 = Eg._V(); //copy
66        ldmat& Vp = Eg._V(); // pointer into Eg
67        ldmat& Vp0 = Eg._V(); // pointer into Eg
68        int end = Vp.rows()-1;
69        int i;
70        mat Li;
71        mat Li0;
72        double maxll=Egll;
73        double tmpll=Egll;
74        double belll=Egll;
75
76        ivec tmpindeces;
77        ivec maxindeces=indeces;
78
79
80        cout << "bb:(" << indeces <<") ll=" << Egll <<endl;
81
82        //try to remove only one rv
83        for ( i=0;i<end;i++ ) {
84                //copy original
85                Li = Vo._L();
86                Li0 = Vo0._L();
87                //remove stuff
88                Li.del_col ( i+1 );
89                Li0.del_col ( i+1 );
90                Vp.ldform ( Li,Vo._D() );
91                Vp0.ldform ( Li0,Vo0._D() );
92                tmpll = Eg.lognc()-Eg0.lognc(); // likelihood is difference of norm. coefs.
93
94                cout << "i=(" << i <<") ll=" << tmpll <<endl;
95
96                //
97                if ( tmpll > Egll ) { //increase of the likelihood
98                        tmpindeces = indeces;
99                        tmpindeces.del ( i );
100                        //search for a better match in this substructure
101                        belll=egiw_bestbelow ( Eg, Eg0, tmpll, tmpindeces );
102                        if ( belll>maxll ) { //better match found
103                                maxll = belll;
104                                maxindeces = tmpindeces;
105                        }
106                }
107        }
108        indeces = maxindeces;
109        return maxll;
110}
111
112ivec ARX::structure_est ( egiw est0 ) {
113        ivec ind=linspace ( 1,rv.count()-1 );
114        egiw_bestbelow ( est, est0, est.lognc()- est0.lognc(), ind );
115        return ind;
116}
Note: See TracBrowser for help on using the browser.