Changeset ba4e2ac in tol
- Timestamp:
- Aug 25, 2009, 11:31:40 AM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- f7133bb
- Parents:
- bd637b5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/arima/_arma_process.tol
rbd637b5 rba4e2ac 10 10 [[ 11 11 Text _.autodoc.description = "Methods related with ARMA process"; 12 13 Real drop = 1.E-8;14 12 15 13 //////////////////////////////////////////////////////////////////////////// … … 52 50 53 51 //////////////////////////////////////////////////////////////////////////// 54 VMatrix DoDrop(VMatrix X)55 ////////////////////////////////////////////////////////////////////////////56 {57 Drop(X,drop)58 };59 60 ////////////////////////////////////////////////////////////////////////////61 52 VMatrix CholeskiFactorCov(VMatrix cov) 62 53 //////////////////////////////////////////////////////////////////////////// 63 54 { 64 //WriteLn("TRACE CholeskiFactorCov("+FullName(cov)+") Rows(cov)="<<VRows(cov)+" Sparsity(cov)="<<Real(VNonNullCells(cov)/VRows(cov)^2));65 VMatrix c = ARMAProcess::DoDrop(cov);55 //WriteLn("TRACE CholeskiFactorCov("+FullName(cov)+") VRows(cov)="<<VRows(cov)+" Sparsity(cov)="<<Real(VNonNullCells(cov)/VRows(cov)^2)); 56 VMatrix c = Drop(cov,1.E-16/VRows(cov)^2); 66 57 //WriteLn("TRACE CholeskiFactorCov Sparsity(c)="<<Real(VNonNullCells(c)/VRows(c)^2)); 67 58 //Real t0 = Copy(Time); … … 85 76 { 86 77 Real n = VRows(S); 87 ARMAProcess::DoDrop(ARMAProcess::AvoidSymRoundErr(Case(78 VMatrix s = ARMAProcess::AvoidSymRoundErr(Case( 88 79 m==n, S, 89 80 m<n, Sub(S,1,1,m,m), … … 100 91 )+Pol2VMat(pol, m, m); 101 92 aux 102 }))) 93 })); 94 Drop(s,1.E-16/n^2) 103 95 }; 104 96 … … 108 100 { 109 101 Real n = VRows(L); 110 ARMAProcess::DoDrop(Case(102 VMatrix L_ = Case( 111 103 m==n, L, 112 104 m<n, Sub(L,1,1,m,m), … … 119 111 )+Pol2VMat(pol, m, m); 120 112 aux 121 })) 113 }); 114 Drop(L_,1.E-16/n^2) 122 115 }; 123 116 … … 175 168 Real _.n = Max(_.p,_.q)+_.p+1; 176 169 //Real _trc.6 = { WriteLn("TRACE FastCholeskiCovFactor _.n=" << _.n); 0 }; 177 170 Real drop = 1.E-16 / _.n^2; 178 171 //Calculates de main minor of length _.n of just pure AR covariance 179 172 VMatrix _.cov_ar_n = 180 ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,1,_.n), _.n, _.n));173 Drop(Pol2VMat(ARMATACov(_.ar,1,_.n), _.n, _.n),drop); 181 174 //Does Choleski factorization of pure AR 182 175 //Real _trc.7 = { WriteLn("TRACE FastCholeskiCovFactor _.cov_ar_n=" << (Matrix VMat2Mat(_.cov_ar_n))); 0 }; … … 184 177 //Real _trc.8 = { WriteLn("TRACE FastCholeskiCovFactor _.L_ar_n=" << (Matrix VMat2Mat(_.L_ar_n))); 0 }; 185 178 //Calculates the inverse of Choleski factorization of pure AR 186 VMatrix _.Li_ar_n = ARMAProcess::DoDrop(CholeskiSolve(_.L_ar_n,Eye(_.n),"PtL"));179 VMatrix _.Li_ar_n = Drop(CholeskiSolve(_.L_ar_n,Eye(_.n),"PtL"),drop); 187 180 //Real _trc.9 = { WriteLn("TRACE FastCholeskiCovFactor _.Li_ar_n=" << (Matrix VMat2Mat(_.Li_ar_n))); 0 }; 188 181 //Extends main minor of length _.n to full data length _.m as Toplitz from 189 182 //last row. Terms _.n^2 is added and substracted to clean rounding error. 190 VMatrix _.Li_ar= 191 (ARMAProcess::ExtendBandedLowTriangToeplitz(_.Li_ar_n,_.m)+_.n^2)-_.n^2;183 VMatrix _.Li_ar= Drop( 184 ARMAProcess::ExtendBandedLowTriangToeplitz(_.Li_ar_n,_.m),drop); 192 185 //Real _trc.10 = { WriteLn("TRACE FastCholeskiCovFactor _.Li_ar=" << (Matrix VMat2Mat(_.Li_ar))); 0 }; 193 186 194 187 //Calculates de main minor of length _.n of joint ARMA covariance 195 188 VMatrix _.cov_arma_n = 196 ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,_.ma,_.n), _.n, _.n));189 Drop(Pol2VMat(ARMATACov(_.ar,_.ma,_.n), _.n, _.n),drop); 197 190 //Filters full ARMA covariance of AR factor 198 VMatrix _.cov_ma_n = (_.Li_ar_n*_.cov_arma_n*Tra(_.Li_ar_n)+_.n^2)-_.n^2;191 VMatrix _.cov_ma_n = Drop(_.Li_ar_n*_.cov_arma_n*Tra(_.Li_ar_n),drop); 199 192 //Extends main minor of length _.n to full data length _.m as Toplitz from 200 193 //last row and column getting a symmetric and sparse banded matrix 201 194 //Real _trc.11 = { WriteLn("TRACE FastCholeskiCovFactor _.cov_ma_n=" << (Matrix VMat2Mat(_.cov_ma_n))); 0 }; 202 VMatrix _.cov_ma_m =203 (ARMAProcess::ExtendBandedSymToeplitz(_.cov_ma_n,_.m)+_.n^2)-_.n^2;195 VMatrix _.cov_ma_m = Drop( 196 ARMAProcess::ExtendBandedSymToeplitz(_.cov_ma_n,_.m),drop); 204 197 //Real _trc.12 = { WriteLn("TRACE FastCholeskiCovFactor _.cov_ma_m=" << (Matrix VMat2Mat(_.cov_ma_m))); 0 }; 205 198 //Does Choleski factorization of pseudo MA factor 206 199 VMatrix _.L_ma = ARMAProcess::CholeskiFactorCov(_.cov_ma_m); 207 200 //Converts to Cholmod.R.Sparse 208 VMatrix _.L_ma_sp = ARMAProcess::DoDrop(Convert(_.L_ma,"Cholmod.R.Sparse"));201 VMatrix _.L_ma_sp = Drop(Convert(_.L_ma,"Cholmod.R.Sparse"),drop); 209 202 //Calculates de logarithm of determinant of _.m ARMA covarianze 210 203 Real _.logDetCov = 2*(-VMatSum(Log(SubDiag(_.Li_ar,0)))+ … … 255 248 Real p = Degree(ar); 256 249 Real q = Degree(ma); 250 Real drop = 1.E-16/m^2; 257 251 //WriteLn("TRACE Eval.Almagro Begin "+Time); 258 252 //WriteLn("TRACE Eval.Almagro(p"<<p+",q="<<q+",m="<<m); … … 311 305 _.p & _.q, 312 306 { 313 VMatrix cov_zz = ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p));307 VMatrix cov_zz = Drop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p),drop); 314 308 //WriteLn("_.cov_zz = "<<_.cov_zz); 315 309 VMatrix cov_aa = Eye(_.q); … … 325 319 _.p & !_.q, 326 320 { 327 ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p))321 Drop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p),drop) 328 322 //WriteLn("_.cov_zz = "<<_.cov_zz); 329 323 }, … … 341 335 { 342 336 aux = solve.LLt(_.L_u,Eye(_.q_p)); 343 ARMAProcess::DoDrop(ARMAProcess::AvoidSymRoundErr(aux))337 Drop(ARMAProcess::AvoidSymRoundErr(aux),drop) 344 338 }; 345 339 //Real _trc.4 = { WriteLn("TRACE Eval.Almagro Creating _.L_u_sp "+Time); 0 }; 346 VMatrix _.L_u_sp = ARMAProcess::DoDrop(Convert(_.L_u,"Cholmod.R.Sparse"));340 VMatrix _.L_u_sp = Drop(Convert(_.L_u,"Cholmod.R.Sparse"),drop); 347 341 //Real _trc.5 = { WriteLn("TRACE Eval.Almagro Creating cov_G "+Time); 0 }; 348 342 Real _.det_cov_u = 2*VMatSum(Log(SubDiag(_.L_u_sp,0))); 349 VMatrix _.H1 = ARMAProcess::DoDrop(Pol2VMat(F^_.p*(1-_.ar), _.m, _.p));350 VMatrix _.H2 = ARMAProcess::DoDrop(Pol2VMat(F^_.q*(_.ma-1), _.m, _.q));343 VMatrix _.H1 = Drop(Pol2VMat(F^_.p*(1-_.ar), _.m, _.p),drop); 344 VMatrix _.H2 = Drop(Pol2VMat(F^_.q*(_.ma-1), _.m, _.q),drop); 351 345 VMatrix _.H = _.H1 | _.H2; 352 VMatrix _.G = ARMAProcess::DoDrop(353 DifEq(1/_.ma, _.H, Rand(0,_.q_p,0,0), Rand(_.q,_.q_p,0,0) ) );346 VMatrix _.G = Drop( 347 DifEq(1/_.ma, _.H, Rand(0,_.q_p,0,0), Rand(_.q,_.q_p,0,0) ),drop); 354 348 VMatrix _.GtG = MtMSqr(_.G); 355 349 VMatrix _.cov_G = _.covi_u + _.GtG; … … 357 351 VMatrix _.L_G = ARMAProcess::CholeskiFactorCov(_.cov_G); 358 352 //Real _trc.7 = { WriteLn("TRACE Eval.Almagro Creating _.L_G_sp "+Time); 0 }; 359 VMatrix _.L_G_sp = ARMAProcess::DoDrop(Convert(_.L_G,"Cholmod.R.Sparse"));353 VMatrix _.L_G_sp = Drop(Convert(_.L_G,"Cholmod.R.Sparse"),drop); 360 354 Real _.det_cov_G = 2*VMatSum(Log(SubDiag(_.L_G_sp,0))); 361 355 Real _.det_cov_z = _.det_cov_u + _.det_cov_G;
Note: See TracChangeset
for help on using the changeset viewer.
