Changeset dac1b19 in tol


Ignore:
Timestamp:
May 7, 2009, 2:34:23 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
eef206c
Parents:
c040c02
Message:

Method marginalDraw returns Matrix instead of Real

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

File:
1 edited

Legend:

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

    rc040c02 rdac1b19  
    2727"  NameBlock config: User configuration parameters\n";
    2828//////////////////////////////////////////////////////////////////////////////
    29   BlockSampler NonLinBlock(
     29  NameBlock NonLinBlock(
    3030    //Filter evaluator
    3131    NameBlock filterEval,
    … …  
    3939    NameBlock config)
    4040//////////////////////////////////////////////////////////////////////////////
    41 {
    42 //WriteLn("TRACE NonLinBlock 0 ");
    43   BysMcmc::BlockSampler blk = [[
     41{[[
    4442  //Scalar sampler
    4543  Code _scalarSampler = config::bsr.scalarSampler.nonLinBlock;
    … …  
    4846  //Filter evaluator
    4947  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+")] ";
    6153  //Name of affected segment in BSR
    6254  Text _.segmentName = _.filterEval::get.segmentName(0);
    … …  
    7769    ((_.bsr::_.modelDef)->NoiseDistrib)[_.segmentNum]
    7870  });
     71  //Non linear parameters
     72  Set _.colNames = _.filterEval::get.colNames(0);
     73  //Number of non linear parameters
     74  Real _.numVar = Card(_.colNames);
    7975  //For input filters is +1, for output ones -1
    8076  Real _.isInputFilter = If(FunctionExist("Set","_.filterEval::get.linBlkNames"),
    … …  
    9288  //It will return a matrix with marginal sampling in selected indexes and ? in
    9389  //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"),
    9591  {
    9692    WriteLn(_MID+"Using specified marginalDraw method");
    … …  
    9995  {
    10096    WriteLn(_MID+"Using default marginalDraw method");
    101     Matrix (Real unused) { _defaultMarginalDraw }
     97    Matrix marginalDraw(Real unused) { _defaultMarginalDraw }
    10298  });
    10399  //Optional filter method that returns log of prior density for one parameter
    … …  
    116112  Set _.filterColIdx = If(!_.isInputFilter, Copy(Empty),
    117113  {
    118     _.bsr::_.mln.blk::getStoreColIndexes(_.linBlkNames)
     114    _.bsr::_.mln.blk::_.blockDef::getStoreColIndexes(_.linBlkNames)
    119115  });
    120116  //Total number of affected parameters in linear block
    121117  //It's 0 for output filters
    122118  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  );
    123128  Real _.m = Card(_.segment->EquIdx);
    124129  Matrix _.W   = Rand(_.m,1,0,0);
    … …  
    147152    NameBlock arimaBlk  = _.bsr::_.arm.blk;
    148153    NameBlock sigBlk    = _.bsr::_.sig.blk;
    149     Matrix u = VMat2Mat(_.store);
     154    Matrix u = VMat2Mat(_.blockDef::_.store);
    150155  //WriteLn("TRACE"+_MID+"draw.scalar 1.1 _.isInputFilter = "<<_.isInputFilter);
    151156    Matrix omega= If(!_.isInputFilter, Col(1),
    152       SubRow(VMat2Mat(_.bsr::_.mln.blk::_.store), _.filterColIdx));
     157      SubRow(VMat2Mat(_.bsr::_.mln.blk::getStore(0)), _.filterColIdx));
    153158  //WriteLn("TRACE"+_MID+"draw.scalar 1.2 omega("<<Rows(omega)+"x"<<Columns(omega));
    154159  //WriteLn("TRACE"+_MID+"draw.scalar 1.3 _.Fi("<<Rows(_.Fi)+"x"<<Columns(_.Fi));
    … …  
    170175  //WriteLn("TRACE"+_MID+"draw.scalar 1.6 d="<<d+" p="<<p+" q="<<q+" m="<<m+" n="<<n);
    171176  //WriteLn("TRACE"+_MID+"draw.scalar 2");
     177   
    172178    Matrix mrgDraw = _.marginalDraw(0);
    173179    Set draw.all = For(1, Rows(mrgDraw), Real(Real i)
    … …  
    183189      Real x1 = bounds[2];
    184190    //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+"]");
    186192    //WriteLn("TRACE"+_MID+"draw.scalar.one d=["<<d+"]");
    187193    //WriteLn("TRACE"+_MID+"draw.scalar.one p=["<<p+"]");
    … …  
    231237      };
    232238      Code LogDens = Case(
    233         Or(Not(arimaBlk::enabled),And(Not(p),Not(q))),
     239        Or(Not(arimaBlk::_.blockDef::enabled),And(Not(p),Not(q))),
    234240          LogDens.WhiteNoise,
    235241        d==0,                     
    … …  
    251257  //WriteLn("TRACE"+_MID+"draw.scalar 3");
    252258  //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  };
    263267
    264268  ////////////////////////////////////////////////////////////////////////////
    … …  
    269273  {
    270274  //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)
    276295  ////////////////////////////////////////////////////////////////////////////
    277296  {
    … …  
    293312  {
    294313  //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))
    313343  }
    314344
Note: See TracChangeset for help on using the changeset viewer.