- Timestamp:
- 07/25/08 15:04:05 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
matlab/mex/linefit2.cpp
r133 r135 12 12 // Convert input variables to IT++ format 13 13 mat Data = mxArray2mat ( input[0] ); 14 if ( Data.rows()!=2)15 { if ( Data.cols()==2) Data=Data.T(); else mexErrMsgTxt("Data are not 2D!");}14 if ( Data.rows() !=2 ) 15 { if ( Data.cols() ==2 ) Data=Data.T(); else mexErrMsgTxt ( "Data are not 2D!" );} 16 16 int ilow = mxArray2int ( input[1] )-1; 17 17 int ihi = mxArray2int ( input[2] )-1; //coreection for different indeces … … 20 20 // ------------------ Start of routine --------------------------- 21 21 int ndat=Data.cols(); 22 int npsi=Data.rows() +1; //add a constant22 int npsi=Data.rows() +1; //add a constant 23 23 RV thr ( "1","{ theta_r }",vec_1 ( npsi ),vec_1 ( 0 ) ); 24 24 25 mat V0=1e-8*eye ( npsi ); V0 ( 0,0 ) =1 0.0;26 vec rgr (npsi);27 double nu0= 2;25 mat V0=1e-8*eye ( npsi ); V0 ( 0,0 ) =1e-4; 26 vec rgr ( npsi ); 27 double nu0=0.1; 28 28 // fitting a linear part => third coef is "1" 29 rgr (2) = 1.0;29 rgr ( 2 ) = 1.0; 30 30 31 31 // RESULTS 32 mat Tlls=zeros (ihi,ihi);32 mat Tlls=zeros ( ihi+1,ihi+1); 33 33 // AR model 34 34 ARX Ar ( thr,V0,nu0 ); 35 35 36 36 //Initialize 37 for ( int i=ilow; i<ihi; i++) {38 rgr.set_subvector (0,Data.get_col ( i ));39 Ar.bayes (rgr);37 for ( int i=ilow+2; i<ihi-2; i++ ) { 38 rgr.set_subvector ( 0,Data.get_col ( i ) ); 39 Ar.bayes ( rgr ); 40 40 } 41 Ar.get_parameters(V0,nu0);42 V0 /=V0(1,1);43 nu0=3;44 Ar.set_parameters(V0,nu0);45 46 41 // FLATTEN 47 for (int i=ilow; i<ihi; i++) { 48 Ar.set_parameters(V0,nu0); 49 for (int t=i+1; t<ihi; t++) { 50 rgr.set_subvector(0,Data.get_col ( t )); 51 Ar.bayes(rgr); 52 Tlls(i,t)=Ar._tll(); 42 /* Ar.get_parameters ( V0,nu0 ); 43 V0 *=1.0/nu0/10000.; // same flattening factor as for nu0 44 nu0=1./10000.;*/ 45 Ar.set_parameters ( V0,nu0 ); 46 47 for ( int i=ilow; i<=ihi; i++ ) { 48 Ar.set_parameters ( V0,nu0 ); 49 for ( int t=i; t<=ihi; t++ ) { 50 rgr.set_subvector ( 0,Data.get_col ( t ) ); 51 Ar.bayes ( rgr ); 52 Tlls ( i,t ) =Ar._tll(); 53 53 } 54 54 } 55 55 56 max_index (Tlls,ilow,ihi);56 max_index ( Tlls,ilow,ihi ); 57 57 58 58 // ------------------ End of routine ----------------------------- 59 59 60 60 output[0] = mxCreateDoubleMatrix ( 2,1, mxREAL ); 61 ivec2mxArray ( vec_2(ilow+1,ihi+1) , output[0] );61 ivec2mxArray ( vec_2 ( ilow+1,ihi+1 ) , output[0] ); 62 62 63 63 if ( n_output>1 ) { 64 // Create output vectors65 output[1] = mxCreateDoubleMatrix ( Tlls.rows(),Tlls.cols(), mxREAL );66 // Convert the IT++ format to Matlab format for output67 mat2mxArray ( Tlls, output[1] );64 // Create output vectors 65 output[1] = mxCreateDoubleMatrix ( Tlls.rows(),Tlls.cols(), mxREAL ); 66 // Convert the IT++ format to Matlab format for output 67 mat2mxArray ( Tlls, output[1] ); 68 68 } 69 69 70 if ( n_output>2 ) { 71 Ar.set_parameters ( V0,nu0 ); 72 // Redo Ar for given points 73 for ( int i=ilow; i<=ihi; i++ ) { 74 rgr.set_subvector ( 0,Data.get_col ( i ) ); 75 Ar.bayes ( rgr ); 76 } 77 78 // Create output vectors 79 output[2] = mxCreateDoubleMatrix ( 3,1, mxREAL ); 80 // Convert the IT++ format to Matlab format for output 81 // mat2mxArray ( Ar._epdf().mean(), output[2] ); 82 mat2mxArray ( Ar._epdf().mean(), output[2] ); 83 } 84 70 85 }