Changeset 77c938e in tol


Ignore:
Timestamp:
Mar 1, 2010, 4:34:48 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
13f9a4e
Parents:
f77a89a
Message:

Using efficient grouping functions

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

Location:
tol_pkg
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MhCnstrLinRegArima/test/test_0001/test.tol

    rf77a89a r77c938e  
    3232Real MLHSteps = 0;
    3333//Length of MCMC
    34 Real SampleLength = 500;
     34Real Burnin = 500;
     35Real SampleLength = 2000;
    3536
    3637/////////////////////////////////////////////////////////////////////////////
    … …  
    3839/////////////////////////////////////////////////////////////////////////////
    3940//Number of variables of each observational node
    40 Real n = 2;
     41Real n = 200;
    4142//Data length of each observational node
    42 Real m  = IntRand(100, 400);
     43Real m  = n*IntRand(2, 10)+IntRand(100,1000);
    4344//Number of inequations
    44 Real r = IntRand(0,2*n);
     45Real r = IntRand(0,4*n);
    4546//Enables/disables full ARIMA components
    46 Real enableARMA = IntRand(0,1);
     47Real enableARMA = IntRand(1,1);
    4748//Seasonal periodicity
    4849Real S = 7;
    … …  
    7374  {
    7475    Real avr = Rand(-10, 10);
    75     Real sig = Rand(2, 4);
     76    Real sig = Rand(1, 2);
    7677    Gaussian(m,1,avr,sig)
    7778  }));
    … …  
    8788
    8889//Standard deviation
    89 Real s = Rand(0.1,0.4);
     90Real s = Rand(0.1,0.2);
    9091//Variance
    9192Real s2 = s^2;
    … …  
    159160{
    160161  WriteLn("Initializing Markov Chain ...");
     162  Real t0 = Copy(Time);
    161163  Real mclra::_.gInitial := s/2;
    162164  Real mclra::initialize(b0_);
    163165  Matrix mcmc  = Rand(0,mclra::_.n,0,0);
    164166  Matrix cache = Rand(0,mclra::_.n,0,0);
    165   While(Rows(mcmc)<SampleLength,
     167  While(Rows(mcmc)<Burnin+SampleLength,
    166168  {
    167169    Real If(Rows(mcmc) < MLHSteps,
    … …  
    177179    True
    178180  });
     181  Real t1 = Copy(Time);
     182  Real ts = (t1-t0)/(Burnin+SampleLength);
     183  WriteLn("  Time by simulation:"<<ts+" seconds");
    179184  mcmc
    180185});
    181 
    182 Set Include("test_circle.tol");
    183 Set Include("test_bsr.tol");
    184 
    185 //Chart circle on real target beta and MCMCŽs all together odd pairs against
    186 Matrix mcmc = circle | bsr.mcmc | Group("ConcatColumns",MCMC);
    187186
    188187Set gelman.diag = RCODA::gelman.diag(MCMC,{[[
    … …  
    192191  Real transform=FALSE,
    193192  Real autoburnin=TRUE]]});
     193
     194Set MCMC.b = EvalSet(MCMC,Matrix(Matrix mcmc)
     195{
     196  SubRow(mcmc,Range(Burnin+1,Burnin+SampleLength,1))
     197});
     198Set gelman.diag.b = RCODA::gelman.diag(MCMC.b,{[[
     199  Real verbose=TRUE,
     200  Real varByCol=TRUE,
     201  Real confidence=0.95,
     202  Real transform=FALSE,
     203  Real autoburnin=TRUE]]});
     204
     205Set Include("test_bsr.tol");
     206
     207//Chart circle on real target beta and MCMCŽs all together odd pairs against
     208Matrix mcmc  = Group("ConcatColumns",MCMC);
     209Matrix mcmc.b = Matrix If(n==2,
     210{
     211  Set Include("test_circle.tol");
     212  circle | bsr.mcmc | Group("ConcatColumns",MCMC.b) 
     213},
     214{
     215  Set Include("test_circle.tol");
     216  circle | bsr.mcmc | Group("ConcatColumns",MCMC.b)
     217});
    194218
    195219
  • tol_pkg/MhCnstrLinRegArima/test/test_0001/test_bsr.tol

    rf77a89a r77c938e  
    5555BysMcmc::@Config bsr.config = [[
    5656//MCMC dimensions
    57   Real mcmc.burnin        =  100;
     57  Real mcmc.burnin        =  Burnin;
    5858  Real mcmc.sampleLength  = SampleLength;
    5959  Real mcmc.cacheLength   =  100;
    60   Real bsr.linBlk.MH.useAfterIter   = 10
     60  Real bsr.linBlk.MH.useAfterIter   = 1/0
    6161]];
    6262
  • tol_pkg/MhCnstrLinRegArima/test/test_0001/test_circle.tol

    rf77a89a r77c938e  
    88Real mclra::initialize(b);
    99Real realMaxLikelihood = mclra::_.log.P;
    10 Real mclra::_.ratio := s/100;
     10Real mclra::_.ratio := s/500;
    1111Matrix circle = Group("ConcatRows", For(1,SampleLength, Matrix(Real numSim)
    1212{
  • tol_pkg/MulVarFunAprox/DesignC2.Monomial.Spheric.MeshFree.tol

    rf77a89a r77c938e  
    5252  //////////////////////////////////////////////////////////////////////////////
    5353  {
    54     Text _MID = "[@DesignC2.Monomial.Spheric.MeshFree::build.stress.points] ";
     54    Text _MID = "[@DesignC2.Monomial.Spheric.Delaunay2D::build.stress.points] ";
    5555    Real _.Z.maxNeighbour := If(prior.Z.order>=0,2,0);
    5656    If(!_.Z.maxNeighbour,
    … …  
    7474    {
    7575      And(
    76         LE(distance_[k], Constant(_.J,1,stress.maxDistance)),
     76        LE(distance_[k], Constant(_.H,1,stress.maxDistance)),
    7777        LT(Y1_[k],Y2_[k]))
    7878    });
    … …  
    115115  })};
    116116
     117
    117118  //////////////////////////////////////////////////////////////////////////////
    118119  Real build.border.points(Real void)
  • tol_pkg/MulVarFunAprox/DesignC2.Spheric.tol

    rf77a89a r77c938e  
    7272    SubRow(_.R,VCol2Set(Y.idx))
    7373  };
     74
     75  //////////////////////////////////////////////////////////////////////////////
     76    VMatrix build.obs(VMatrix X)
     77  //////////////////////////////////////////////////////////////////////////////
     78  {
     79    FunRn2R::@BaseC2.Eval.Function eval =
     80       FunRn2R::@BaseC2.Eval.Function::New(get.base(0));
     81    MatQuery::@KNN.Neighbourhood ngbh =
     82      _.ann::search(VMat2Mat(X),_.X.maxNeighbour);
     83    Real m = VRows(X);
     84    VMatrix dist = Mat2VMat(Sqrt(ngbh::_.distance2));
     85    VMatrix X.h = Mat2VMat(ngbh::_.neighbour);
     86    VMatrix X.idx = DifEq(1/(1-B),Constant(m,1,1));
     87    VMatrix triplet.all = Group("ConcatRows", For(1,_.X.maxNeighbour,VMatrix(Real k)
     88    {
     89      VMatrix X.h.k = SubCol(X.h,[[k]]);
     90      VMatrix dist.k = SubCol(dist,[[k]]);
     91      VMatrix R = get.radius(X.h.k);
     92      VMatrix tao = dist.k $/ R;
     93      VMatrix lambda = (-tao^2+1)^4;
     94      VMatrix match = LT(dist.k,R);
     95      SubRow(X.idx | X.h.k | dist.k | tao| lambda, MatQuery::SelectMatch(match))
     96    }));
     97    VMatrix x.idx = SubCol(triplet.all,[[1]]);
     98    VMatrix y.idx = SubCol(triplet.all,[[2]]);
     99    VMatrix xy.idx = x.idx | y.idx;
     100    VMatrix lambda.col = SubCol(triplet.all,[[5]]);
     101    VMatrix triplet.lambda = xy.idx | lambda.col;
     102    VMatrix lambda = Triplet(VMat2Mat(triplet.lambda),m,_.H);
     103    VMatrix sum.lambda = lambda*Constant(_.H,1,1);
     104    VMatrix sum.lambda.inv = Convert(sum.lambda,"Blas.R.Dense")^-1;
     105    VMatrix weight = Eye(m,m,0,sum.lambda.inv)*lambda;
     106    VMatrix dif =
     107      SubRow(  X,VCol2Set(SubCol(triplet.all,[[1]]))) -
     108      SubRow(_.Y,VCol2Set(SubCol(triplet.all,[[2]]))) ;
     109    VMatrix P.row = Group("ConcatRows", For(1,_.K,VMatrix(Real k)
     110    {
     111      x.idx
     112    }));
     113    VMatrix P.y = Group("ConcatRows", For(1,_.K,VMatrix(Real k)
     114    {
     115      y.idx
     116    }));
     117    VMatrix YnCum = DifEq(1/(1-B),_.Yn);
     118    VMatrix YnCumB = Sub(SetCol([[0]])<<YnCum,1,1,_.H,1);
     119    VMatrix P.YnCum  = SubRow(YnCum, VCol2Set(P.y));
     120    VMatrix P.YnCumB = SubRow(YnCumB,VCol2Set(P.y));
     121    VMatrix P.k = Group("ConcatRows", For(1,_.K,VMatrix(Real k)
     122    {
     123      y.idx*0+k
     124    }));
     125    VMatrix P.col = P.YnCumB + P.k;
     126    VMatrix P.match = LE(P.col,P.YnCum);
     127    Real eval::upgrade.cache(dif);
     128    VMatrix P.ev = Group("ConcatRows", For(1,_.K,VMatrix(Real k)
     129    {
     130      lambda.col $* eval::evaluate.v(k,dif)
     131    }));
     132    Matrix P.triplet = VMat2Mat(
     133      SubRow(P.row | P.col | P.ev, MatQuery::SelectMatch(P.match)));
     134    VMatrix Px = Pack(Convert(Triplet(P.triplet, m, _.N),"Cholmod.R.Sparse"));
     135    VMatrix Qx = Eye(m,m,0,sum.lambda.inv)*Px
     136  };
     137
    74138
    75139  ///////////////////////////////////////////////////////////////////////////
  • tol_pkg/MulVarFunAprox/MulVarFunAprox.tol

    rf77a89a r77c938e  
    2222#Embed "DesignC2.Monomial.Spheric.Grid.tol";
    2323#Embed "DesignC2.Monomial.Spheric.MeshFree.tol";
     24#Embed "DesignC2.Monomial.Spheric.Delaunay2D.tol";
    2425#Embed "ModelC2.tol"
    2526
Note: See TracChangeset for help on using the changeset viewer.