Changeset b86a123 in tol


Ignore:
Timestamp:
Dec 5, 2008, 8:22:58 AM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
3c0146e
Parents:
9ea7897
Message:

Fixed bug in covariance building

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_estimOneNode.tol

    r9ea7897 rb86a123  
    2222"  Real _.sigma;          //Sigma value or ? to simulate it\n"
    2323"//Optional members \n"
     24"  Set _.orderRelation;   //Set of Bsr.OrderRelation.Info\n"
    2425"  Set _.arima;           //Set of ARIMAStruct\n"
    2526"  Set _.timeInfo;        //Set of BSR.NoiseTimeInfo\n"
    26 "  Set _.orderRelation;   //Set of Bsr.OrderRelation.Info\n"
    2727"]];\n";
    2828Set EstimOneNode(NameBlock data_, Set nonLinFil, NameBlock config_)
    2929//////////////////////////////////////////////////////////////////////////////
    3030{
    31   Text _MID = _MID+"";
     31  Text _MID = "[EstimOneNode]";
    3232  //Data source for model defining
    3333  NameBlock data = data_;
    … …  
    127127  });
    128128
     129  Real m.full = m+prior.num;
     130
    129131//WriteLn(_MID+" TRACE 6");
    130132  //Observational information
    … …  
    139141        data::_.arima, Copy(Empty));
    140142      Set ArimaAuxInfo = Copy(Empty);
    141       VMatrix Cov = Eye(m);
    142       VMatrix L = Eye(m);
    143       VMatrix Li = Eye(m);
     143      VMatrix Cov = Eye(m.full,m.full,0,Rand(m,1,1,1)<<Rand(prior.num,1,0,0));
     144      VMatrix L = Cov;
     145      VMatrix Li = Cov;
    144146      Set EquIdx = Range(1,m,1);
    145147      Set TimeInfo = If(ObjectExist("Set","data::_.timeInfo"),
    … …  
    151153  VMatrix prior.X = Triplet(prior.X.triplet,prior.num,n);
    152154  Set noisePrior = If(!prior.num,Copy(Empty),
    153   {[[
     155  {
     156    [[
    154157    BSR.NoiseDistrib(
    155158      Text Name = data::_.segmentName+".Prior::Noise";
    … …  
    159162      Set arima = Copy(Empty);
    160163      Set ArimaAuxInfo = Copy(Empty);
    161       VMatrix Cov = Eye(m);
    162       VMatrix L = Eye(m);
    163       VMatrix Li = Eye(m);
     164      VMatrix Cov = Eye(m.full,m.full,0,Rand(m,1,0,0)<<Rand(prior.num,1,1,1));
     165      VMatrix L = Cov;
     166      VMatrix Li = Cov;
    164167      Set EquIdx = Range(m+1,m+prior.num,1);
    165168      Set TimeInfo = Copy(Empty)
    … …  
    192195    VMatrix A = domain.A << order.A
    193196  );
    194 //WriteLn(_MID+" TRACE 10");
    195   //Calling BSR simulator
    196   Set aux = BysMcmc::Bsr::Gibbs::EstimParsed
    197   (
    198     modelDef,
    199     nonLinearFilters,
    200     config_,
    201     BysMcmc::Bsr::Gibbs::NoNotifier(0)
    202   );
    203 //WriteLn(_MID+" TRACE 11");
    204   //Adding data source information
    205   Set bsr.estim = [[data]]<<aux;
     197  Set result = If(Not(config_::mcmc.sampleLength), [[data, modelDef]],
     198  {
     199  //WriteLn(_MID+" TRACE 10");
     200    //Calling BSR simulator
     201    Set aux = BysMcmc::Bsr::Gibbs::EstimParsed
     202    (
     203      modelDef,
     204      nonLinearFilters,
     205      config_,
     206      BysMcmc::Bsr::Gibbs::NoNotifier(0)
     207    );
     208    //WriteLn(_MID+" TRACE 11");
     209    //Adding data source information
     210    [[data]]<<aux
     211  });
    206212  //Checks unique name and prepares for hashed searching by name
    207   Real SetIndexByName(bsr.estim);
     213  Real SetIndexByName(result);
    208214//WriteLn(_MID+" TRACE 12");
    209   bsr.estim
     215  result
    210216};
    211217/////////////////////////////////////////////////////////////////////////////
    … …  
    215221//////////////////////////////////////////////////////////////////////////////
    216222Text _.autodoc.member.EstimOneNodeProbit =
    217 "Estimates a model with just one node, usually observational and dense."
     223"Estimates a probit model with just one node, usually observational and "
     224"dense."
    218225"Model is defined as a BSR basic and an non linear ProbitFilter."
    219 "BSR will be built from simplified data argument matching this API"
     226"BSR will be built from simplified data argument matching the same API "
     227"used by BysMcmc::Bsr::Gibbs::EstimOneNode, fixing _.sigma to 1"
    220228"NameBlock data = \n"
    221229"[[\n"
     230"//Mandatory members \n"
    222231"  Set  _.docInfo         //BSR.DocInfo \n"
    223232"  Text _.segmentName;    //Node name\n"
    224 "  Set _.linearParamInfo; //Set of Bsr.Param.Info\n"
    225 "  Matrix _.Y;            //Input data\n"
    226 "  Matrix _.X;            //Output data\n"
    227 "  Real _.sigma=1;        //Sigma value must be fixed as 1\n"
     233"  Set _.linearParamInfo; //Set of Bsr.OneNode.LinearParamInfo\n"
     234"  Anything _.Y;          //Output data (Matrix or VMatrix)\n"
     235"  Anything _.X;          //Input data (Matrix or VMatrix)\n"
     236"  Real _.sigma = 1;      //Sigma value or ? to simulate it\n"
     237"//Optional members \n"
     238"  Set _.orderRelation;   //Set of Bsr.OrderRelation.Info\n"
     239"  Set _.arima;           //Set of ARIMAStruct\n"
     240"  Set _.timeInfo;        //Set of BSR.NoiseTimeInfo\n"
    228241"]];\n";
    229242  NameBlock EstimOneNodeProbit(NameBlock data, NameBlock config_)
    230243//////////////////////////////////////////////////////////////////////////////
    231244{
     245  //All methods are performed for being _.sigma=1
     246  Real data::_.sigma:=1;
    232247  Set nonLinearFilters = {[[
    233248  //Filtro no lineal del output para el modelo probit
    … …  
    242257    Set _.estim = BysMcmc::Bsr::Gibbs::EstimOneNode
    243258      (data, nonLinearFilters, config_);
    244     Matrix _.param = Tra(_.estim::param.average);
     259    Matrix _.param = If(Not(config_::mcmc.sampleLength), Rand(0,0,0,0),
     260                        Tra(_.estim::param.average));
     261   
     262    //////////////////////////////////////////////////////////////////////////
     263    Text _.autodoc.member.GetProbPoint =
     264    "Returns output probabilities for given input matrix and parameters "
     265    "vector";
     266    Matrix GetProbPoint(Matrix X, Matrix beta)
     267    //////////////////////////////////////////////////////////////////////////
     268    {
     269      F01(X*beta)
     270    };
     271    //////////////////////////////////////////////////////////////////////////
     272    Text _.autodoc.member.GetProbAvg =
     273    "Returns output probabilities for given input matrix and average vector "
     274    "of simulated parameters";
     275    Matrix GetProbAvg(Matrix X)
     276    //////////////////////////////////////////////////////////////////////////
     277    {
     278      GetProbPoint(X,_.param)
     279    };
     280    //////////////////////////////////////////////////////////////////////////
     281    Text _.autodoc.member.GetProb =
     282    "Returns output probabilities for given input matrix integrated "
     283    "over all simulated vectors of parameters";
    245284    Matrix GetProb(Matrix X)
     285    //////////////////////////////////////////////////////////////////////////
    246286    {
    247       F01(X*_.param)
    248     };
    249     Matrix _.outputProb = GetProb(data::_.X)
     287      Real numSim = Rows(_.estim::report::mcmc);
     288      Matrix prob = Rand(Rows(X),1,0,0);
     289      Set For(1,numSim,Real (Real sim)
     290      {
     291        Matrix pr=GetProbPoint(X,Tra(SubRow(_.estim::report::mcmc,[[sim]])));
     292        Matrix prob := prob + pr;
     293        0
     294      });
     295      prob*(1/numSim)
     296    }
    250297  ]]
    251298};
Note: See TracChangeset for help on using the changeset viewer.