close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Ticket #844: _reloaderFromMcmc.tol

File _reloaderFromMcmc.tol, 2.8 KB (added by pgea@…, 15 years ago)
Line 
1/////////////////////////////////////////////////////////////////////////////
2// LIBRARY: StdtLib (Standard Library of TOL)
3// FILE: _reloaderFromMcmc.tol
4// PURPOSE:
5/////////////////////////////////////////////////////////////////////////////
6
7/////////////////////////////////////////////////////////////////////////////
8Class @McmcReloaderFromMcmc : @McmcReloader
9/////////////////////////////////////////////////////////////////////////////
10{
11
12// (1) por valor:
13//  Matrix _.mcmc;
14// (2) por referencia:
15  Set _.mcmcSet = Copy(Empty);
16
17  Set  _.colNames;
18
19  ////////////////////////////////////////////////////////////////////////////
20  Matrix _getMcmc(Real void)
21  ////////////////////////////////////////////////////////////////////////////
22  {
23// (1) por valor:
24//    _.mcmc;
25// (2) por referencia:
26    _.mcmcSet[1]
27  };
28
29  ////////////////////////////////////////////////////////////////////////////
30  Set selectIndexes(Set selectedNames)
31  ////////////////////////////////////////////////////////////////////////////
32  {
33    If(!Card(selectedNames) | !Card(_.colNames) , Copy(Empty),
34    {
35      Real If(!HasIndexByName(selectedNames), SetIndexByName(selectedNames));
36      SelectIndexByName(selectedNames, _.colNames)
37    })
38  };
39
40  ////////////////////////////////////////////////////////////////////////////
41  VMatrix reloadSimulation(Real numSim, Set indexes)
42  ////////////////////////////////////////////////////////////////////////////
43  {
44    Real numRow = getRowSequence(numSim);
45    Matrix row = Sub(_getMcmc(?), numRow, 1, 1, Columns(_getMcmc(?)));
46    Mat2VMat(SubCol(row, indexes), TRUE)
47  };
48
49  ////////////////////////////////////////////////////////////////////////////
50  Static @McmcReloaderFromMcmc New(Matrix mcmc, Set colNames, Real sequential,
51    Real burnin)
52  ////////////////////////////////////////////////////////////////////////////
53  {
54    Real mcmc.rows = Rows(mcmc);
55    Real mcmc.cols = Columns(mcmc);
56    Case(mcmc.cols!=Card(colNames), {
57      WriteLn("[@McmcReloaderFromMcmc] MCMC columns differs from "
58        <<"number of parameters","E");
59      @McmcReloader::Null(?)
60    }, burnin>=mcmc.rows, {
61      WriteLn("[@McmcReloaderFromMcmc] MCMC rows is less or equal "
62        <<"than specified burnin","E");
63      @McmcReloader::Null(?)
64    }, True, {
65      @McmcReloaderFromMcmc reloader = [[
66        Set  _.colNames  = colNames;
67// (1) por valor:
68//        Matrix _.mcmc = mcmc;
69// (2) por referencia:
70        Set _.mcmcSet = [[ mcmc ]];
71        Real _.sampleLength = Rows(mcmc) - burnin;
72        Real _.sequential = sequential;
73        Real _.burnin = burnin
74      ]];
75      Real reloader::initialize.sequence(0);
76      Real SetIndexByName(reloader::_.colNames);
77      reloader
78    })
79  }
80
81};