Changeset 0c19991 in tol
- Timestamp:
- Aug 12, 2009, 10:34:58 AM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- d3756e3
- Parents:
- a2d7c82
- Location:
- tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs
- Files:
-
- 4 edited
-
_inputMissingBlock.tol (modified) (1 diff)
-
_mainLinearBlock.tol (modified) (2 diffs)
-
_outputMissingBlock.tol (modified) (1 diff)
-
_stdLinearBlock.tol (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_inputMissingBlock.tol
ra2d7c82 r0c19991 22 22 If(!Card(inputMissingBlock), 23 23 BysMcmc::Bsr::Gibbs::StdLinearBlock.Default(name, numBlock, firstCol, config), 24 BysMcmc::Bsr::Gibbs::StdLinear FullBlock blk = [[24 BysMcmc::Bsr::Gibbs::StdLinearBlock blk = [[ 25 25 //Given initial values of block variables 26 26 VMatrix _.store_ = Mat2VMat(SetMat(Extract(inputMissingBlock, 6))); -
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_mainLinearBlock.tol
ra2d7c82 r0c19991 30 30 If(!Card(varNames), 31 31 BysMcmc::Bsr::Gibbs::StdLinearBlock.Default(name,numBlock,firstCol,config), 32 BysMcmc::Bsr::Gibbs::StdLinear FullBlock blk = [[32 BysMcmc::Bsr::Gibbs::StdLinearBlock blk = [[ 33 33 34 34 //////////////////////////////////////////////////////////////////////////// 35 Real _ buildWorkSpace(VMatrixY, //Non filtered output36 VMatrixX, //Non filtered input37 BysMcmc::BlockSampler arm.blk) //ArimaBlock filter35 Real _do_buildWorkSpace(VMatrix Y, //Non filtered output 36 VMatrix X, //Non filtered input 37 BysMcmc::BlockSampler arm.blk) //ArimaBlock filter 38 38 //////////////////////////////////////////////////////////////////////////// 39 39 { 40 //WriteLn("TRACE"+_MID+" MainLinearBlock::_do_buildWorkSpace 0"); 40 41 BysMcmc::Bsr::Gibbs::WorkSpace.ArimaReg wsar = 41 42 [[ … … 44 45 NameBlock _.arm.blk = arm.blk 45 46 ]]; 47 //WriteLn("TRACE"+_MID+" MainLinearBlock::_do_buildWorkSpace 1"); 46 48 NameBlock _.ws := wsar; 49 //WriteLn("TRACE"+_MID+" MainLinearBlock::_do_buildWorkSpace 2"); 47 50 True 51 }; 52 53 //////////////////////////////////////////////////////////////////////////// 54 Real _buildWorkSpace(VMatrix Y, //Non filtered output 55 VMatrix X, //Non filtered input 56 BysMcmc::BlockSampler arm.blk) //ArimaBlock filter 57 //////////////////////////////////////////////////////////////////////////// 58 { 59 //WriteLn("TRACE"+_MID+" MainLinearBlock::_buildWorkSpace 0"); 60 If(!_.N1, 61 { 62 //WriteLn("TRACE"+_MID+" MainLinearBlock::_buildWorkSpace 1"); 63 _do_buildWorkSpace(Y,X,arm.blk) 64 }, 65 { 66 //WriteLn("TRACE"+_MID+" MainLinearBlock::_buildWorkSpace 2"); 67 VMatrix b1 = _.partialSampler::_.fixedValues; 68 VMatrix X1 = SubCol(X, _.i1); 69 VMatrix X2 = SubCol(X, _.i2); 70 VMatrix Y2 = Y - X1*b1; 71 _do_buildWorkSpace(Y2,X2,arm.blk) 72 }) 48 73 }; 49 74 Code _.buildWorkSpace = _buildWorkSpace; -
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_outputMissingBlock.tol
ra2d7c82 r0c19991 21 21 If(!Card(outputMissingBlock), 22 22 BysMcmc::Bsr::Gibbs::StdLinearBlock.Default(name, numBlock, firstCol, config), 23 BysMcmc::Bsr::Gibbs::StdLinear FullBlock blk = [[23 BysMcmc::Bsr::Gibbs::StdLinearBlock blk = [[ 24 24 //Given initial values of block variables 25 25 VMatrix _.store = Mat2VMat(SetMat(Extract(outputMissingBlock, 6))); -
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_stdLinearBlock.tol
ra2d7c82 r0c19991 103 103 VMatrix _.beta = Rand(0,0,0,0); 104 104 105 //////////////////////////////////////////////////////////////////////////// 105 106 Real putMID(Text mid) 107 //////////////////////////////////////////////////////////////////////////// 106 108 { 107 109 Text _MID := mid; … … 120 122 Real matchConstrains(VMatrix beta0, VMatrix A, VMatrix a) 121 123 //////////////////////////////////////////////////////////////////////////// 122 { 123 124 { 124 125 //WriteLn("TRACE "+_MID+" matchConstrains 1 beta0="<<beta0); 125 126 Real ok = TRUE; … … 469 470 ////////////////////////////////////////////////////////////////////////////// 470 471 { 471 BysMcmc::Bsr::Gibbs::StdLinearSubBlock subBlock =472 BysMcmc::Bsr::Gibbs::StdLinearSubBlock freeBlock = 472 473 [[ Text _MID = mid ]]; 473 subBlock474 freeBlock 474 475 }; 475 476 … … 483 484 ////////////////////////////////////////////////////////////////////////////// 484 485 { 485 Real initialize.subBlocks(Real unused);486 Real matchConstrains(VMatrix beta0, VMatrix A, VMatrix a);487 488 ////////////////////////////////////////////////////////////////////////////489 Real initialize(Real unused)490 ////////////////////////////////////////////////////////////////////////////491 {492 initialize.subBlocks(unused)493 };494 486 495 487 //////////////////////////////////////////////////////////////////////////// … … 506 498 { 507 499 _.ws 500 }; 501 502 BysMcmc::Bsr::Gibbs::StdLinearSubBlock _.fullBlock = 503 BysMcmc::Bsr::Gibbs::StdLinearSubBlock.Build(_MID+"[_.fullBlock] "); 504 BysMcmc::Bsr::Gibbs::StdLinearSubBlock _.freeBlock = 505 BysMcmc::Bsr::Gibbs::StdLinearSubBlock.Build(_MID+"[_.freeBlock] "); 506 507 Set _.i1 = Copy(Empty); //_.partialSampler::getNonFreeIndex(0); 508 Set _.i2 = Copy(Empty); //_.partialSampler::getFreeIndex(0); 509 Real _.N1 = ?; 510 Real _.N2 = ?; 511 512 //////////////////////////////////////////////////////////////////////////// 513 Real initialize.subBlocks(Real unused) 514 //////////////////////////////////////////////////////////////////////////// 515 { 516 Set _.i1 := _.partialSampler::getNonFreeIndex(0); 517 Set _.i2 := _.partialSampler::getFreeIndex(0); 518 Real _.N1 := Card(_.i1); 519 Real _.N2 := Card(_.i2); 520 Code _.freeBlock::standarize := standarize; 521 Code _.freeBlock::getWorkSpace := getWorkSpace; 522 Real _.freeBlock::usePreconditioning := 523 _.config::bsr.linBlk.usePreconditioning; 524 Real _.freeBlock::cholesky.warningFreq := 525 _.config::bsr.cholesky.warningFreq; 526 Real _.freeBlock::truncMNormal.gibbsNumIter := 527 _.config::bsr.truncMNormal.gibbsNumIter; 528 Real _.freeBlock::drop_val := 529 _.config::bsr.linBlk.X.drop; 530 Real _.freeBlock::_.eps := 531 _.config::bsr.cholesky.epsilon*_.N2*(_.N2+1); 532 Real _.freeBlock::_.MH.useAfterIter := 533 Max(1,_.config::bsr.linBlk.MH.useAfterIter); 534 Real _.freeBlock::_.MH.maxRejected := 535 _.config::bsr.linBlk.MH.maxRejected; 536 Real _.freeBlock::_.MH.maxConsecutive := 537 _.config::bsr.linBlk.MH.maxConsecutive; 538 1 539 }; 540 541 //////////////////////////////////////////////////////////////////////////// 542 Real initialize(Real unused) 543 //////////////////////////////////////////////////////////////////////////// 544 { 545 initialize.subBlocks(0) 546 }; 547 548 //////////////////////////////////////////////////////////////////////////// 549 Real matchConstrains(VMatrix beta0, VMatrix A, VMatrix a) 550 //////////////////////////////////////////////////////////////////////////// 551 { 552 If(!_.N1, 553 { 554 Real ok = _.freeBlock::matchConstrains(beta0,A,a); 555 Real putStoreV(_.freeBlock::_.beta0); 556 ok 557 }, 558 { 559 Real ok1 = _.fullBlock::matchConstrains(beta0,A,a); 560 Real ok2 = If(!ok1, False, 561 { 562 VMatrix b1 = _.partialSampler::_.fixedValues; 563 VMatrix b2 = SubRow(_.fullBlock::_.beta0, _.i2); 564 VMatrix A1 = SubCol(A, _.i1); 565 VMatrix A2 = SubCol(A, _.i2); 566 VMatrix a2 = a - A1*b1; 567 Real _.freeBlock::matchConstrains(b2,A2,a2) 568 }); 569 VMatrix b_ = _.partialSampler::mergeWithFreeSample(_.freeBlock::_.beta0); 570 Real putStoreV(b_); 571 ok2 572 }) 573 }; 574 575 //////////////////////////////////////////////////////////////////////////// 576 VMatrix draw(Real numSim) 577 //////////////////////////////////////////////////////////////////////////// 578 { 579 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 0"); 580 If(!_.N1, 581 { 582 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 1.1"); 583 _.freeBlock::draw(numSim) 584 }, 585 { 586 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 2.1"); 587 VMatrix b1 = _.partialSampler::_.fixedValues; 588 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 2.2"); 589 VMatrix A1 = SubCol(_.fullBlock::_.A, _.i1); 590 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 2.3"); 591 VMatrix _.freeBlock::_.a := _.fullBlock::_.a - A1*b1; 592 //WriteLn("TRACE"+_MID+" StdLinearBlock::draw 2.4"); 593 _.freeBlock::draw(numSim) 594 }) 508 595 } 509 596 510 597 }; 598 511 599 512 600 ////////////////////////////////////////////////////////////////////////////// … … 529 617 aux 530 618 }; 531 532 //////////////////////////////////////////////////////////////////////////////533 Text _.autodoc.member.StdLinearFullBlock =534 "Builds a NameBlock that can draw a Gibbs sample of an standarized linear "535 "block of a general regression model with variant input and ouput regression "536 "matrices and optional but fixed constraining inequations.";537 //////////////////////////////////////////////////////////////////////////////538 Class StdLinearFullBlock: StdLinearBlock539 //////////////////////////////////////////////////////////////////////////////540 {541 BysMcmc::Bsr::Gibbs::StdLinearSubBlock _.subBlock =542 BysMcmc::Bsr::Gibbs::StdLinearSubBlock.Build(_MID+"[_.subBlock] ");543 544 ////////////////////////////////////////////////////////////////////////////545 //Default behaviour assumes standarized linear regression546 VMatrix standarize(VMatrix _Z)547 ////////////////////////////////////////////////////////////////////////////548 {549 _Z550 };551 552 ////////////////////////////////////////////////////////////////////////////553 NameBlock getWorkSpace(Real unused)554 ////////////////////////////////////////////////////////////////////////////555 {556 _.ws557 };558 559 ////////////////////////////////////////////////////////////////////////////560 Real initialize.subBlocks(Real unused)561 ////////////////////////////////////////////////////////////////////////////562 {563 Real _.subBlock::putMID(_MID+"[_.subBlock] ");564 Code _.subBlock::standarize := standarize;565 Code _.subBlock::getWorkSpace := getWorkSpace;566 Real _.subBlock::usePreconditioning :=567 _.config::bsr.linBlk.usePreconditioning;568 Real _.subBlock::cholesky.warningFreq :=569 _.config::bsr.cholesky.warningFreq;570 Real _.subBlock::truncMNormal.gibbsNumIter :=571 _.config::bsr.truncMNormal.gibbsNumIter;572 Real _.subBlock::drop_val :=573 _.config::bsr.linBlk.X.drop;574 Real _.subBlock::_.eps :=575 _.config::bsr.cholesky.epsilon*_.N*(_.N+1);576 Real _.subBlock::_.MH.useAfterIter :=577 Max(1,_.config::bsr.linBlk.MH.useAfterIter);578 Real _.subBlock::_.MH.maxRejected :=579 _.config::bsr.linBlk.MH.maxRejected;580 Real _.subBlock::_.MH.maxConsecutive :=581 _.config::bsr.linBlk.MH.maxConsecutive;582 1583 };584 585 ////////////////////////////////////////////////////////////////////////////586 Real initialize(Real unused)587 ////////////////////////////////////////////////////////////////////////////588 {589 initialize.subBlocks(unused)590 };591 592 ////////////////////////////////////////////////////////////////////////////593 Real matchConstrains(VMatrix beta0, VMatrix A, VMatrix a)594 ////////////////////////////////////////////////////////////////////////////595 {596 Real _.subBlock::matchConstrains(beta0,A,a);597 Real putStoreV(_.subBlock::_.beta0);598 1599 };600 601 ////////////////////////////////////////////////////////////////////////////602 VMatrix draw(Real numSim)603 ////////////////////////////////////////////////////////////////////////////604 {605 _.subBlock::draw(numSim)606 }607 608 };609 /*610 //////////////////////////////////////////////////////////////////////////////611 Text _.autodoc.member.StdLinearPartialBlock =612 "Builds a NameBlock that can draw a Gibbs sample of an standarized linear "613 "block of a general regression model that is partially fixed or reloaded.";614 //////////////////////////////////////////////////////////////////////////////615 Class StdLinearPartialBlock: BlockSampler616 //////////////////////////////////////////////////////////////////////////////617 {618 BysMcmc::StdLinearSubBlock _.subBlock = StdLinearSubBlock.Build(0);619 B620 };621 */
Note: See TracChangeset
for help on using the changeset viewer.
