Changeset 50d9df2 in tol
- Timestamp:
- Nov 24, 2008, 1:02:10 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 9e14914
- Parents:
- c6d5b9e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_stdLinearBlock.tol
rc6d5b9e r50d9df2 38 38 //Matrix of border of constraining inequations 39 39 VMatrix _.a = Rand(0,0,0,0); 40 //Transformed restrictions 41 VMatrix _.D = Rand(0,0,0,0); 40 42 //Cholesky decomposition of current information matrix that is not 41 43 //explicitely stored … … 48 50 //factorizations 49 51 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; 50 55 51 56 //Maximum accepted rounding error for Choleski operations … … 115 120 If(And(design.is.constant,VRows(_.L)), 0, 116 121 { 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 128 126 }); 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 }) 137 152 }) 138 153 }; … … 199 214 { 200 215 //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); 208 223 Real If(distBorder<=0, 209 224 { … … 213 228 { 214 229 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"); 216 231 If(!VRows(_.beta0),0, 217 232 { 218 233 VMatrix z0 := Tra(Tra(_.beta0-sr::nu)*_.Ls); 219 VMatrix z := TruncStdGaussian( D,d,z0,1,234 VMatrix z := TruncStdGaussian(_.D,d,z0,1, 220 235 _.blockDef::_.config::bsr.truncMNormal.gibbsNumIter); 221 236 1
Note: See TracChangeset
for help on using the changeset viewer.
