Changeset dd921c2 in tol
- Timestamp:
- Apr 1, 2009, 3:51:34 PM (18 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- c07b2db
- Parents:
- 24bdea7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_stdLinearBlock.tol
r24bdea7 rdd921c2 59 59 Set _.solution = Copy(Empty); 60 60 61 Real _changed.X = True;61 Real changed.X = True; 62 62 63 63 //Maximum accepted rounding error for Choleski operations … … 67 67 //Current maximum of rounding error in solution 68 68 Real _.cholSolMaxRoundErr = 0; 69 69 //Logarithm of density of last generated vector 70 Real _.betaLogDens = -1/0; 70 71 //Stores the associated drawing method 71 Code _drawer = UnknownCode;72 Code drawer = UnknownCode; 72 73 73 74 //////////////////////////////////////////////////////////////////////////// … … 89 90 VMatrix _.a := a; 90 91 //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); 92 93 //WriteLn("TRACE "+_MID+" initialize 7"); 93 94 VMatrix (_.blockDef::_.store) := If(!_.R, beta0, … … 137 138 If(And(design.is.constant,VRows(_.L)), 0, 138 139 { 139 Real _changed.X := If(Or(VColumns(X)!=VColumns(_old.X),140 Real changed.X := If(Or(VColumns(X)!=VColumns(_old.X), 140 141 VRows (X)!=VRows (_old.X)), -1, 141 142 { 142 143 1+VMatMax(Abs(X-_old.X))-1 143 144 }); 144 If(! _changed.X ,0,145 If(!changed.X ,0, 145 146 { 146 147 Real density = VNonNullCells(X)/(VRows(X)*VColumns(X)); … … 160 161 }, 161 162 { 162 //WriteLn("TRACE"+_MID+" factorize changed="<< _changed.X );163 //WriteLn("TRACE"+_MID+" factorize changed="<<changed.X ); 163 164 Real numErr = Copy(NError); 164 165 VMatrix _.L := If(density<.13, … … 195 196 //////////////////////////////////////////////////////////////////////////// 196 197 //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 "); 201 205 Real Do factorize(X); 202 206 Real If(VRows(_.L)<=0, CMsg::Coded::show … … 235 239 Text _.autodoc.member.draw.unconstrained = 236 240 "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"); 248 247 Copy(_.blockDef::_.store) 249 248 }; … … 252 251 Text _.autodoc.member.draw.constrained = 253 252 "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 { 258 256 //WriteLn("TRACE "+_MID+" draw.constrained 1.1 Max(A*b0-a)="<<VMatMax(_.A*_.blockDef::_.store - a)); 259 257 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"))); 261 259 VMatrix z0 = Tra(Tra(_.blockDef::_.store-nu)*_.Ls); 262 260 //WriteLn("TRACE "+_MID+" draw.constrained 1.2 Max(D*z0-d)="<<VMatMax(_.D*z0 - d)); … … 281 279 1 282 280 }); 281 Real _.betaLogDens := -0.5*VMatDat(MtMSqr(z),1,1); 283 282 VMatrix (_.blockDef::_.store) := nu + CholeskiSolve(_.L,z,"LtP"); 284 283 Copy(_.blockDef::_.store) … … 293 292 If(_.blockDef::enabled, 294 293 { 295 VMatrix aux = _drawer(numSim);294 VMatrix aux = drawer(numSim, _.solution::nu); 296 295 //WriteLn("TRACE "+_MID+" draw"); 297 296 Real _.blockDef::checkNonFiniteValues(numSim); … … 304 303 305 304 //////////////////////////////////////////////////////////////////////////// 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::nu315 },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 ////////////////////////////////////////////////////////////////////////////333 305 Text _.autodoc.member.setStore = 334 306 "Sets _.store to the specified row vector of values";
Note: See TracChangeset
for help on using the changeset viewer.
