Changeset 1a21056e in tol


Ignore:
Timestamp:
Mar 22, 2009, 6:00:53 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
c325af8
Parents:
0987ed8
Message:

Preparing for preconditioned Cholesky decomposition

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

File:
1 edited

Legend:

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

    r0987ed8 r1a21056e  
    2626    config
    2727  );
     28  Real _drop_val = config::bsr.linBlk.X.drop;
    2829  //Messages IDentifier
    2930  Text    _MID = "["+_.blockDef::_.name+"] ";
    … …  
    4445  VMatrix _.L  = Rand(0,0,0,0);
    4546  VMatrix _.Ls = Rand(0,0,0,0);
     47  //Preconditioning
     48  VMatrix _.H  = Rand(0,0,0,0);
     49  VMatrix _.Hs = Rand(0,0,0,0);
    4650  //Last known valid initial point for constrained simulation
    4751  VMatrix _.beta0 = Rand(0,0,0,0);
    … …  
    112116
    113117  ////////////////////////////////////////////////////////////////////////////
     118    VMatrix _drop(VMatrix X)
     119  ////////////////////////////////////////////////////////////////////////////
     120  {
     121    Drop(X, _drop_val)
     122  };
     123
     124  ////////////////////////////////////////////////////////////////////////////
    114125  //Update Cholesky factorization matrix _.L
    115126  //If design matrix is assumed as constant does it just the first time
    … …  
    127138      If(!_changed.X ,0,
    128139      {
    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,
     140        Real density = VNonNullCells(X)/(VRows(X)*VColumns(X));
     141      //WriteLn("TRACE "+_MID+" factorize density = "<<density);
     142        If(And(_.blockDef::_.config::bsr.linBlk.usePreconditioning,VRows(_.L)),
    133143        {
    134           CholeskiFactor(X,"XtX")
    135         },
     144          VMatrix Hs = _.Ls;
     145          VMatrix H  = _.L;
     146          VMatrix G  = Tra(CholeskiSolve(H,Tra(X),"PtL"));
     147          Real density.G = VNonNullCells(G)/(VRows(G)*VColumns(G));
     148        //WriteLn("TRACE "+_MID+" factorize density G = "<<density.G);
     149          VMatrix S  = CholeskiFactor(G,"XtX");
     150          VMatrix Ss = CholeskiSolve(S,Convert(S, "Cholmod.R.Sparse"),"P");
     151          VMatrix _.Ls := Hs*Ss;
     152          VMatrix _.L  := _.Ls;
     153          1
     154        },       
    136155        {
    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,
    149         {
    150           _.Ls := CholeskiSolve(_.L,Convert(_.L, "Cholmod.R.Sparse"),"P")
    151         });
    152         VMatrix _old.X := X;
    153         1
     156        //WriteLn("TRACE"+_MID+" factorize changed="<<_changed.X );
     157          Real numErr = Copy(NError);
     158          VMatrix _.L := If(density<.13,
     159          {
     160            CholeskiFactor(X,"XtX")
     161          },
     162          {/*
     163            Text path = TolAppDataPath+"tmp/"+ToName(_MID)+"_dense_factorize.oza";
     164            WriteLn(_MID+"Dense factorization matrix will be stored into "+path);
     165            Real Ois.Store([[X]],path); */
     166            VMatrix X_   = Convert(X,"Blas.R.Dense");
     167            VMatrix XtX_ = MtMSqr(X_);
     168            VMatrix XtX = Convert(XtX_,"Cholmod.R.Sparse");
     169            CholeskiFactor(XtX,"X")
     170          });
     171          Real If(Copy(NError)>numErr,
     172          {
     173            Text path = TolAppDataPath+"tmp/"+ToName(_MID)+"_error_factorize.oza";
     174            WriteLn(_MID+"Failed factorization matrix will be stored into "+path);
     175            Ois.Store([[X]],path)
     176          });
     177          VMatrix If(_.R,
     178          {
     179            _.Ls := CholeskiSolve(_.L,Convert(_.L, "Cholmod.R.Sparse"),"P")
     180          });
     181          VMatrix _old.X := X;
     182          1
     183        })
    154184      })
    155185    })
    156186  };
    157187 
     188
    158189  ////////////////////////////////////////////////////////////////////////////
    159190  //Solves the linear system corresponding to the standarized linear regression
Note: See TracChangeset for help on using the changeset viewer.