Changeset dac1b19 in tol
- Timestamp:
- May 7, 2009, 2:34:23 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- eef206c
- Parents:
- c040c02
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tol/stdlib/math/stat/models/bayesian/bysMcmc/bsr/gibbs/_nonLinBlock.tol
rc040c02 rdac1b19 27 27 " NameBlock config: User configuration parameters\n"; 28 28 ////////////////////////////////////////////////////////////////////////////// 29 BlockSamplerNonLinBlock(29 NameBlock NonLinBlock( 30 30 //Filter evaluator 31 31 NameBlock filterEval, … … 39 39 NameBlock config) 40 40 ////////////////////////////////////////////////////////////////////////////// 41 { 42 //WriteLn("TRACE NonLinBlock 0 "); 43 BysMcmc::BlockSampler blk = [[ 41 {[[ 44 42 //Scalar sampler 45 43 Code _scalarSampler = config::bsr.scalarSampler.nonLinBlock; … … 48 46 //Filter evaluator 49 47 NameBlock _.filterEval = filterEval; 50 51 //Defining the block in the Markov Chain 52 Real _defined = define 53 ( 54 _.filterEval::get.name(0), 55 _.filterEval::get.colNames(0), 56 bsr::_.mcmcPartialHandler, 57 numBlock, 58 firstCol, 59 config 60 ); 48 49 //Filter name 50 Text _.name = _.filterEval::get.name(0); 51 //Message identificator 52 Text _MID = "[NonLinBlock("+_.name+")] "; 61 53 //Name of affected segment in BSR 62 54 Text _.segmentName = _.filterEval::get.segmentName(0); … … 77 69 ((_.bsr::_.modelDef)->NoiseDistrib)[_.segmentNum] 78 70 }); 71 //Non linear parameters 72 Set _.colNames = _.filterEval::get.colNames(0); 73 //Number of non linear parameters 74 Real _.numVar = Card(_.colNames); 79 75 //For input filters is +1, for output ones -1 80 76 Real _.isInputFilter = If(FunctionExist("Set","_.filterEval::get.linBlkNames"), … … 92 88 //It will return a matrix with marginal sampling in selected indexes and ? in 93 89 //other ones that will be sampled by non linear block in the standard way 94 Code _.marginalDraw = If(FunctionExist(" Real","_.filterEval::marginalDraw"),90 Code _.marginalDraw = If(FunctionExist("Matrix","_.filterEval::marginalDraw"), 95 91 { 96 92 WriteLn(_MID+"Using specified marginalDraw method"); … … 99 95 { 100 96 WriteLn(_MID+"Using default marginalDraw method"); 101 Matrix (Real unused) { _defaultMarginalDraw }97 Matrix marginalDraw(Real unused) { _defaultMarginalDraw } 102 98 }); 103 99 //Optional filter method that returns log of prior density for one parameter … … 116 112 Set _.filterColIdx = If(!_.isInputFilter, Copy(Empty), 117 113 { 118 _.bsr::_.mln.blk:: getStoreColIndexes(_.linBlkNames)114 _.bsr::_.mln.blk::_.blockDef::getStoreColIndexes(_.linBlkNames) 119 115 }); 120 116 //Total number of affected parameters in linear block 121 117 //It's 0 for output filters 122 118 Real _.filterColNum = Card(_.filterColIdx); 119 //Defining the block in the Markov Chain 120 NameBlock _.blockDef = BysMcmc::DefineBlock 121 ( 122 _.name, 123 _.colNames, 124 numBlock, 125 firstCol, 126 config 127 ); 123 128 Real _.m = Card(_.segment->EquIdx); 124 129 Matrix _.W = Rand(_.m,1,0,0); … … 147 152 NameBlock arimaBlk = _.bsr::_.arm.blk; 148 153 NameBlock sigBlk = _.bsr::_.sig.blk; 149 Matrix u = VMat2Mat(_. store);154 Matrix u = VMat2Mat(_.blockDef::_.store); 150 155 //WriteLn("TRACE"+_MID+"draw.scalar 1.1 _.isInputFilter = "<<_.isInputFilter); 151 156 Matrix omega= If(!_.isInputFilter, Col(1), 152 SubRow(VMat2Mat(_.bsr::_.mln.blk:: _.store), _.filterColIdx));157 SubRow(VMat2Mat(_.bsr::_.mln.blk::getStore(0)), _.filterColIdx)); 153 158 //WriteLn("TRACE"+_MID+"draw.scalar 1.2 omega("<<Rows(omega)+"x"<<Columns(omega)); 154 159 //WriteLn("TRACE"+_MID+"draw.scalar 1.3 _.Fi("<<Rows(_.Fi)+"x"<<Columns(_.Fi)); … … 170 175 //WriteLn("TRACE"+_MID+"draw.scalar 1.6 d="<<d+" p="<<p+" q="<<q+" m="<<m+" n="<<n); 171 176 //WriteLn("TRACE"+_MID+"draw.scalar 2"); 177 172 178 Matrix mrgDraw = _.marginalDraw(0); 173 179 Set draw.all = For(1, Rows(mrgDraw), Real(Real i) … … 183 189 Real x1 = bounds[2]; 184 190 //WriteLn("TRACE"+_MID+"draw.scalar.one 2.["+IntText(i)+"].2"); 185 //WriteLn("TRACE"+_MID+"draw.scalar.one arimaBlk:: enabled=["<<arimaBlk::enabled+"]");191 //WriteLn("TRACE"+_MID+"draw.scalar.one arimaBlk::_.blockDef::enabled=["<<arimaBlk::_.blockDef::enabled+"]"); 186 192 //WriteLn("TRACE"+_MID+"draw.scalar.one d=["<<d+"]"); 187 193 //WriteLn("TRACE"+_MID+"draw.scalar.one p=["<<p+"]"); … … 231 237 }; 232 238 Code LogDens = Case( 233 Or(Not(arimaBlk:: enabled),And(Not(p),Not(q))),239 Or(Not(arimaBlk::_.blockDef::enabled),And(Not(p),Not(q))), 234 240 LogDens.WhiteNoise, 235 241 d==0, … … 251 257 //WriteLn("TRACE"+_MID+"draw.scalar 3"); 252 258 //Real show.arma(0); 253 Mat2VMat(SetCol(draw.all)) 254 }; 255 256 //////////////////////////////////////////////////////////////////////////// 257 Real _buildWorkSpace(Real unused_) 258 //////////////////////////////////////////////////////////////////////////// 259 { 260 True 261 }; 262 Code _.buildWorkSpace = _buildWorkSpace; 259 Matrix values = SetCol(draw.all); 260 //WriteLn("TRACE"+_MID+"draw 3 "<<Matrix Tra(values)); 261 Real Do setStore(values); 262 //WriteLn("TRACE"+_MID+"draw 5 "); 263 Real _.blockDef::checkNonFiniteValues(numSim); 264 //WriteLn("TRACE"+_MID+"draw.scalar 4"); 265 Copy(_.blockDef::_.store) 266 }; 263 267 264 268 //////////////////////////////////////////////////////////////////////////// … … 269 273 { 270 274 //WriteLn("TRACE"+_MID+"draw 1"); 271 draw.scalar(numSim) 272 }; 273 274 //////////////////////////////////////////////////////////////////////////// 275 Real do.filter(VMatrix Y) 275 If(_.blockDef::enabled, 276 { 277 //WriteLn("TRACE"+_MID+"draw 2"); 278 If(_.blockDef::_.numCol==0, 279 { 280 Real setStore(VMat2Mat(_.blockDef::_.store)); 281 Rand(0,1,0,0) 282 }, 283 { 284 draw.scalar(numSim) 285 }) 286 }, 287 { 288 //WriteLn("TRACE"+_MID+"draw 3"); 289 Copy(_.blockDef::_.store) 290 }) 291 }; 292 293 //////////////////////////////////////////////////////////////////////////// 294 Real filter(VMatrix Y) 276 295 //////////////////////////////////////////////////////////////////////////// 277 296 { … … 293 312 { 294 313 //WriteLn("TRACE "+_MID+"::setStore 1 values("<<Rows(values)+"x"<<Columns(values)+")"); 295 Real putStore(values); 296 Real If(_.N==0, True, 297 { 298 //WriteLn("TRACE "+_MID+"::setStore 3"); 299 Matrix _.Fi := _.filterEval::eval(VMat2Mat(_.store)); 300 //WriteLn("TRACE "+_MID+"::setStore 4"); 301 Real ok = If(!_.isInputFilter, 0, 302 { 303 //WriteLn("TRACE "+_MID+"::setStore 5"); 304 SetMin(For(1,_.filterColNum,Real(Real column) 305 { 306 _.bsr::setSegmentInputCol( 307 SubCol(_.Fi,[[column]]), _.segmentNum, _.filterColIdx[column]) 308 })) 309 }); 310 //WriteLn("TRACE "+_MID+"::setStore 6"); 311 ok 312 }) 314 Real If(_.blockDef::_.numCol==0,0, 315 { 316 //WriteLn("TRACE "+_MID+"::setStore 2"); 317 Real _.blockDef::setStore(values) 318 }); 319 //WriteLn("TRACE "+_MID+"::setStore 3"); 320 Matrix _.Fi := _.filterEval::eval(VMat2Mat(_.blockDef::_.store)); 321 //WriteLn("TRACE "+_MID+"::setStore 4"); 322 Real ok = If(!_.isInputFilter, 0, 323 { 324 //WriteLn("TRACE "+_MID+"::setStore 5"); 325 SetMin(For(1,_.filterColNum,Real(Real column) 326 { 327 _.bsr::setSegmentInputCol( 328 SubCol(_.Fi,[[column]]), _.segmentNum, _.filterColIdx[column]) 329 })) 330 }); 331 //WriteLn("TRACE "+_MID+"::setStore 6"); 332 ok 333 }; 334 335 //////////////////////////////////////////////////////////////////////////// 336 Text _.autodoc.member.setMcmcRow = 337 "Sets _.store to the columns related to this block of a given row of a " 338 "Markov Chain"; 339 Real setMcmcRow(Matrix mcmc, Real row) 340 //////////////////////////////////////////////////////////////////////////// 341 { 342 Real setStore(_.blockDef::getMcmcRow(mcmc, row)) 313 343 } 314 344
Note: See TracChangeset
for help on using the changeset viewer.
