Changeset 4efc00a in tol


Ignore:
Timestamp:
May 11, 2010, 2:58:02 PM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
a868db9
Parents:
5633d43
Message:

multivariate linear model with unknown covariance matrix and constraining linear equalities
refs #902

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

Location:
tol_pkg/BysVecLinReg
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/BysVecLinReg/Multivariate.tol

    r5633d43 r4efc00a  
    7373  //Choleski decomposition of VxIm as sparse explicit((d*m)x(d*m))
    7474  VMatrix _.VxIm.Le = Rand(0,0,0,0);
    75  
     75
     76  ////////////////////////////////////////////////////////////////////////////
     77  // Optional linear constraining equalities
     78  //
     79  //   C * vec(A) = c
     80  //
     81  //Number of linear constraining equalities
     82  Real _.r.C = 0;
     83  //Coefficient matrix of linear constraining equalities
     84  VMatrix _.C = Rand(0,0,0,0);
     85  //Right vector of linear constraining equalities
     86  VMatrix _.c = Rand(0,0,0,0);
     87  ////////////////////////////////////////////////////////////////////////////
     88
    7689  ////////////////////////////////////////////////////////////////////////////
    7790  Real check.dim(Text method, VMatrix M, Real nRow, Real nCol)
    … …  
    155168
    156169  ////////////////////////////////////////////////////////////////////////////
     170  Real set.linearConstrainingEquations(VMatrix C, VMatrix c)
     171  ////////////////////////////////////////////////////////////////////////////
     172  {
     173    Real r = VRows(c);
     174    If(Or(!check.dim("set.linearConstrainingEquations",C,r,_.m*_.d),
     175          !check.dim("set.linearConstrainingEquations",c,r,1      )),False,
     176    {
     177      Real _.r.C := r;
     178      VMatrix _.C := C;
     179      VMatrix _.c := c;
     180      True
     181    })
     182  };
     183
     184  ////////////////////////////////////////////////////////////////////////////
    157185  Real change.X(VMatrix X)
    158186  ////////////////////////////////////////////////////////////////////////////
    … …  
    251279
    252280  ////////////////////////////////////////////////////////////////////////////
     281  VMatrix gibbs.draw.vec.A.std(Real numSim)
     282  ////////////////////////////////////////////////////////////////////////////
     283  {
     284    If(!_.r.C, Gaussian(_.d*_.m,1,0,1),
     285    {
     286      VMatrix C = Tra(_.IdxXLi*Tra(_.C))*_.VxIm.Le;
     287      VMatrix c = _.c - _.C * _.vec.nu;
     288      eqConstrainedStdGaussian(C,c)
     289    })
     290  };
     291
     292  ////////////////////////////////////////////////////////////////////////////
    253293  VMatrix gibbs.draw.vec.A(Real numSim)
    254294  ////////////////////////////////////////////////////////////////////////////
    255295  {
    256     VMatrix e = Gaussian(_.d*_.m,1,0,1);
     296    VMatrix e = gibbs.draw.vec.A.std(numSim);
    257297    VMatrix e.1 = _.VxIm.Le*e;
    258298    VMatrix e.2 = Tra(Tra(e.1)*_.IdxXLi);
  • tol_pkg/BysVecLinReg/test/gen_multivariant_linear_regression.tol

    r5633d43 r4efc00a  
    1010WriteLn("Current Random Seed = "<<rndSeed);
    1111
    12 Real d = IntRand(2,10);
    13 Real m = IntRand(2,10);
    14 Real N = IntRand(m*10,m*100);
     12Real If(!ObjectExist("Real","r.eq"), r.eq = 0, r.eq);
     13
     14Real d = IntRand(r.eq+2,r.eq+10);
     15Real m = IntRand(r.eq+2,r.eq+10);
     16Real N = IntRand(m*5,m*30);
    1517Real sampleLength = 5000;
    1618
    … …  
    2325VMatrix Y = A*X+E;
    2426
     27VMatrix C = If(!r.eq,Rand(0,d*m,0,0),
     28  Round(Rand(r.eq,d*m,-2.5,2.5,"Cholmod.R.Sparse",r.eq*2)));
     29VMatrix c = If(!r.eq,Rand(0,1,0,0),
     30  C*BysVecLinReg::vmatrix2vec(A));
  • tol_pkg/BysVecLinReg/tools.tol

    r5633d43 r4efc00a  
    4343  VMatrix c.2 = c-c.1;
    4444  VMatrix e.2 = MinimumResidualsSolve(C.2,c.2);
    45 //VMatrix C.2*e.2-c.2
    46   e.2
     45  VMatrix err = C.2*e.2-c.2;
     46  Real errMax = VMatMax(Abs(err));
     47  If((n^3)+errMax^2 != n^3,
     48    WriteLn("[BysVecLinReg::eqConstrainedStdGaussian] errMax="<<errMax,"W"));
     49  Triplet(SetCol(p.1<<p.2) | Constant(n,1,1) | VMat2Mat(e.1 << e.2), n, 1)
     50//SetOfMatrix(Tra(p), Constant(n,1,1),VMat2Mat(e.1 << e.2))
    4751};
Note: See TracChangeset for help on using the changeset viewer.