Changeset 8ffe39c in tol
- Timestamp:
- Jan 5, 2012, 11:24:50 AM (15 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 16db681
- Parents:
- 7b5e14e
- Location:
- tol_tests/tol/BSR/test_08
- Files:
-
- 5 added
- 1 edited
-
fit_beta.tol (added)
-
fit_beta_01.gif (added)
-
fit_beta_02.gif (added)
-
fit_beta_03.gif (added)
-
fit_beta_04.gif (added)
-
test.tol (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol_tests/tol/BSR/test_08/test.tol
r7b5e14e r8ffe39c 26 26 Matrix zero = Rand(m,1,0,0); 27 27 Matrix one = zero+1; 28 //Original supplied data29 Matrix X1 = Rand(m, 5, -.3, .3);30 //Deived inputs31 Matrix X2 = SubCol(X1,[[1]]) $* SubCol(X1,[[2]]);32 //Constant input33 Matrix X3 = Rand(Rows(X1),1,1,1);34 28 //Full input matrix 35 Matrix X = X1|X2|X3; 36 //Real parameters of linear block 29 Matrix X = { 30 Matrix X1 = Round(Rand(m, 5, -0.5, 1.5)); 31 //Matrix X2 = SubCol(X1,[[1]]) $* SubCol(X1,[[2]]); 32 Matrix X2 = Round(Rand(m, 1, -0.5, 2.5)); 33 //Constant input 34 Matrix X3 = Rand(m,1,1,1); 35 Matrix X_ = X1|X2|X3 36 }; 37 38 //Real parameters of linear block 37 39 Matrix b = {Col( 38 Param_1=Rand(- 2,0),39 Param_2=Rand( -2,0),40 Param_1=Rand(-1,0), 41 Param_2=Rand( 0,1), 40 42 Param_3=Rand(-2,0), 41 Param_4=Rand( 0, 1),43 Param_4=Rand( 0,0.2), 42 44 Param_5=Rand(Param_4,2), 43 45 Param_6=Rand(Param_5,3), … … 46 48 Matrix e = Gaussian(Rows(X),1,0,1); 47 49 //Real filter matrix 48 Matrix F= X*b;50 Matrix Xb = X*b; 49 51 //Latent linear output 50 Matrix Z = F+e;52 Matrix z = Xb+e; 51 53 //Real output probabilities 52 Matrix Yp = F01( Z);54 Matrix Yp = F01(Xb); 53 55 //Simulated probit model 54 Matrix Y = GE(Z,zero); 56 Matrix Y = GE(z,zero); 57 Real Y_avr = MatAvr(Y); 58 Matrix Xb_e = Xb | e; 59 Matrix Yp_Ype = Yp | F01(Xb+e); 60 61 Real success = MatAvr(EQ(Y,GE(Yp, 0.5))); 62 63 /* */ 55 64 56 65 Set mh.estim = Probit(Y, X); 57 66 Matrix b.mh = mh.estim[1]; 58 67 Matrix Xb.mh = X*b.mh; 68 Matrix Yp.mh = F01(Xb.mh); 59 69 ////////////////////////////////////////////////////////////////////////////// 60 70 //These is the only information that will be known in real world problems 61 71 ////////////////////////////////////////////////////////////////////////////// 62 72 //Data matrix containing full output and input 63 Matrix data.mat = Y|X 1;73 Matrix data.mat = Y|X; 64 74 //Set of names of columns in data.mat 65 Set data.name = [["Output"]]<<For(1,Columns(X 1),Text(Real j)75 Set data.name = [["Output"]]<<For(1,Columns(X),Text(Real j) 66 76 { "Input_"+IntText(j)} ); 67 77 … … 98 108 Real _check_data.orig = SetIndexByName(_.data.orig); 99 109 100 Set _.data.handler = _.data.orig << 101 {[[ 102 Matrix Input_Prod_1_2 = _.data.orig::Input_1 $* _.data.orig::Input_2; 103 Matrix Constant = Rand(Rows(_.data.orig[1]),1,1,1) 104 ]]}; 110 Set _.data.handler = _.data.orig; 105 111 106 112 Real _check_data.handler = SetIndexByName(_.data.handler); … … 119 125 // Variable initVal min max priAvg priSig priSigWeight 120 126 LPI("Input_1", 0, -1/0, 0, ?, ?, ?), 121 LPI("Input_2", 0, -1/0,0, ?, ?, ?),127 LPI("Input_2", 0, 0, +1/0, ?, ?, ?), 122 128 LPI("Input_3", 0, -1/0, 0, ?, ?, ?), 123 129 LPI("Input_4", 0, 0, +1/0, ?, ?, ?), 124 130 LPI("Input_5", 0, 0, +1/0, ?, ?, ?), 125 LPI("Input_ Prod_1_2",0, 0, +1/0, ?, ?, ?),126 LPI(" Constant" , _.cteAvg, -1/0, +1/0, _.cteAvg, 0.25, 0.90)131 LPI("Input_6", 0, 0, +1/0, ?, ?, ?), 132 LPI("Input_7" , _.cteAvg, -1/0, +1/0, ?, ?, ?) 127 133 ]]}; 128 134 //Input matrix … … 140 146 // lower <= upper 141 147 BysMcmc::@Bsr.OrderRelation.Info("Input_4", "Input_5"), 142 BysMcmc::@Bsr.OrderRelation.Info("Input_5", "Input_ Prod_1_2")148 BysMcmc::@Bsr.OrderRelation.Info("Input_5", "Input_6") 143 149 ]] 144 150 … … 151 157 ////////////////////////////////////////////////////////////////////////////// 152 158 //MCMC dimensions 153 Real mcmc.burnin = 1000; 154 Real mcmc.sampleLength = 4000; 155 Real mcmc.thinning = 2; //Probit mcmc have high alternance 156 Real mcmc.cacheLength = 100; 157 Real bsr.iniVal.try.findFeasible = 1; 158 Real bsr.iniVal.try.zero = 2; 159 Real bsr.iniVal.try.givenByUser = 3; 159 Real mcmc.burnin = 2000; 160 Real mcmc.sampleLength = 10000; 161 Real mcmc.thinning = 1; //Probit mcmc have high alternance 162 Real mcmc.cacheLength = If(mcmc.sampleLength>=2000,100,1); 163 Real bsr.iniVal.try.givenByUser = 1; 164 Real bsr.iniVal.try.cnstrMLE = 2; 165 Real bsr.iniVal.try.zero = 3; 166 Real bsr.iniVal.try.findFeasible = 4; 160 167 Real bsr.iniVal.try.cnstrMinNorm = 5; 161 Real bsr.iniVal.try.cnstrMLE = 4;162 168 //Generic flags 163 169 Real do.resume = 0; 164 Real do.report = True;170 Real do.report = mcmc.sampleLength>=2000; 165 171 Real do.eval = False; //Has no sense for probit models 166 172 Real do.linear.effects = False //Has no sense for probit models … … 187 193 Rows(b_full)-VColumns(bsr.oneNode.data::_.X),0,0); 188 194 195 Matrix Xb_ = X*b_; 196 Matrix Yp_ = F01(Xb_); 197 198 Matrix CompareBeta = b | b.mh | b_; 199 Matrix CompareFilter = Xb | Xb.mh | Xb_; 200 Matrix CompareProb = Yp| Yp.mh | Yp_; 201 202 Real success.mh = MatAvr(EQ(Y,GE(Yp.mh, 0.5))); 203 Real success_ = MatAvr(EQ(Y,GE(Yp_, 0.5))); 204 205 206 Set residuals_cache = ((bsr.oneNode.cycler::_.sampler::_.nonLinBlk)[1]):: 207 _.filter::_.residuals_cache; 208 209 Set residuals_cache_stats = For(1,Card(residuals_cache),Set(Real k) 210 { 211 Matrix ek = residuals_cache[k]; 212 Real nu = MatAvr(ek); 213 Real sig = Sqrt(MatAvr(ek$*ek)); 214 Matrix frq = Frequency(ek,30,-3,3); 215 [[k,nu,sig,frq]] 216 }); 217 Set rc = ExtractByIndex(residuals_cache,Range(10,Card(residuals_cache),1)); 218 Matrix e_ = SetSum(rc)*1/Card(rc); 219 Real nu_ = MatAvr(e_); 220 Real sig_ = Sqrt(MatAvr(e_$*e_)); 221 Matrix frq_ = Frequency(e_,30,-3,3); 222 223 224 Real numErr1 = Copy(NError); 225 226 Real quality = Min(1,success_/success); 227 //Extented information about test behaviour 228 Set partialResults_ = 229 [[ 230 numErr0, numErr1 231 ]]; 232 233 //This is a messure of the success of the test 234 Real quality_ = And(numErr0 == numErr1)*quality; 235 236 237 //Return the results 238 Set resultStr_ = @strTestStatus(summary_, link_, quality_, 239 "Partial results = "<<partialResults_, 240 "NO DBServerType", "NO DBServerHost", "NO DBAlias", 241 email_); 242 WriteLn(""<<resultStr_); 243 resultStr_ 244 245 /* 189 246 //Output probabilities for given input matrix integrated over all simulated 190 247 //vectors of parameters (Bayesian inference by exact method) … … 197 254 Matrix outAprBys = GE(outProbAprBys,one*0.5); 198 255 199 Matrix CompareBeta = b | b_ | b.mh;200 Matrix CompareProb = Yp|outProbExcBys|outProbAprBys;201 256 Matrix SuccessExcBys = EQ(Y,outExcBys); 202 257 Matrix SuccessAprBys = EQ(Y,outAprBys); … … 213 268 outProbAprBys); 214 269 215 Real numErr1 = Copy(NError);216 217 Real quality = MatAvr(SuccessExcBys);218 //Extented information about test behaviour219 Set partialResults_ =220 [[221 numErr0, numErr1222 ]];223 224 //This is a messure of the success of the test225 Real quality_ = And(numErr0 == numErr1)*quality;226 227 228 //Return the results229 Set resultStr_ = @strTestStatus(summary_, link_, quality_,230 "Partial results = "<<partialResults_,231 "NO DBServerType", "NO DBServerHost", "NO DBAlias",232 email_);233 WriteLn(""<<resultStr_);234 resultStr_235 236 270 /* */
Note: See TracChangeset
for help on using the changeset viewer.
