Changeset ba4e2ac in tol


Ignore:
Timestamp:
Aug 25, 2009, 11:31:40 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
f7133bb
Parents:
bd637b5
Message:

Use of ((VMatrix + n2) - n2) converts sparse to dense, so, it has been replaced by Drop(VMatrix,1.E-16/n2)
Removing arbitrary drop parameter

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/stdlib/math/stat/models/bayesian/arima/_arma_process.tol

    rbd637b5 rba4e2ac  
    1010[[
    1111  Text _.autodoc.description = "Methods related with ARMA process";
    12 
    13   Real drop = 1.E-8;
    1412
    1513  ////////////////////////////////////////////////////////////////////////////
    … …  
    5250
    5351  ////////////////////////////////////////////////////////////////////////////
    54   VMatrix DoDrop(VMatrix X)
    55   ////////////////////////////////////////////////////////////////////////////
    56   {
    57     Drop(X,drop)
    58   };
    59 
    60   ////////////////////////////////////////////////////////////////////////////
    6152  VMatrix CholeskiFactorCov(VMatrix cov)
    6253  ////////////////////////////////////////////////////////////////////////////
    6354  {
    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);
    6657  //WriteLn("TRACE CholeskiFactorCov Sparsity(c)="<<Real(VNonNullCells(c)/VRows(c)^2));
    6758  //Real t0 = Copy(Time);
    … …  
    8576  {
    8677    Real n = VRows(S);
    87     ARMAProcess::DoDrop(ARMAProcess::AvoidSymRoundErr(Case(
     78    VMatrix s = ARMAProcess::AvoidSymRoundErr(Case(
    8879      m==n, S,
    8980      m<n,  Sub(S,1,1,m,m),
    … …  
    10091        )+Pol2VMat(pol, m, m);
    10192        aux
    102       })))
     93      }));
     94    Drop(s,1.E-16/n^2)
    10395  };
    10496
    … …  
    108100  {
    109101    Real n = VRows(L);
    110     ARMAProcess::DoDrop(Case(
     102    VMatrix L_ = Case(
    111103      m==n, L,
    112104      m<n,  Sub(L,1,1,m,m),
    … …  
    119111        )+Pol2VMat(pol, m, m);
    120112        aux
    121       }))
     113      });
     114    Drop(L_,1.E-16/n^2)
    122115  };
    123116
    … …  
    175168    Real _.n = Max(_.p,_.q)+_.p+1;
    176169  //Real _trc.6 = { WriteLn("TRACE FastCholeskiCovFactor _.n=" << _.n); 0 };
    177 
     170    Real drop = 1.E-16 / _.n^2;
    178171    //Calculates de main minor of length _.n of just pure AR covariance
    179172    VMatrix _.cov_ar_n =
    180       ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,1,_.n), _.n, _.n));
     173      Drop(Pol2VMat(ARMATACov(_.ar,1,_.n), _.n, _.n),drop);
    181174    //Does Choleski factorization of pure AR
    182175  //Real _trc.7 = { WriteLn("TRACE FastCholeskiCovFactor _.cov_ar_n=" << (Matrix VMat2Mat(_.cov_ar_n))); 0 };
    … …  
    184177  //Real _trc.8 = { WriteLn("TRACE FastCholeskiCovFactor _.L_ar_n=" << (Matrix VMat2Mat(_.L_ar_n))); 0 };
    185178    //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);
    187180  //Real _trc.9 = { WriteLn("TRACE FastCholeskiCovFactor _.Li_ar_n=" << (Matrix VMat2Mat(_.Li_ar_n))); 0 };
    188181    //Extends main minor of length _.n to full data length _.m as Toplitz from 
    189182    //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);
    192185  //Real _trc.10 = { WriteLn("TRACE FastCholeskiCovFactor _.Li_ar=" << (Matrix VMat2Mat(_.Li_ar))); 0 };
    193186
    194187    //Calculates de main minor of length _.n of joint ARMA covariance
    195188    VMatrix _.cov_arma_n =
    196       ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,_.ma,_.n), _.n, _.n));
     189      Drop(Pol2VMat(ARMATACov(_.ar,_.ma,_.n), _.n, _.n),drop);
    197190    //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);
    199192    //Extends main minor of length _.n to full data length _.m as Toplitz from
    200193    //last row and column getting a symmetric and sparse banded matrix
    201194  //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);
    204197  //Real _trc.12 = { WriteLn("TRACE FastCholeskiCovFactor _.cov_ma_m=" << (Matrix VMat2Mat(_.cov_ma_m))); 0 };
    205198    //Does Choleski factorization of pseudo MA factor
    206199    VMatrix _.L_ma = ARMAProcess::CholeskiFactorCov(_.cov_ma_m);
    207200    //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);
    209202    //Calculates de logarithm of determinant of _.m ARMA covarianze
    210203    Real _.logDetCov = 2*(-VMatSum(Log(SubDiag(_.Li_ar,0)))+
    … …  
    255248    Real    p     = Degree(ar);
    256249    Real    q     = Degree(ma);
     250    Real drop = 1.E-16/m^2;
    257251  //WriteLn("TRACE Eval.Almagro Begin "+Time);
    258252  //WriteLn("TRACE Eval.Almagro(p"<<p+",q="<<q+",m="<<m);
    … …  
    311305    _.p & _.q,
    312306    {
    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);
    314308    //WriteLn("_.cov_zz = "<<_.cov_zz);
    315309      VMatrix cov_aa = Eye(_.q);
    … …  
    325319    _.p & !_.q,
    326320    {
    327       ARMAProcess::DoDrop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p))
     321      Drop(Pol2VMat(ARMATACov(_.ar,_.ma,_.p), _.p, _.p),drop)
    328322    //WriteLn("_.cov_zz = "<<_.cov_zz);
    329323    },
    … …  
    341335    {
    342336      aux = solve.LLt(_.L_u,Eye(_.q_p));
    343       ARMAProcess::DoDrop(ARMAProcess::AvoidSymRoundErr(aux))
     337      Drop(ARMAProcess::AvoidSymRoundErr(aux),drop)
    344338    };
    345339  //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);
    347341  //Real _trc.5 = { WriteLn("TRACE Eval.Almagro Creating cov_G "+Time); 0 };
    348342    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);
    351345    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);
    354348    VMatrix _.GtG = MtMSqr(_.G);
    355349    VMatrix _.cov_G = _.covi_u + _.GtG;
    … …  
    357351    VMatrix _.L_G   = ARMAProcess::CholeskiFactorCov(_.cov_G);
    358352  //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);
    360354    Real _.det_cov_G = 2*VMatSum(Log(SubDiag(_.L_G_sp,0)));
    361355    Real _.det_cov_z = _.det_cov_u + _.det_cov_G;
Note: See TracChangeset for help on using the changeset viewer.