Changeset e433e42 in tol
- Timestamp:
- Mar 11, 2009, 3:52:31 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 1941f9c
- Parents:
- f2ee099
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_arimaBlock.tol
rf2ee099 re433e42 184 184 VMatrix Li_ar = Rand(0,0,0,0); 185 185 VMatrix L_ma = Rand(0,0,0,0); 186 Set Li_ar_factors = Copy(Empty); 187 Set L_ma_factors = Copy(Empty); 186 188 //WriteLn("TRACE"+_MID+" initialize block["<<resBlockNum_+"] 2.2.7 "+Time); 187 189 Set segment->ArimaAuxInfo := 188 190 [[ 189 191 numPar, m, difDegree, p, q, numDifData, 190 dif, ar, ma, Li_ar, L_ma ,192 dif, ar, ma, Li_ar, L_ma ,Li_ar_factors, L_ma_factors, 191 193 D, equIdxVec 192 194 ]]; … … 195 197 }; 196 198 197 //////////////////////////////////////////////////////////////////////////// 198 Text _.autodoc.member.calcArimaBlockLi = 199 200 //////////////////////////////////////////////////////////////////////////// 201 Text _.autodoc.member.covDecomp.FastChol = 199 202 "Calculates the Choleski decomposition and its inverse for a block with " 200 "ARIMA struct"; 201 Real calcArimaBlockLi(BSR.NoiseDistrib segment) 202 //////////////////////////////////////////////////////////////////////////// 203 { 204 If(_.blockDef::_.config::bsr.arimaFilter!= 205 BysMcmc::Options::Arima.Filter::FastChol, 0, { 206 //WriteLn("TRACE"+_MID+" calcArimaBlockLi ["+segment->Name+"] 1 "); 203 "ARIMA struct using ARMAProcess::FastCholeskiCovFactor over full ARMA " 204 "structure"; 205 Real covDecomp.FastChol(BSR.NoiseDistrib segment) 206 //////////////////////////////////////////////////////////////////////////// 207 { 207 208 Set aux = segment->ArimaAuxInfo; 208 209 Real m = aux::m; 209 210 NameBlock fastChol = ARMAProcess::FastCholeskiCovFactor(aux::ar, aux::ma, m); 210 211 Real If(VRows(fastChol::_.Li_ar)<=0, CMsg::Coded::show 211 (BysMcmc::_.cmsg::_.invCholFac,[[_MID+ " MAfactor of equations block "+segment->Name]]));212 (BysMcmc::_.cmsg::_.invCholFac,[[_MID+ " AR factor of equations block "+segment->Name]])); 212 213 Real If(VRows(fastChol::_.L_ma)<=0, CMsg::Coded::show 213 214 (BysMcmc::_.cmsg::_.invCholFac,[[_MID+ " MA factor of equations block "+segment->Name]])); … … 215 216 VMatrix aux::L_ma := fastChol::_.L_ma; 216 217 1 217 })}; 218 219 //////////////////////////////////////////////////////////////////////////// 220 Text _.autodoc.member.calcAllArimaBlockLi = 218 }; 219 220 //////////////////////////////////////////////////////////////////////////// 221 Text _.autodoc.member.filterJustBlock.FastChol = 222 "Filters matrix by Choleski decomposition of ARIMA covarianze of a " 223 "noise block that was decomposed using covDecomp.FastChol method"; 224 VMatrix filterJustBlock.FastChol(BSR.NoiseDistrib segment, VMatrix X) 225 //////////////////////////////////////////////////////////////////////////// 226 { 227 //WriteLn("TRACE"+_MID+" filterJustBlock ["+segment->Name+"] 1"); 228 Set aux = segment->ArimaAuxInfo; 229 CholeskiSolve(aux::L_ma,aux::Li_ar*X,"PtL") 230 }; 231 232 //////////////////////////////////////////////////////////////////////////// 233 Text _.autodoc.member.covDecomp.FastCholSea = 234 "Calculates the Choleski decomposition and its inverse for a block with " 235 "ARIMA struct using ARMAProcess::FastCholeskiCovFactor over each seasonal " 236 "component of ARMA structure in an independent way"; 237 Real covDecomp.FastCholSea(BSR.NoiseDistrib segment) 238 //////////////////////////////////////////////////////////////////////////// 239 { 240 Set aux = segment->ArimaAuxInfo; 241 Real m = aux::m; 242 Set aux::Li_ar_factors := Copy(Empty); 243 Set aux::L_ma_factors := Copy(Empty); 244 Set EvalSet(segment->Arima, Real(ARIMAStruct factor) 245 { 246 NameBlock fastChol = ARMAProcess::FastCholeskiCovFactor(factor->AR, factor->MA, m); 247 Real If(VRows(fastChol::_.Li_ar)<=0, CMsg::Coded::show 248 (BysMcmc::_.cmsg::_.invCholFac,[[_MID+ " AR factor of equations block "+segment->Name]])); 249 Real If(VRows(fastChol::_.L_ma)<=0, CMsg::Coded::show 250 (BysMcmc::_.cmsg::_.invCholFac,[[_MID+ " MA factor of equations block "+segment->Name]])); 251 Set Append(aux::Li_ar_factors, [[ fastChol::_.Li_ar ]]); 252 Set Append(aux::L_ma_factors, [[ fastChol::_.L_ma ]]); 253 1 254 }); 255 1 256 }; 257 258 //////////////////////////////////////////////////////////////////////////// 259 Text _.autodoc.member.filterJustBlock.FastCholSea = 260 "Filters matrix by Choleski decomposition of ARIMA covarianze of a " 261 "noise block that was decomposed using covDecomp.FastCholSea method"; 262 VMatrix filterJustBlock.FastCholSea(BSR.NoiseDistrib segment, VMatrix X) 263 //////////////////////////////////////////////////////////////////////////// 264 { 265 //WriteLn("TRACE"+_MID+" filterJustBlock ["+segment->Name+"] 1"); 266 Set aux = segment->ArimaAuxInfo; 267 VMatrix F = X; 268 Set For(1,Card(segment->Arima), Real(Real k) 269 { 270 VMatrix F := CholeskiSolve(aux::L_ma_factors[k],aux::Li_ar_factors[k]*F,"PtL"); 271 1 272 }); 273 F 274 }; 275 276 //////////////////////////////////////////////////////////////////////////// 277 Text _.autodoc.member.covDecomp.DifEq = 278 "Does bothing due to DifEq requires no previous action to filter"; 279 Real covDecomp.DifEq(BSR.NoiseDistrib segment) 280 //////////////////////////////////////////////////////////////////////////// 281 { 282 1 283 }; 284 285 //////////////////////////////////////////////////////////////////////////// 286 Text _.autodoc.member.filterJustBlock.DifEq = 287 "Filters matrix by Choleski decomposition of ARIMA covarianze of a " 288 "noise block solving ARMA difference equations with zero as initial values"; 289 VMatrix filterJustBlock.DifEq(BSR.NoiseDistrib segment, VMatrix X) 290 //////////////////////////////////////////////////////////////////////////// 291 { 292 //WriteLn("TRACE"+_MID+" filterJustBlock ["+segment->Name+"] 1"); 293 Set aux = segment->ArimaAuxInfo; 294 DifEq(aux::ma/aux::ar,X) 295 }; 296 /* */ 297 //////////////////////////////////////////////////////////////////////////// 298 Real covDecomp(BSR.NoiseDistrib segment) 299 //////////////////////////////////////////////////////////////////////////// 300 { 301 Eval("covDecomp."+ _.blockDef::_.config::bsr.arimaFilter+"(segment)") 302 }; 303 //////////////////////////////////////////////////////////////////////////// 304 VMatrix filterJustBlock(BSR.NoiseDistrib segment, VMatrix X) 305 //////////////////////////////////////////////////////////////////////////// 306 { 307 Eval("filterJustBlock."+ _.blockDef::_.config::bsr.arimaFilter+"(segment,X)") 308 }; 309 /* * / 310 Code covDecomp = If(FunctionExist("Real", "covDecomp."+config::bsr.arimaFilter), 311 { 312 FindCode("Real", "covDecomp."+ config::bsr.arimaFilter) 313 }, 314 { 315 WriteLn(MID_+"Cannot find ARMA covariance decomposition method "+ 316 "covDecomp."+config::bsr.arimaFilter+ 317 "\nUsing default one "+covDecomp.FastChol); 318 covDecomp.FastChol 319 }); 320 Code filterJustBlock = If(FunctionExist("VMatrix", "filterJustBlock."+config::bsr.arimaFilter), 321 { 322 FindCode("Real", "filterJustBlock."+ config::bsr.arimaFilter) 323 }, 324 { 325 WriteLn(MID_+"Cannot find ARMA filtering method "+ 326 "filterJustBlock."+config::bsr.arimaFilter+ 327 "\nUsing default one "+filterJustBlock.FastChol); 328 filterJustBlock.FastChol 329 }); 330 /* */ 331 332 //////////////////////////////////////////////////////////////////////////// 333 Text _.autodoc.member.covDecompAll = 221 334 "Calculates the inverse of Choleski decomposition of ARIMA blocks all " 222 335 "together"; 223 Real calcAllArimaBlockLi(Real numSim) 224 //////////////////////////////////////////////////////////////////////////// 225 { 226 Set If(And(Or(numSim<=1,_.blockDef::enabled), 227 _.blockDef::_.config::bsr.arimaFilter== 228 BysMcmc::Options::Arima.Filter::FastChol), 229 { 230 //WriteLn("TRACE"+_MID+" calcAllArimaBlockLi ("<<numSim+") "); 231 EvalSet(_.armaParamBlock, calcArimaBlockLi) 232 }); 336 Real covDecompAll(Real numSim) 337 //////////////////////////////////////////////////////////////////////////// 338 { 339 Set EvalSet(_.armaParamBlock, covDecomp); 233 340 1 234 341 }; … … 272 379 1 273 380 }; 381 274 382 Real _.cannotDrawArma = False; 275 383 Real _.initialized = initialize(0); … … 288 396 aux 289 397 }; 290 Real _.createFilters = c alcAllArimaBlockLi(0);398 Real _.createFilters = covDecompAll(0); 291 399 292 400 //////////////////////////////////////////////////////////////////////////// … … 303 411 1 304 412 }; 305 ////////////////////////////////////////////////////////////////////////////306 Text _.autodoc.member.filterJustBlock =307 "Filters matrix by Choleski decomposition of ARIMA covarianze of a "308 "noise block";309 VMatrix filterJustBlock(BSR.NoiseDistrib segment, VMatrix X)310 ////////////////////////////////////////////////////////////////////////////311 {312 //WriteLn("TRACE"+_MID+" filterJustBlock ["+segment->Name+"] 1");313 Set aux = segment->ArimaAuxInfo;314 If(Or(aux::p,aux::q),315 {316 Case(317 _.blockDef::_.config::bsr.arimaFilter==318 BysMcmc::Options::Arima.Filter::FastChol,319 CholeskiSolve(aux::L_ma,aux::Li_ar*X,"PtL"),320 _.blockDef::_.config::bsr.arimaFilter==321 BysMcmc::Options::Arima.Filter::DifEq,322 DifEq(aux::ma/aux::ar,X) )323 },324 {325 X326 })327 };328 413 329 414 //////////////////////////////////////////////////////////////////////////// … … 342 427 //////////////////////////////////////////////////////////////////////////// 343 428 { 344 /*345 Set s = EvalSet(_.armaParamBlock, VMatrix set.filterArima(BSR.NoiseDistrib segment)346 {347 VMatrix aux1 = filterJustBlock(segment,SubRow(DX, segment->EquIdx));348 enlargeRowsVMatrix(aux1, (segment->ArimaAuxInfo)::equIdxVec)349 });350 SetSum(s)351 */352 429 Set s = EvalSet(_.armaParamBlock, Set set.filterArima(BSR.NoiseDistrib segment) 353 430 { … … 494 571 Real Do setStore(values); 495 572 //WriteLn("TRACE"+_MID+" draw.scalar blockDef="<<Matrix VMat2Mat(Tra(_.blockDef::_.store))); 496 Real Do c alcAllArimaBlockLi(numSim);573 Real Do covDecompAll(numSim); 497 574 //WriteLn("TRACE"+_MID+" draw 5 "); 498 575 Real _.blockDef::checkNonFiniteValues(numSim); … … 506 583 //////////////////////////////////////////////////////////////////////////// 507 584 { 508 If(_.blockDef::enabled, 585 If(And(_.blockDef::enabled, 586 numSim%(_.blockDef::_.config::bsr.arimaSkipIter)==1), 509 587 { 510 588 draw.scalar(numSim, noise, sigBlk, False)
Note: See TracChangeset
for help on using the changeset viewer.
