Changeset 60
- Timestamp:
- 03/31/08 13:53:36 (17 years ago)
- Files:
-
- 1 added
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified BDM.kdevelop ¶
r45 r60 24 24 <filelistdirectory>/home/smidl/work/mixpp</filelistdirectory> 25 25 <run> 26 <mainprogram>/home/smidl/work/mixpp/tests/pmsm_sim </mainprogram>26 <mainprogram>/home/smidl/work/mixpp/tests/pmsm_sim2</mainprogram> 27 27 <directoryradio>custom</directoryradio> 28 28 <customdirectory>/home/smidl/work/mixpp</customdirectory> … … 171 171 <tree> 172 172 <hidepatterns>*.o,*.lo,CVS,*~,cmake*,Makefile</hidepatterns> 173 <hidenonprojectfiles> true</hidenonprojectfiles>173 <hidenonprojectfiles>false</hidenonprojectfiles> 174 174 <showvcsfields>false</showvcsfields> 175 175 </tree> -
TabularUnified BDM.kdevelop.filelist ¶
r45 r60 28 28 tests/CMakeLists.txt 29 29 tests/pmsm_sim.cpp 30 tests/pmsm_sim2.cpp 30 31 tests/pmsm_unkQ.cpp 31 32 tests/pmsm_unkQpf.cpp … … 38 39 tests/testResample.cpp 39 40 tests/testSmp.cpp 41 tests/testbidiff.cpp -
TabularUnified bdm/estim/libPF.cpp ¶
r32 r60 4 4 5 5 using std::endl; 6 7 6 8 7 void PF::bayes ( const vec &dt ) { -
TabularUnified bdm/estim/libPF.h ¶
r33 r60 19 19 20 20 using namespace itpp; 21 22 //UGLY HACK 23 extern double PF_SSAT;//used for StrSim:06 test... if length>0 the value is written. 21 24 22 25 /*! … … 60 63 61 64 class MPF : public PF { 62 BM_T* Bms[1000 ];65 BM_T* Bms[10000]; 63 66 64 67 //! internal class for MPDF providing composition of eEmp with external components … … 105 108 // 106 109 107 if ( n>1000 ) it_error ( "increase 1000 here!" );110 if ( n>10000 ) it_error ( "increase 10000 here!" ); 108 111 109 112 for ( int i=0;i<n;i++ ) { … … 126 129 for ( int i=0;i<n;i++ ) {Bms[i]->condition ( _samples ( i ) );} 127 130 } 131 132 //SimStr: 133 double SSAT; 128 134 }; 129 135 … … 132 138 int i; 133 139 vec lls ( n ); 140 vec llsP ( n ); 134 141 ivec ind; 135 142 double mlls=-std::numeric_limits<double>::infinity(); 136 143 144 // StrSim:06 145 double sumLWL=0.0; 146 double sumL2WL=0.0; 147 double WL = 0.0; 148 137 149 for ( i=0;i<n;i++ ) { 138 150 //generate new samples from paramater evolution model; 139 _samples ( i ) = par.samplecond ( _samples ( i ), lls ( i ) );151 _samples ( i ) = par.samplecond ( _samples ( i ), llsP ( i ) ); 140 152 Bms[i]->condition ( _samples ( i ) ); 141 153 Bms[i]->bayes ( dt ); … … 144 156 if ( lls ( i ) >mlls ) mlls=lls ( i ); //find maximum likelihood (for numerical stability) 145 157 } 158 159 if ( true ) { 160 for ( i=0;i<n;i++ ) { 161 WL = _w ( i ) *exp ( llsP ( i ) ); //using old weights! 162 sumLWL += exp ( lls ( i ) ) *WL; 163 sumL2WL += exp ( 2*lls ( i ) ) *WL; 164 } 165 SSAT = sumL2WL/(sumLWL*sumLWL); 166 } 146 167 147 168 // compute weights … … 150 171 } 151 172 152 _w /=sum(_w); //? 153 154 double eff = 1.0/( _w*_w ); 173 _w /=sum ( _w ); //? 174 175 176 177 double eff = 1.0/ ( _w*_w ); 155 178 if ( eff < ( 0.1*n ) ) { 156 179 ind = est.resample(); … … 161 184 //fixme this would require new assignment operator 162 185 // *Bms[i] = *Bms[ind ( i ) ]; 163 186 164 187 // poor-man's solution: replicate constructor here 165 188 // copied from MPF::MPF … … 170 193 } 171 194 }; 172 cout << '.'; 195 cout << '.'; 173 196 } 174 197 } -
TabularUnified bdm/stat/libEF.cpp ¶
r32 r60 60 60 61 61 vec mgamma::samplecond ( vec &cond, double &ll ) { 62 *_beta=k / cond;62 this->condition(cond ); 63 63 vec smp = epdf.sample(); 64 64 ll = epdf.evalpdflog ( smp ); -
TabularUnified bdm/stat/libEF.h ¶
r51 r60 96 96 double eval ( const vec &val ) const ; 97 97 double evalpdflog ( const vec &val ) const; 98 vec mean() const {return mu;}98 vec mean() const {return mu;} 99 99 100 100 //Access methods … … 140 140 //! Returns poiter to alpha and beta. Potentially dengerous: use with care! 141 141 void _param ( vec* &a, vec* &b ) {a=αb=β}; 142 vec mean() const {vec pom(alpha); pom/=beta; return pom;}142 vec mean() const {vec pom ( alpha ); pom/=beta; return pom;} 143 143 }; 144 144 /* … … 228 228 */ 229 229 class mgamma : public mEF { 230 protected: 230 231 //! Internal epdf that arise by conditioning on \c rvc 231 232 egamma epdf; … … 247 248 }; 248 249 250 /*! 251 \brief Gamma random walk around a fixed point 252 253 Mean value, \f$\mu\f$, of this density is given by a geometric combination of \c rvc and given fixed point, $p$. $k$ is the coefficient of the geometric combimation 254 \f[ \mu = \mu_{t-1} ^{l} p^{1-l}\f] 255 256 Standard deviation of the random walk is proportional to one $k$-th the mean. 257 This is achieved by setting \f$\alpha=k\f$ and \f$\beta=k/\mu\f$. 258 259 The standard deviation of the walk is then: \f$\mu/\sqrt(k)\f$. 260 */ 261 class mgamma_fix : public mgamma { 262 protected: 263 double l; 264 vec refl; 265 public: 266 //! Constructor 267 mgamma_fix ( const RV &rv,const RV &rvc ) : mgamma ( rv,rvc ),refl ( rv.count() ) {}; 268 //! Set value of \c k 269 void set_parameters ( double k0 , vec ref0, double l0 ) { 270 mgamma::set_parameters ( k0 ); 271 refl=pow ( ref0,1.0-l0 );l=l0; 272 }; 273 274 void condition ( const vec &val ) {vec mean=elem_mult ( refl,pow ( val,l ) ); *_beta=k/mean;}; 275 }; 276 249 277 //! Switch between various resampling methods. 250 278 enum RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; … … 264 292 public: 265 293 //! Default constructor 266 eEmp ( const RV &rv0 ,int n0 ) :epdf ( rv0 ),n(n0),w(n),samples(n) {};294 eEmp ( const RV &rv0 ,int n0 ) :epdf ( rv0 ),n ( n0 ),w ( n ),samples ( n ) {}; 267 295 //! Set sample 268 296 void set_parameters ( const vec &w0, epdf* pdf0 ); … … 276 304 vec sample() const {it_error ( "Not implemented" );return 0;} 277 305 //! inherited operation : NOT implemneted 278 double evalpdflog(const vec &val) const {it_error ( "Not implemented" );return 0.0;} 279 vec mean()const {vec pom=zeros(rv.count()); 280 for (int i=0;i<n;i++){pom+=samples(i)*w(i);} 306 double evalpdflog ( const vec &val ) const {it_error ( "Not implemented" );return 0.0;} 307 vec mean() const { 308 vec pom=zeros ( rv.count() ); 309 for ( int i=0;i<n;i++ ) {pom+=samples ( i ) *w ( i );} 281 310 return pom; 282 311 } … … 287 316 288 317 template<class sq_T> 289 enorm<sq_T>::enorm ( RV &rv ) :eEF (rv), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {};318 enorm<sq_T>::enorm ( RV &rv ) :eEF ( rv ), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 290 319 291 320 template<class sq_T> … … 320 349 321 350 template<class sq_T> 322 mat enorm<sq_T>::sample ( int N ) const {351 mat enorm<sq_T>::sample ( int N ) const { 323 352 mat X ( dim,N ); 324 353 vec x ( dim ); … … 346 375 template<class sq_T> 347 376 double enorm<sq_T>::evalpdflog ( const vec &val ) const { 348 if ( !cached ) {it_error ("this should not happen, see cached");}377 if ( !cached ) {it_error ( "this should not happen, see cached" );} 349 378 350 379 // 1.83787706640935 = log(2pi) -
TabularUnified tests/CMakeLists.txt ¶
r54 r60 46 46 link_directories (${BDM_BINARY_DIR}/simulator_zdenek) 47 47 add_executable (pmsm_sim pmsm_sim.cpp) 48 add_executable (pmsm_sim2 pmsm_sim2.cpp) 48 49 target_link_libraries (pmsm_sim ${BdmLibs} pmsmsim netcdf_c++) 50 target_link_libraries (pmsm_sim2 ${BdmLibs} pmsmsim netcdf_c++)