Changeset dd921c2 in tol


Ignore:
Timestamp:
Apr 1, 2009, 3:51:34 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
c07b2db
Parents:
24bdea7
Message:

Removing max-likelihood step
Preparing for Metropolis-Hastings method explained in #664

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

File:
1 edited

Legend:

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

    r24bdea7 rdd921c2  
    5959  Set _.solution = Copy(Empty);
    6060
    61   Real _changed.X = True;
     61  Real changed.X = True;
    6262
    6363  //Maximum accepted rounding error for Choleski operations
    … …  
    6767  //Current maximum of rounding error in solution
    6868  Real _.cholSolMaxRoundErr     = 0;
    69 
     69  //Logarithm of density of last generated vector
     70  Real _.betaLogDens = -1/0;
    7071  //Stores the associated drawing method
    71   Code _drawer = UnknownCode;
     72  Code drawer = UnknownCode;
    7273
    7374  ////////////////////////////////////////////////////////////////////////////
    … …  
    8990    VMatrix _.a    := a;
    9091  //WriteLn("TRACE "+_MID+" initialize 6 _.a="<<_.a);
    91     Code    _drawer   := If(_.R, draw.constrained, draw.unconstrained);
     92    Code    drawer   := If(_.R, draw.constrained, draw.unconstrained);
    9293  //WriteLn("TRACE "+_MID+" initialize 7");
    9394    VMatrix (_.blockDef::_.store) := If(!_.R, beta0,
    … …  
    137138    If(And(design.is.constant,VRows(_.L)), 0,
    138139    {
    139       Real _changed.X := If(Or(VColumns(X)!=VColumns(_old.X),
     140      Real changed.X := If(Or(VColumns(X)!=VColumns(_old.X),
    140141                               VRows   (X)!=VRows   (_old.X)), -1,
    141142      {
    142143        1+VMatMax(Abs(X-_old.X))-1
    143144      });
    144       If(!_changed.X ,0,
     145      If(!changed.X ,0,
    145146      {
    146147        Real density = VNonNullCells(X)/(VRows(X)*VColumns(X));
    … …  
    160161        },       
    161162        {
    162         //WriteLn("TRACE"+_MID+" factorize changed="<<_changed.X );
     163        //WriteLn("TRACE"+_MID+" factorize changed="<<changed.X );
    163164          Real numErr = Copy(NError);
    164165          VMatrix _.L := If(density<.13,
    … …  
    195196  ////////////////////////////////////////////////////////////////////////////
    196197  //Solves the linear system corresponding to the standarized linear regression
    197   Real solve(Real numSim, VMatrix Y, VMatrix X)
    198   ////////////////////////////////////////////////////////////////////////////
    199   {
    200   //WriteLn("TRACE "+_MID+" solve 1 X="<< VMat2Mat(X));
     198  Real solve(Real numSim_, VMatrix Y_, VMatrix X_)
     199  ////////////////////////////////////////////////////////////////////////////
     200  {
     201    Real numSim = numSim_;
     202    VMatrix Y = Y_;
     203    VMatrix X = X_;
     204  //WriteLn("TRACE "+_MID+" solve 1 ");
    201205    Real Do factorize(X);
    202206    Real If(VRows(_.L)<=0, CMsg::Coded::show
    … …  
    235239  Text _.autodoc.member.draw.unconstrained =
    236240  "Method of generation of a linear block in unconstrained case";
    237   VMatrix draw.unconstrained(Real numSim)
    238   ////////////////////////////////////////////////////////////////////////////
    239   {
    240   //WriteLn("TRACE "+_MID+" draw.unconstrained 2");
    241     VMatrix   b1 = Gaussian(_.N,1,0,1);
    242   //WriteLn("TRACE "+_MID+" draw.unconstrained 3 b1="<<Matrix(VMat2Mat(Tra(b1))));
    243     VMatrix   b2 = CholeskiSolve(_.L,b1,"LtP");
    244   //WriteLn("TRACE "+_MID+" draw.unconstrained 4 _.L="<<Matrix(VMat2Mat(_.L)));
    245   //WriteLn("TRACE "+_MID+" draw.unconstrained 4 b2="<<Matrix(VMat2Mat(Tra(b2))));
    246     VMatrix  (_.blockDef::_.store) := _.solution::nu+b2;
    247   //WriteLn("TRACE "+_MID+" draw.unconstrained 5");
     241  VMatrix draw.unconstrained(Real numSim, VMatrix nu)
     242  ////////////////////////////////////////////////////////////////////////////
     243  {
     244    VMatrix z = Gaussian(_.N,1,0,1);
     245    Real _.betaLogDens := -0.5*VMatDat(MtMSqr(z),1,1);
     246    VMatrix  (_.blockDef::_.store):=nu+CholeskiSolve(_.L,z,"LtP");
    248247    Copy(_.blockDef::_.store)
    249248  };
    … …  
    252251  Text _.autodoc.member.draw.constrained =
    253252  "Method of generation of a linear block in constrained case";
    254   VMatrix draw.constrained(Real numSim)
    255   ////////////////////////////////////////////////////////////////////////////
    256   {
    257     VMatrix nu = _.solution::nu;
     253  VMatrix draw.constrained(Real numSim, VMatrix nu)
     254  ////////////////////////////////////////////////////////////////////////////
     255  {
    258256  //WriteLn("TRACE "+_MID+" draw.constrained 1.1 Max(A*b0-a)="<<VMatMax(_.A*_.blockDef::_.store - a));
    259257    VMatrix d   = _.a - _.A*nu;
    260     VMatrix If(_changed.X, _.D  := Tra(CholeskiSolve(_.L,_.At,"PtL")));
     258    VMatrix If(changed.X, _.D  := Tra(CholeskiSolve(_.L,_.At,"PtL")));
    261259    VMatrix z0  = Tra(Tra(_.blockDef::_.store-nu)*_.Ls);
    262260  //WriteLn("TRACE "+_MID+" draw.constrained 1.2 Max(D*z0-d)="<<VMatMax(_.D*z0 - d));
    … …  
    281279      1
    282280    });
     281    Real _.betaLogDens := -0.5*VMatDat(MtMSqr(z),1,1);
    283282    VMatrix  (_.blockDef::_.store) := nu + CholeskiSolve(_.L,z,"LtP");
    284283    Copy(_.blockDef::_.store)
    … …  
    293292    If(_.blockDef::enabled,
    294293    {
    295       VMatrix aux = _drawer(numSim);
     294      VMatrix aux = drawer(numSim, _.solution::nu);
    296295    //WriteLn("TRACE "+_MID+" draw");
    297296      Real _.blockDef::checkNonFiniteValues(numSim);
    … …  
    304303
    305304  ////////////////////////////////////////////////////////////////////////////
    306   Text _.autodoc.member.maxLikelihood =
    307   "Method of contitioned maximum likelihood";
    308   VMatrix maxLikelihood(Real numSim, VMatrix Y, VMatrix X)
    309   ////////////////////////////////////////////////////////////////////////////
    310   {
    311     Real solve(numSim,Y,X);
    312     VMatrix aux = If(!_.R,
    313     {
    314       _.solution::nu
    315     },
    316     {
    317       VMatrix d = _.a - _.A*_.solution::nu;
    318       If(VMatMax(d)>=0, _.solution::nu,
    319       {
    320         WriteLn("Cannot do maxLikelihood for constrained linear block "+
    321           _.blockDef::_.name,"W");
    322         draw.constrained(numSim)
    323       })
    324     });
    325     VMatrix  (_.blockDef::_.store) := aux;
    326   //WriteLn("TRACE "+_MID+" maxLikelihood aux="<<Matrix(Tra(VMat2Mat(aux))));
    327     Real _.blockDef::checkNonFiniteValues(numSim);
    328     Copy(_.blockDef::_.store)
    329   };
    330 
    331 
    332   ////////////////////////////////////////////////////////////////////////////
    333305  Text _.autodoc.member.setStore =
    334306  "Sets _.store to the specified row vector of values";
Note: See TracChangeset for help on using the changeset viewer.