Changeset f9c7f71 in tol


Ignore:
Timestamp:
Apr 14, 2010, 3:51:56 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
823054d
Parents:
fdb5742
Message:

La llamada a Estimate es opcional
Se reporta la comparación de verosimilitudes del ARIMA generado real y el del valor medio de la MCMC

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_tests/tol/ARIMA/mcmc/mtrymh.mcmc.tol

    rfdb5742 rf9c7f71  
    1010Matrix mcmc = Rand(0,mtm_arima::_.n,0,0);
    1111
    12 Matrix L = {
    13   Matrix COV = modEst.0::Correlations::COV;
    14   Real n = mtm_arima::_.n;
    15   Real r = Rows(COV);
    16   Real k = r-n+1;
    17   Choleski(Sub(COV,k,k,n,n))
    18 };
    19 Matrix Li = LTInverse(L);
    20 VMatrix mtm_arima::_.L := Mat2VMat(L);
    21 VMatrix mtm_arima::_.Li := Mat2VMat(Li);
    22 Real mtm_arima::_.s := 1;
    23 
     12Real If(!ObjectExist("Matrix","modEst.0::Correlations::COV"),
     13{
     14  Real mtm_arima::_.s := 0.001
     15},
     16{
     17  Matrix L = {
     18    Matrix COV = modEst.0::Correlations::COV;
     19    Real n = mtm_arima::_.n;
     20    Real r = Rows(COV);
     21    Real k = r-n+1;
     22    Choleski(Sub(COV,k,k,n,n))
     23  };
     24  Matrix Li = LTInverse(L);
     25  VMatrix mtm_arima::_.L := Mat2VMat(L);
     26  VMatrix mtm_arima::_.Li := Mat2VMat(Li);
     27  Real mtm_arima::_.s := 1
     28});
     29 
    2430
    2531Real numSim = 0;
    … …  
    4349
    4450/* */
    45 Real mtm_arima::_.sFactor := 1.00;
     51Real mtm_arima::_.sFactor := 1.01;
    4652Real numSim := 0;
    4753Real mtm.t0 = Copy(Time);
    … …  
    6268Real raftery.rate = ?;
    6369Real raftery.speed = ?;
     70Real burnin = 500;
    6471
    6572Matrix cmp = mcmc | Group("ConcatColumns", For(1,Rows(PARAM),Matrix(Real j)
    … …  
    7885  ]]});
    7986  Real raftery.burnin := MatMax(SubCol(raftery,[[1]]));
     87  Real burnin := Min(raftery.burnin,500);
    8088  Real raftery.thinning := MatMax(SubCol(raftery,[[4]]));
    8189  Real raftery.rate := (numSim-raftery.burnin)/(numSim*raftery.thinning);
    … …  
    8391]]});
    8492 
     93Matrix mcmc.sub = SubRow(mcmc, Range(burnin+1,Rows(mcmc),1));
     94Matrix x.avr = Tra(Constant(1,Rows(mcmc.sub),1/Rows(mcmc.sub))*mcmc.sub);
     95Set arima.avr = mtm_arima::col2arima(Mat2VMat(x.avr));
     96Set ev.avr = ARIMALevinsonEval(arima.avr, Tra(SerMat(z)));
     97Serie e;
     98Serie residuals.avr  =
     99{
     100  Matrix res = ev.avr[4];
     101  Date   ini = Succ(Last(z),Diario,-Rows(ev.avr[4])+1);
     102  If(!Rows(res), 0*z, MatSerSet(Tra(res),Diario,ini)[1])
     103};
     104Real logLH.real = (SimulArima::EvalRealARIMA::ev)[12];
     105Real logLH.avr = (ev.avr)[12];
     106Real prob.refuse = Min(1,Max(0,1-Exp(logLH.avr-logLH.real)));
     107
     108Real Q_draw_by_Pi_draw = mtm_arima::_.num_Q_draw/mtm_arima::_.num_draw;
     109Real num_logWeight_by_Pi_draw = mtm_arima::_.num_logWeight/mtm_arima::_.num_draw;
     110
    85111Text report = ""
    86112  <<rndSeed+"\t"
    … …  
    89115  <<mtm_arima::_.n+"\t"
    90116  <<mtm_arima::_.k+"\t"
     117  <<Q_draw_by_Pi_draw+"\t"
     118  <<num_logWeight_by_Pi_draw+"\t"
    91119  <<arima.time+"\t"
    92120  <<mtm.time+"\t"
    … …  
    97125  <<raftery.rate+"\t"
    98126  <<raftery.speed+"\t"
     127  <<logLH.real+"\t"
     128  <<logLH.avr+"\t"
     129  <<prob.refuse+"\t"
    99130  <<numErr+"\t"
    100131  <<numWar+"\n";
    … …  
    105136  +"mtm_arima::_.n\t"
    106137  +"mtm_arima::_.k\t"
     138  +"Q_draw_by_Pi_draw\t"
     139  +"num_logWeight_by_Pi_draw\t"
    107140  +"arima.time\t"
    108141  +"mtm.time\t"
    … …  
    112145  +"raftery.thinning\t"
    113146  +"raftery.rate\t"
    114   +"raftery.speed\t"
     147  +"logLH.real\t"
     148  +"logLH.avr\t"
     149  +"prob.refuse\t"
    115150  +"numErr\t"
    116151  +"numWar\n"));
Note: See TracChangeset for help on using the changeset viewer.