Changeset 50d9df2 in tol


Ignore:
Timestamp:
Nov 24, 2008, 1:02:10 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
9e14914
Parents:
c6d5b9e
Message:

Ensuring input matrix has changed. Else it will reuse old factorization

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

File:
1 edited

Legend:

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

    rc6d5b9e r50d9df2  
    3838  //Matrix of border of constraining inequations
    3939  VMatrix _.a  = Rand(0,0,0,0);
     40  //Transformed restrictions
     41  VMatrix _.D = Rand(0,0,0,0);
    4042  //Cholesky decomposition of current information matrix that is not
    4143  //explicitely stored
    … …  
    4850  //factorizations
    4951  Real design.is.constant = False;
     52  //Matrix of linear system in last iteration
     53  VMatrix _old.X  = Rand(0,0,0,0);
     54  Real _changed.X = True;
    5055
    5156  //Maximum accepted rounding error for Choleski operations
    … …  
    115120    If(And(design.is.constant,VRows(_.L)), 0,
    116121    {
    117       Real sparse = VNonNullCells(X)/(VRows(X)*VColumns(X));
    118       Real numErr = Copy(NError);
    119       VMatrix _.L := If(sparse<.20,
    120       {
    121         CholeskiFactor(X,"XtX")
    122       },
    123       {
    124         VMatrix X_   = Convert(X,"Blas.R.Dense");
    125         VMatrix XtX_ = MtMSqr(X_);
    126         VMatrix XtX  = Convert(XtX_,"Cholmod.R.Sparse");
    127         CholeskiFactor(XtX,"X")
     122      Real _changed.X := If(Or(VColumns(X)!=VColumns(_old.X),
     123                               VRows   (X)!=VRows   (_old.X)), -1,
     124      {
     125        1+VMatMax(Abs(X-_old.X))-1
    128126      });
    129       Real If(Copy(NError)>numErr,
    130       {
    131         Text path = TolAppDataPath+"tmp/"+ToName(_MID)+".oza";
    132         WriteLn("Failed factorization matrix will be stored into "+path);
    133         Ois.Store([[X]],path)
    134       });
    135       VMatrix If(_.R, _.Ls := Convert(_.L, "Cholmod.R.Sparse"));
    136       1
     127      If(!_changed.X ,0,
     128      {
     129        WriteLn("TRACE"+_MID+" factorize changed="<<_changed.X );
     130        Real sparse = VNonNullCells(X)/(VRows(X)*VColumns(X));
     131        Real numErr = Copy(NError);
     132        VMatrix _.L := If(sparse<.20,
     133        {
     134          CholeskiFactor(X,"XtX")
     135        },
     136        {
     137          VMatrix X_   = Convert(X,"Blas.R.Dense");
     138          VMatrix XtX_ = MtMSqr(X_);
     139          VMatrix XtX  = Convert(XtX_,"Cholmod.R.Sparse");
     140          CholeskiFactor(XtX,"X")
     141        });
     142        Real If(Copy(NError)>numErr,
     143        {
     144          Text path = TolAppDataPath+"tmp/"+ToName(_MID)+".oza";
     145          WriteLn("Failed factorization matrix will be stored into "+path);
     146          Ois.Store([[X]],path)
     147        });
     148        VMatrix If(_.R, _.Ls := Convert(_.L, "Cholmod.R.Sparse"));
     149        VMatrix _old.X := X;
     150        1
     151      })
    137152    })
    138153  };
    … …  
    199214  {
    200215  //WriteLn("TRACE "+_MID+" draw.constrained 1.1 Max(A*b0-a)="<<VMatMax(_.A*_.blockDef::_.store - a));
    201     VMatrix   d   = _.a - _.A*sr::nu;
    202     VMatrix   D   = Tra(CholeskiSolve(_.L,_.At,"PtL"));
    203     VMatrix   z0  = Tra(Tra(_.blockDef::_.store-sr::nu)*_.Ls);
    204   //WriteLn("TRACE "+_MID+" draw.constrained 1.2 Max(D*z0-d)="<<VMatMax(D*z0 - d));
    205     VMatrix   z   = TruncStdGaussian(D,d,z0,1,
    206                      _.blockDef::_.config::bsr.truncMNormal.gibbsNumIter);
    207     Real distBorder = VMatMax(D*z-d);
     216    VMatrix d   = _.a - _.A*sr::nu;
     217    VMatrix If(_changed.X, _.D  := Tra(CholeskiSolve(_.L,_.At,"PtL")));
     218    VMatrix z0  = Tra(Tra(_.blockDef::_.store-sr::nu)*_.Ls);
     219  //WriteLn("TRACE "+_MID+" draw.constrained 1.2 Max(D*z0-d)="<<VMatMax(_.D*z0 - d));
     220    VMatrix z = TruncStdGaussian(_.D,d,z0,1,
     221                 _.blockDef::_.config::bsr.truncMNormal.gibbsNumIter);
     222    Real distBorder = VMatMax(_.D*z-d);
    208223    Real If(distBorder<=0,
    209224    {
    … …  
    213228    {
    214229      WriteLn(_MID+" Found a point that doesn't match constrains Max(D*z-d)="<<
    215         VMatMax(D*z-d)+"\n Trying again");
     230        VMatMax(_.D*z-d)+"\n Trying again");
    216231      If(!VRows(_.beta0),0,
    217232      {
    218233        VMatrix z0 := Tra(Tra(_.beta0-sr::nu)*_.Ls);
    219         VMatrix z  := TruncStdGaussian(D,d,z0,1,
     234        VMatrix z  := TruncStdGaussian(_.D,d,z0,1,
    220235                     _.blockDef::_.config::bsr.truncMNormal.gibbsNumIter);
    221236        1
Note: See TracChangeset for help on using the changeset viewer.