Changeset 9fc2160 in tol
- Timestamp:
- Mar 19, 2009, 9:36:24 AM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 1a17e39
- Parents:
- 73bf20ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol_tests/tol/random_generation/test_0005/test.tol
r73bf20ce r9fc2160 11 11 "ARMA noise" ; 12 12 13 Real PutRandomSeed(1 032679103);13 Real PutRandomSeed(1938259105); 14 14 Real rnd_seed=GetRandomSeed(0); 15 15 WriteLn("rnd_seed "+IntText(rnd_seed)); … … 28 28 VMatrix b = Rand(n,1,-2,2); 29 29 //Regular AutoRegressive degree 30 Real p = IntRand(0, 2);30 Real p = IntRand(0,3); 31 31 //Regular AutoRegressive polynomial 32 32 Polyn ar = RandStationary(p); 33 33 //Regular Moving Average degree 34 Real q = IntRand(0, 2);34 Real q = IntRand(0,3); 35 35 //Regular Moving Average polynomial 36 36 Polyn ma = RandStationary(q); … … 67 67 //of density of linear regression parameters and also of corresponding 68 68 //ARMA noise 69 Matrix logDens = SetMat(For(1,100,Set(Real iter)70 {71 72 //Simulates n independent normal variables69 //Matrix logDens = SetMat(For(1,100,Set(Real iter) 70 //{ 71 WriteLn("TRACE Iteration "<<iter); 72 WriteLn("TRACE Simulates n independent normal variables"); 73 73 VMatrix b01 = Gaussian(n,1,0,1); 74 //Applys the regular linear change of variables to draw the paraneters74 WriteLn("TRACE Applys the regular linear change of variables to draw the paraneters"); 75 75 VMatrix b_ = nu_+CholeskiSolve(L_,b01,"LtP"); 76 76 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"); 79 78 Real lgDns_b = MatSum(Log(f01(VMat2Mat(b01)))); 80 79 81 80 VMatrix z_ = (Y-X*b_)*(1/s); 82 //Calculates logarithm of density of ARMA noise by Levinson method81 WriteLn("TRACE Calculates logarithm of density of ARMA noise by Levinson method"); 83 82 Set ev.levinson = ARIMALevinsonEval(arima,VMat2Mat(z_)); 84 83 Real lgDns_z.levinson = ev.levinson::logLH; 85 84 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; 89 92 /* 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]] 95 94 })); 96 95 //logarithm of density of linear regression parameters 97 96 Matrix lgDns_b = SubCol(logDens,[[1]]); 98 97 //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]]); 100 101 //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]]); 102 103 //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); 104 107 //Adding a constant to logarithm of density of ARMA noise 105 108 Matrix lgDns_z.levinson_ = lgDns_z.levinson + MatAvr(lgDns_b-lgDns_z.levinson); 106 109 //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_)); 108 113 //By Bayes theorem, this error must be close to zero 109 114 Real err.levinson = MatMax(Abs(lgDns_b - lgDns_z.levinson_)); 110 115 //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); 112 119 //This is a [0,1] metric of quality 113 120 Real quality.levinson = Max(0,1-err.levinson); 114 121 115 122 //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_; 117 125 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; 119 128 Matrix lgDns_dif.levinson = lgDns_b-lgDns_z.levinson; 120 129 … … 126 135 numErr0, 127 136 numErr1, 128 err.almagro, 129 quality.almagro, 137 err.almagro.1, 138 quality.almagro.1, 139 err.almagro.2, 140 quality.almagro.2, 130 141 err.levinson, 131 142 quality.levinson … … 133 144 //This is a messure of the success of the test 134 145 Real quality_ = And(numErr1 == numErr0)* 135 Min(quality.almagro , quality.levinson);146 Min(quality.almagro.1, quality.almagro.2, quality.levinson); 136 147 137 //WriteLn("TRACE 6");148 WriteLn("TRACE 6"); 138 149 //Return the results 139 150 Set resultStr_ = strTestStatus(summary_, link_, quality_, … … 145 156 146 157 /* */ 158
Note: See TracChangeset
for help on using the changeset viewer.
