Changeset 9fc2160 in tol


Ignore:
Timestamp:
Mar 19, 2009, 9:36:24 AM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
1a17e39
Parents:
73bf20ce
Message:

Adding check of ARMAProcess::Eval.Almagro

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_tests/tol/random_generation/test_0005/test.tol

    r73bf20ce r9fc2160  
    1111   "ARMA noise" ;
    1212
    13   Real PutRandomSeed(1032679103);
     13  Real PutRandomSeed(1938259105);
    1414  Real rnd_seed=GetRandomSeed(0);
    1515  WriteLn("rnd_seed "+IntText(rnd_seed));
    … …  
    2828  VMatrix b = Rand(n,1,-2,2);
    2929  //Regular AutoRegressive degree
    30   Real p = IntRand(0,2);
     30  Real p = IntRand(0,3);
    3131  //Regular AutoRegressive polynomial
    3232  Polyn ar = RandStationary(p);
    3333  //Regular Moving Average degree
    34   Real q = IntRand(0,2);
     34  Real q = IntRand(0,3);
    3535  //Regular Moving Average polynomial
    3636  Polyn ma = RandStationary(q);
    … …  
    6767  //of density of linear regression parameters and also of corresponding
    6868  //ARMA noise
    69   Matrix logDens = SetMat(For(1,100,Set(Real iter)
    70   {
    71 
    72     //Simulates n independent normal variables
     69//Matrix logDens = SetMat(For(1,100,Set(Real iter)
     70//{
     71    WriteLn("TRACE Iteration "<<iter);
     72    WriteLn("TRACE Simulates n independent normal variables");
    7373    VMatrix b01 = Gaussian(n,1,0,1);
    74     //Applys the regular linear change of variables to draw the paraneters
     74    WriteLn("TRACE Applys the regular linear change of variables to draw the paraneters");
    7575    VMatrix b_ = nu_+CholeskiSolve(L_,b01,"LtP");
    7676   
    77     //logarithm of density of linear regression parameters is not affected by
    78     //a regular linear variable change
     77    WriteLn("TRACE logarithm of density of linear regression parameters is not affected by a regular linear variable change");
    7978    Real lgDns_b = MatSum(Log(f01(VMat2Mat(b01))));
    8079 
    8180    VMatrix z_ = (Y-X*b_)*(1/s);
    82     //Calculates logarithm of density of ARMA noise by Levinson method
     81    WriteLn("TRACE Calculates logarithm of density of ARMA noise by Levinson method");
    8382    Set ev.levinson =  ARIMALevinsonEval(arima,VMat2Mat(z_));
    8483    Real lgDns_z.levinson = ev.levinson::logLH;
    8584
    86     //Calculates logarithm of density of ARMA noise by Almagro method
    87     Set ev.almagro = ARIMAAlmagroEval(arima, VMat2Mat(z_));
    88     Real lgDns_z.almagro = ev.almagro::logLH;
     85    WriteLn("TRACE Calculates logarithm of density of ARMA noise by Almagro method");
     86    Set ev.almagro.1 = ARIMAAlmagroEval(arima, VMat2Mat(z_));
     87    Real lgDns_z.almagro.1 = ev.almagro.1::logLH;
     88
     89    WriteLn("TRACE Alternative expression for Almagro method");
     90    NameBlock ev.almagro.2 = ARMAProcess::Eval.Almagro(ar, ma, z_, 1);
     91    Real lgDns_z.almagro.2 = ev.almagro.2::_.logLH;
    8992/*
    90     //Alternative expression for Almagro method
    91     NameBlock ev.almagro_ = ARMAProcess::Eval.Almagro(ar, ma, z_, 1);
    92     Real lgDns_z.almagro_ = ev.almagro_::_.logLH;
    93 */
    94     [[lgDns_b, lgDns_z.almagro, lgDns_z.levinson]]
     93    [[lgDns_b, lgDns_z.almagro.2, lgDns_z.almagro.2, lgDns_z.levinson]]
    9594  }));
    9695  //logarithm of density of linear regression parameters
    9796  Matrix lgDns_b  = SubCol(logDens,[[1]]);
    9897  //logarithm of density of ARMA noise by Almagro method
    99   Matrix lgDns_z.almagro  = SubCol(logDens,[[2]]);
     98  Matrix lgDns_z.almagro.1  = SubCol(logDens,[[2]]);
     99  //logarithm of density of ARMA noise by Almagro method
     100  Matrix lgDns_z.almagro.2  = SubCol(logDens,[[3]]);
    100101  //logarithm of density of ARMA noise by Levinson method
    101   Matrix lgDns_z.levinson  = SubCol(logDens,[[3]]);
     102  Matrix lgDns_z.levinson  = SubCol(logDens,[[4]]);
    102103  //Adding a constant to logarithm of density of ARMA noise
    103   Matrix lgDns_z.almagro_ = lgDns_z.almagro + MatAvr(lgDns_b-lgDns_z.almagro);
     104  Matrix lgDns_z.almagro.1_ = lgDns_z.almagro.1 + MatAvr(lgDns_b-lgDns_z.almagro.1);
     105  //Adding a constant to logarithm of density of ARMA noise
     106  Matrix lgDns_z.almagro.2_ = lgDns_z.almagro.2 + MatAvr(lgDns_b-lgDns_z.almagro.2);
    104107  //Adding a constant to logarithm of density of ARMA noise
    105108  Matrix lgDns_z.levinson_ = lgDns_z.levinson + MatAvr(lgDns_b-lgDns_z.levinson);
    106109  //By Bayes theorem, this error must be close to zero
    107   Real err.almagro = MatMax(Abs(lgDns_b - lgDns_z.almagro_));
     110  Real err.almagro.1 = MatMax(Abs(lgDns_b - lgDns_z.almagro.1_));
     111  //By Bayes theorem, this error must be close to zero
     112  Real err.almagro.2 = MatMax(Abs(lgDns_b - lgDns_z.almagro.2_));
    108113  //By Bayes theorem, this error must be close to zero
    109114  Real err.levinson = MatMax(Abs(lgDns_b - lgDns_z.levinson_));
    110115  //This is a [0,1] metric of quality
    111   Real quality.almagro = Max(0,1-err.almagro);
     116  Real quality.almagro.1 = Max(0,1-err.almagro.1);
     117  //This is a [0,1] metric of quality
     118  Real quality.almagro.2 = Max(0,1-err.almagro.2);
    112119  //This is a [0,1] metric of quality
    113120  Real quality.levinson = Max(0,1-err.levinson);
    114121
    115122  //Visualize a chart of this matrix to observe de adjustment
    116   Matrix lgDns_cmp = lgDns_b | lgDns_z.almagro_ | lgDns_z.levinson_;
     123  Matrix lgDns_cmp = lgDns_b | lgDns_z.almagro.1_ |
     124                     lgDns_z.almagro.2_ | lgDns_z.levinson_;
    117125
    118   Matrix lgDns_dif.almagro = lgDns_b-lgDns_z.almagro;
     126  Matrix lgDns_dif.almagro.1 = lgDns_b-lgDns_z.almagro.1;
     127  Matrix lgDns_dif.almagro.2 = lgDns_b-lgDns_z.almagro.2;
    119128  Matrix lgDns_dif.levinson = lgDns_b-lgDns_z.levinson;
    120129
    … …  
    126135    numErr0,
    127136    numErr1,
    128     err.almagro,
    129     quality.almagro,
     137    err.almagro.1,
     138    quality.almagro.1,
     139    err.almagro.2,
     140    quality.almagro.2,
    130141    err.levinson,
    131142    quality.levinson
    … …  
    133144//This is a messure of the success of the test
    134145  Real quality_ = And(numErr1 == numErr0)*
    135                   Min(quality.almagro, quality.levinson);
     146                  Min(quality.almagro.1, quality.almagro.2, quality.levinson);
    136147
    137 //WriteLn("TRACE 6");
     148  WriteLn("TRACE 6");
    138149//Return the results
    139150  Set resultStr_ = strTestStatus(summary_, link_, quality_,
    … …  
    145156
    146157/* */
     158
Note: See TracChangeset for help on using the changeset viewer.