Changeset 8ffe39c in tol


Ignore:
Timestamp:
Jan 5, 2012, 11:24:50 AM (15 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
16db681
Parents:
7b5e14e
Message:

Refs #1387

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

Location:
tol_tests/tol/BSR/test_08
Files:
5 added
1 edited

Legend:

Unmodified
Added
Removed
  • tol_tests/tol/BSR/test_08/test.tol

    r7b5e14e r8ffe39c  
    2626Matrix zero = Rand(m,1,0,0);
    2727Matrix one = zero+1;
    28 //Original supplied data
    29 Matrix X1 = Rand(m, 5, -.3, .3);
    30 //Deived inputs
    31 Matrix X2 = SubCol(X1,[[1]]) $* SubCol(X1,[[2]]);
    32 //Constant input
    33 Matrix X3 = Rand(Rows(X1),1,1,1);
    3428//Full input matrix
    35 Matrix X  = X1|X2|X3;
    36 //Real parameters of linear block
     29Matrix 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
    3739Matrix 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),
    4042  Param_3=Rand(-2,0),
    41   Param_4=Rand( 0,1),
     43  Param_4=Rand( 0,0.2),
    4244  Param_5=Rand(Param_4,2),
    4345  Param_6=Rand(Param_5,3),
    … …  
    4648Matrix e  = Gaussian(Rows(X),1,0,1);
    4749//Real filter matrix
    48 Matrix F = X*b;
     50Matrix Xb = X*b;
    4951//Latent linear output
    50 Matrix Z = F+e;
     52Matrix z = Xb+e;
    5153//Real output probabilities
    52 Matrix Yp = F01(Z);
     54Matrix Yp = F01(Xb);
    5355//Simulated probit model
    54 Matrix Y  = GE(Z,zero);
     56Matrix Y  = GE(z,zero);
     57Real Y_avr = MatAvr(Y);
     58Matrix Xb_e = Xb | e;
     59Matrix Yp_Ype = Yp | F01(Xb+e);
     60
     61Real success  = MatAvr(EQ(Y,GE(Yp,    0.5)));
     62
     63/* */
    5564
    5665Set mh.estim = Probit(Y, X);
    5766Matrix b.mh = mh.estim[1];
    58 
     67Matrix Xb.mh = X*b.mh;
     68Matrix Yp.mh = F01(Xb.mh);
    5969//////////////////////////////////////////////////////////////////////////////
    6070//These is the only information that will be known in real world problems
    6171//////////////////////////////////////////////////////////////////////////////
    6272//Data matrix containing full output and input
    63 Matrix data.mat = Y|X1;
     73Matrix data.mat = Y|X;
    6474//Set of names of columns in data.mat
    65 Set data.name = [["Output"]]<<For(1,Columns(X1),Text(Real j)
     75Set data.name = [["Output"]]<<For(1,Columns(X),Text(Real j)
    6676{ "Input_"+IntText(j)} );
    6777
    … …  
    98108  Real _check_data.orig = SetIndexByName(_.data.orig);
    99109
    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;
    105111
    106112  Real _check_data.handler = SetIndexByName(_.data.handler);
    … …  
    119125    //   Variable      initVal   min    max     priAvg   priSig  priSigWeight
    120126    LPI("Input_1",           0, -1/0,     0,         ?,       ?,          ?),
    121     LPI("Input_2",           0, -1/0,     0,         ?,       ?,          ?),
     127    LPI("Input_2",           0,    0,  +1/0,         ?,       ?,          ?),
    122128    LPI("Input_3",           0, -1/0,     0,         ?,       ?,          ?),
    123129    LPI("Input_4",           0,    0,  +1/0,         ?,       ?,          ?),
    124130    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,         ?,       ?,          ?)
    127133  ]]};
    128134  //Input matrix
    … …  
    140146    //                      lower        <=  upper 
    141147    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")
    143149  ]]
    144150
    … …  
    151157//////////////////////////////////////////////////////////////////////////////
    152158//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;
    160167    Real bsr.iniVal.try.cnstrMinNorm = 5;
    161     Real bsr.iniVal.try.cnstrMLE = 4;
    162168//Generic flags
    163169  Real do.resume          =  0;
    164   Real do.report          =  True;
     170  Real do.report          =  mcmc.sampleLength>=2000;
    165171  Real do.eval            =  False; //Has no sense for probit models
    166172  Real do.linear.effects  =  False  //Has no sense for probit models
    … …  
    187193                 Rows(b_full)-VColumns(bsr.oneNode.data::_.X),0,0);
    188194
     195Matrix Xb_ = X*b_;
     196Matrix Yp_ = F01(Xb_);
     197
     198Matrix CompareBeta = b | b.mh | b_;
     199Matrix CompareFilter = Xb | Xb.mh | Xb_;
     200Matrix CompareProb = Yp| Yp.mh | Yp_;
     201
     202Real success.mh = MatAvr(EQ(Y,GE(Yp.mh, 0.5)));
     203Real success_   = MatAvr(EQ(Y,GE(Yp_,   0.5)));
     204
     205
     206Set residuals_cache = ((bsr.oneNode.cycler::_.sampler::_.nonLinBlk)[1])::
     207  _.filter::_.residuals_cache;
     208
     209Set 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});
     217Set rc = ExtractByIndex(residuals_cache,Range(10,Card(residuals_cache),1));
     218Matrix e_ = SetSum(rc)*1/Card(rc);
     219Real nu_ = MatAvr(e_);
     220Real sig_ = Sqrt(MatAvr(e_$*e_));
     221Matrix frq_ = Frequency(e_,30,-3,3);
     222
     223
     224Real numErr1 = Copy(NError);
     225
     226Real quality = Min(1,success_/success);
     227//Extented information about test behaviour
     228Set partialResults_ =
     229[[
     230  numErr0, numErr1
     231]];
     232
     233//This is a messure of the success of the test
     234Real quality_ = And(numErr0 == numErr1)*quality;
     235
     236
     237//Return the results
     238Set resultStr_ = @strTestStatus(summary_, link_, quality_,
     239                  "Partial results = "<<partialResults_,
     240                  "NO DBServerType", "NO DBServerHost", "NO DBAlias",
     241                  email_);
     242WriteLn(""<<resultStr_);
     243resultStr_
     244
     245/*
    189246//Output probabilities for given input matrix integrated over all simulated
    190247//vectors of parameters (Bayesian inference by exact method)
    … …  
    197254Matrix outAprBys = GE(outProbAprBys,one*0.5);
    198255
    199 Matrix CompareBeta = b | b_ | b.mh;
    200 Matrix CompareProb = Yp|outProbExcBys|outProbAprBys;
    201256Matrix SuccessExcBys = EQ(Y,outExcBys);
    202257Matrix SuccessAprBys = EQ(Y,outAprBys);
    … …  
    213268  outProbAprBys);
    214269
    215 Real numErr1 = Copy(NError);
    216 
    217 Real quality = MatAvr(SuccessExcBys);
    218 //Extented information about test behaviour
    219 Set partialResults_ =
    220 [[
    221   numErr0, numErr1
    222 ]];
    223 
    224 //This is a messure of the success of the test
    225 Real quality_ = And(numErr0 == numErr1)*quality;
    226 
    227 
    228 //Return the results
    229 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 
    236270/* */ 
Note: See TracChangeset for help on using the changeset viewer.