Changeset e9469de4 in tol


Ignore:
Timestamp:
Mar 27, 2009, 10:32:20 AM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
44ae460
Parents:
76ecf8e
Message:

Preparing for Metropolis-Hastings method explained in #664

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

Location:
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs
Files:
4 edited

Legend:

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

    r76ecf8e re9469de4  
    264264  //WriteLn("TRACE"+_MID+" draw.sig.lin 8");
    265265    VMatrix _.beta := If(Not(_.lin.blk::_.blockDef::_.numCol),Rand(0,1,0,0),
    266       _.lin.blk::draw(numSim, Y01, X01));
     266    {
     267      Real _.lin.blk::solve(numSim, Y01, X01);
     268      _.lin.blk::draw(numSim, Y01, X01)
     269    });
    267270  //WriteLn("TRACE"+_MID+" draw.sig.lin 9");
    268271    _.beta << sig << arm << im << om
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_inputMissingBlock.tol

    r76ecf8e re9469de4  
    210210    {
    211211      NameBlock ls = buildLinearSystem(arima,si,beta,Z);
     212      Real _.lin.blk::solve(numSim, ls::Y01, ls::X01);
    212213      VMatrix _.blockDef::_.store := _.lin.blk::draw(numSim, ls::Y01, ls::X01);
    213214      _.blockDef::_.store
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_outputMissingBlock.tol

    r76ecf8e re9469de4  
    191191    {
    192192      NameBlock ls = buildLinearSystem(arima,si,Z);
     193      Real _.lin.blk::solve(numSim, ls::Y01, ls::X01);
    193194      VMatrix _.blockDef::_.store := _.lin.blk::draw(numSim, ls::Y01, ls::X01);
    194195      _.blockDef::_.store
  • tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_stdLinearBlock.tol

    r76ecf8e re9469de4  
    5656  //Matrix of linear system in last iteration
    5757  VMatrix _old.X  = Rand(0,0,0,0);
     58  //
     59  Set _.solution = Copy(Empty);
     60
    5861  Real _changed.X = True;
    5962
    … …  
    6467  //Current maximum of rounding error in solution
    6568  Real _.cholSolMaxRoundErr     = 0;
     69
     70  //Stores the associated drawing method
     71  Code _drawer = UnknownCode;
    6672
    6773  ////////////////////////////////////////////////////////////////////////////
    … …  
    189195  ////////////////////////////////////////////////////////////////////////////
    190196  //Solves the linear system corresponding to the standarized linear regression
    191   NameBlock solve(Real numSim, VMatrix Y, VMatrix X)
     197  Real solve(Real numSim, VMatrix Y, VMatrix X)
    192198  ////////////////////////////////////////////////////////////////////////////
    193199  {
    … …  
    221227    });
    222228  //WriteLn("TRACE "+_MID+" solve 8");
    223     NameBlock [[ XtY, nu, err ]]
     229    Set _.solution := [[ numSim, Y, X, XtY, nu, err ]];
     230    Real SetIndexByName(_.solution);
     231    1
    224232  };
    225233
    … …  
    227235  Text _.autodoc.member.draw.unconstrained =
    228236  "Method of generation of a linear block in unconstrained case";
    229   VMatrix draw.unconstrained(Real numSim, VMatrix Y, VMatrix X, NameBlock sr)
     237  VMatrix draw.unconstrained(Real numSim)
    230238  ////////////////////////////////////////////////////////////////////////////
    231239  {
    … …  
    236244  //WriteLn("TRACE "+_MID+" draw.unconstrained 4 _.L="<<Matrix(VMat2Mat(_.L)));
    237245  //WriteLn("TRACE "+_MID+" draw.unconstrained 4 b2="<<Matrix(VMat2Mat(Tra(b2))));
    238     VMatrix  (_.blockDef::_.store) := sr::nu+b2;
     246    VMatrix  (_.blockDef::_.store) := _.solution::nu+b2;
    239247  //WriteLn("TRACE "+_MID+" draw.unconstrained 5");
    240248    Copy(_.blockDef::_.store)
    … …  
    244252  Text _.autodoc.member.draw.constrained =
    245253  "Method of generation of a linear block in constrained case";
    246   VMatrix draw.constrained(Real numSim, VMatrix Y, VMatrix X, NameBlock sr)
    247   ////////////////////////////////////////////////////////////////////////////
    248   {
     254  VMatrix draw.constrained(Real numSim)
     255  ////////////////////////////////////////////////////////////////////////////
     256  {
     257    VMatrix nu = _.solution::nu;
    249258  //WriteLn("TRACE "+_MID+" draw.constrained 1.1 Max(A*b0-a)="<<VMatMax(_.A*_.blockDef::_.store - a));
    250     VMatrix d   = _.a - _.A*sr::nu;
     259    VMatrix d   = _.a - _.A*nu;
    251260    VMatrix If(_changed.X, _.D  := Tra(CholeskiSolve(_.L,_.At,"PtL")));
    252     VMatrix z0  = Tra(Tra(_.blockDef::_.store-sr::nu)*_.Ls);
     261    VMatrix z0  = Tra(Tra(_.blockDef::_.store-nu)*_.Ls);
    253262  //WriteLn("TRACE "+_MID+" draw.constrained 1.2 Max(D*z0-d)="<<VMatMax(_.D*z0 - d));
    254263    VMatrix z = TruncStdGaussian(_.D,d,z0,1,
    … …  
    265274      If(!VRows(_.beta0),0,
    266275      {
    267         VMatrix z0 := Tra(Tra(_.beta0-sr::nu)*_.Ls);
     276        VMatrix z0 := Tra(Tra(_.beta0-nu)*_.Ls);
    268277        VMatrix z  := TruncStdGaussian(_.D,d,z0,1,
    269278                     _.blockDef::_.config::bsr.truncMNormal.gibbsNumIter);
    … …  
    272281      1
    273282    });
    274     VMatrix  (_.blockDef::_.store) := sr::nu + CholeskiSolve(_.L,z,"LtP");
     283    VMatrix  (_.blockDef::_.store) := nu + CholeskiSolve(_.L,z,"LtP");
    275284    Copy(_.blockDef::_.store)
    276285  };
    277 
    278   Code _drawer = draw.constrained;
    279286
    280287  ////////////////////////////////////////////////////////////////////////////
    … …  
    286293    If(_.blockDef::enabled,
    287294    {
    288       NameBlock sr  = solve(numSim,Y,X);
    289       VMatrix aux = _drawer(numSim, Y, X, sr);
     295    //Real solve(numSim,Y,X);
     296      VMatrix aux = _drawer(numSim);
    290297    //WriteLn("TRACE "+_MID+" draw");
    291298      Real _.blockDef::checkNonFiniteValues(numSim);
    … …  
    303310  ////////////////////////////////////////////////////////////////////////////
    304311  {
    305     NameBlock sr = solve(numSim,Y,X);
    306   //WriteLn("TRACE "+_MID+" maxLikelihood sr::nu="<<Matrix(Tra(VMat2Mat(sr::nu))));
     312    Real solve(numSim,Y,X);
    307313    VMatrix aux = If(!_.R,
    308314    {
    309       sr::nu
     315      _.solution::nu
    310316    },
    311317    {
    312       VMatrix d = _.a - _.A*sr::nu;
    313       If(VMatMax(d)>=0, sr::nu,
     318      VMatrix d = _.a - _.A*_.solution::nu;
     319      If(VMatMax(d)>=0, _.solution::nu,
    314320      {
    315321        WriteLn("Cannot do maxLikelihood for constrained linear block "+
    316322          _.blockDef::_.name,"W");
    317         draw.constrained(numSim, Y, X, sr)
     323        draw.constrained(numSim)
    318324      })
    319325    });
Note: See TracChangeset for help on using the changeset viewer.