Changeset 1a21056e in tol
- Timestamp:
- Mar 22, 2009, 6:00:53 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- c325af8
- Parents:
- 0987ed8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_stdLinearBlock.tol
r0987ed8 r1a21056e 26 26 config 27 27 ); 28 Real _drop_val = config::bsr.linBlk.X.drop; 28 29 //Messages IDentifier 29 30 Text _MID = "["+_.blockDef::_.name+"] "; … … 44 45 VMatrix _.L = Rand(0,0,0,0); 45 46 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); 46 50 //Last known valid initial point for constrained simulation 47 51 VMatrix _.beta0 = Rand(0,0,0,0); … … 112 116 113 117 //////////////////////////////////////////////////////////////////////////// 118 VMatrix _drop(VMatrix X) 119 //////////////////////////////////////////////////////////////////////////// 120 { 121 Drop(X, _drop_val) 122 }; 123 124 //////////////////////////////////////////////////////////////////////////// 114 125 //Update Cholesky factorization matrix _.L 115 126 //If design matrix is assumed as constant does it just the first time … … 127 138 If(!_changed.X ,0, 128 139 { 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)), 133 143 { 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 }, 136 155 { 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 }) 154 184 }) 155 185 }) 156 186 }; 157 187 188 158 189 //////////////////////////////////////////////////////////////////////////// 159 190 //Solves the linear system corresponding to the standarized linear regression
Note: See TracChangeset
for help on using the changeset viewer.
