Changeset ffb0c31 in tol


Ignore:
Timestamp:
Nov 13, 2009, 7:12:57 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
de893de
Parents:
c255c99
Message:

Storing ARMA initial values

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1706 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/stdlib/math/stat/models/bayesian/bysMcmc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/_config.tol

    rc255c99 rffb0c31  
    138138  //Arima filter method
    139139  Text bsr.arimaFilter = BysMcmc::Options::Arima.Filter::FastChol;
     140  //Enables/disables storement of the Markov chain of initial values
     141  Real bsr.arimaStoreInitialValues = False;
    140142//===========================================================================
    141143//CODA and other diagnostic report configuration
    … …  
    188190  //If true an internal TOL profiling will be executed
    189191  Real do.mcmc.profiler = False;
     192 
     193  @BysInf.Report.Config GetReportConfig(Real void)
     194  {
     195    @BysInf.Report.Config
     196    (
     197      report.raftery.diag.q,
     198      report.raftery.diag.r,
     199      report.raftery.diag.s,
     200      report.raftery.diag.eps,
     201      report.acf.lag,
     202      report.histogram.parts,
     203      report.kerDens.points
     204    )
     205  };
    190206
    191207  ////////////////////////////////////////////////////////////////////////////
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_arimaBlock.tol

    rc255c99 rffb0c31  
    3434  VMatrix   _.difFilter      = Rand(0,0,0,0);
    3535  Set       _.segment.free.index = Copy(Empty);
     36  VMatrix   _.U0 = Rand(0,1,0,0);
     37  Matrix    _.U0.cache = Rand(0,0,0,0);
     38  Matrix    _.U0.mcmc = Rand(0,0,0,0);
     39  Set       _.U0.names = Copy(Empty);
    3640
    3741  //--------------------------------------------------------------------------
    … …  
    8690    Real numDifData = m;
    8791    VMatrix D = Eye(m);
     92    VMatrix u0 = Rand(0,0,0,0);
    8893    Set segment->ArimaAuxInfo :=
    8994    [[
    90       numPar, m, difDegree, p, q, numDifData, dif, ar, ma, D
     95      numPar, m, difDegree, p, q, numDifData, dif, ar, ma, D, u0
    9196    ]];
    9297    Real SetIndexByName(segment->ArimaAuxInfo);
    … …  
    191196    Set Li_ar_factors = Copy(Empty);
    192197    Set L_ma_factors = Copy(Empty);
    193   //WriteLn("TRACE"+_MID+" initializeArimaBlock["<<resBlockNum_+"] 2.2.7 "+Time);
     198    VMatrix u0 = Rand(0,0,0,0);
     199    WriteLn("TRACE"+_MID+" initializeArimaBlock 3 ");
     200    Set If(_.config::bsr.arimaStoreInitialValues,
     201    {
     202      WriteLn("TRACE"+_MID+" initializeArimaBlock 4.1 p="<<p);
     203      Set z0.names = For(1,p,Text(Real k)
     204      {
     205        Text name = segment->Name+".InitialValue.Noise."+IntText(k);
     206        Eval(name+"=name")
     207      });
     208      WriteLn("TRACE"+_MID+" initializeArimaBlock 4.2 q="<<q);
     209      Set a0.names = For(1,q,Text(Real k)
     210      {
     211        Text name = segment->Name+".InitialValue.Residual."+IntText(k);
     212        Eval(name+"=name")
     213      });
     214      Set u0.names = z0.names<<a0.names;
     215      WriteLn("TRACE"+_MID+" initializeArimaBlock after 4.3 u0.names=\n"<<u0.names);
     216      Append(_.U0.names, u0.names, True)
     217    });
     218    WriteLn("TRACE"+_MID+" initializeArimaBlock 5 ");
    194219    Set segment->ArimaAuxInfo :=
    195220    [[
    196221       numPar, m, difDegree, p, q, numDifData,
    197222       dif, ar, ma, Li_ar, L_ma ,Li_ar_factors, L_ma_factors,
    198        D, equIdxVec
     223       D, equIdxVec, u0
    199224    ]];
    200225    Real SetIndexByName(segment->ArimaAuxInfo);
    … …  
    538563  //WriteLn("TRACE"+_MID+" draw.scalar [iter "<<numSim+"] 1 ");
    539564    Matrix noise_ = VMat2Mat(noise);
     565    Real oldResBlockNum = -1;
     566    VMatrix If(_.config::bsr.arimaStoreInitialValues,
     567    {
     568      VMatrix _.U0 := Rand(0,1,0,0)
     569    });
    540570    Set arma.draw.all =
    541571    EvalSet(_.segment.free.index, Real arma.arms.draw(Real paramNum)
    … …  
    584614      NameBlock almagro = ARMAProcess::Eval.Almagro(ar,ma,z_,sigma);
    585615
    586       VMatrix u0 = almagro::Draw.U_cond_Z(0);
     616      VMatrix u0 = If(oldResBlockNum == pd->resBlockNum,
     617      {
     618        aux::u0
     619      },
     620      {
     621        aux::u0 := almagro::Draw.U_cond_Z(0);
     622        If(_.config::bsr.arimaStoreInitialValues,
     623        {
     624          _.U0 := _.U0 << aux::u0
     625        });
     626        aux::u0 
     627      }); 
    587628      VMatrix z0 = almagro::Get.Z0(u0);
    588629      VMatrix a0 = almagro::Get.A0(u0);
    … …  
    609650    //WriteLn("TRACE"+_MID+" draw.scalar pd->coef="<<pd->coef);
    610651      pd->coef
     652    });
     653
     654    Matrix If(_.config::bsr.arimaStoreInitialValues,
     655    {
     656      Case(
     657      numSim==1,
     658      {
     659        _.U0.mcmc := Rand(0,VRows(_.U0),0,0);
     660        _.U0.cache := VMat2Mat(_.U0,True)
     661      },
     662      numSim%100,
     663      {
     664        _.U0.cache := _.U0.cache << VMat2Mat(_.U0,True)
     665      },
     666      1==1,
     667      {
     668        _.U0.mcmc := _.U0.mcmc << _.U0.cache;
     669        _.U0.cache := Rand(0,VRows(_.U0),0,0)
     670      })
    611671    });
    612672  //Real show.arma(0);
    … …  
    803863    Set _.arimaStructBlock =
    804864    {
     865      BysMcmc::@Config _.config := Copy(config);
     866
    805867    //WriteLn("TRACESelecting noise with known wariance");
    806868      Select(NoiseDistrib, Real(@BSR.NoiseDistrib segment)
Note: See TracChangeset for help on using the changeset viewer.