Changeset a62df64 in tol


Ignore:
Timestamp:
Nov 27, 2009, 7:34:10 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
1593d006
Parents:
972bf92
Message:

Using MulVarFunAprox::@BaseC2FunRn2R.Monomial to create the base of approximation functions

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

File:
1 edited

Legend:

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

    r972bf92 ra62df64  
    1414
    1515//Random seed setting
    16 Real PutRandomSeed(0);
     16Real PutRandomSeed(234234);
    1717Real rndSeed = GetRandomSeed(0);
    1818WriteLn("Current Random Seed = "<<rndSeed);
    1919
    20 #Require MulVarFunAprox;
     20//#Require MulVarFunAprox;
    2121//#Embed "../../../_embed_all.tol";
     22#Embed "../../MulVarFunAprox.tol";
    2223
    2324Real n = 2;
    2425
    25 
    26 Set Base.VFun = {SetOfCode(
    27   VMatrix p00 (VMatrix x) { Rand(VRows(x),1,1,1) },
    28   VMatrix p10 (VMatrix x) { SubCol(x,[[1]]) },
    29   VMatrix p01 (VMatrix x) { SubCol(x,[[2]]) },
    30   VMatrix p20 (VMatrix x) { RPow(SubCol(x,[[1]]),2) },
    31   VMatrix p02 (VMatrix x) { RPow(SubCol(x,[[2]]),2) },
    32   VMatrix p11 (VMatrix x) { SubCol(x,[[1]])$*SubCol(x,[[2]]) }
    33 )};
    34 
    35 Set Base.VDerFst = {[[
    36 {SetOfCode(
    37   VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    38   VMatrix p10 (VMatrix x) { Rand(VRows(x),1,1,1) },
    39   VMatrix p01 (VMatrix x) { Rand(VRows(x),1,0,0) },
    40   VMatrix p20 (VMatrix x) { SubCol(x,[[1]])*2 },
    41   VMatrix p02 (VMatrix x) { Rand(VRows(x),1,0,0) },
    42   VMatrix p11 (VMatrix x) { SubCol(x,[[2]]) }
    43 )};
    44 {SetOfCode(
    45   VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    46   VMatrix p10 (VMatrix x) { Rand(VRows(x),1,0,0) },
    47   VMatrix p01 (VMatrix x) { Rand(VRows(x),1,1,1) },
    48   VMatrix p20 (VMatrix x) { Rand(VRows(x),1,0,0) },
    49   VMatrix p02 (VMatrix x) { SubCol(x,[[2]])*2 },
    50   VMatrix p11 (VMatrix x) { SubCol(x,[[1]]) }
    51 )}
    52 ]]};
    53 
    54 Set Base.VDerSnd = {[[
    55 {[[
    56   {SetOfCode(
    57     VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    58     VMatrix p10 (VMatrix x) { Rand(VRows(x),1,0,0) },
    59     VMatrix p01 (VMatrix x) { Rand(VRows(x),1,0,0) },
    60     VMatrix p20 (VMatrix x) { Rand(VRows(x),1,2,2) },
    61     VMatrix p02 (VMatrix x) { Rand(VRows(x),1,0,0) },
    62     VMatrix p11 (VMatrix x) { Rand(VRows(x),1,0,0) }
    63   )};
    64   {SetOfCode(
    65     VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    66     VMatrix p10 (VMatrix x) { Rand(VRows(x),1,0,0) },
    67     VMatrix p01 (VMatrix x) { Rand(VRows(x),1,0,0) },
    68     VMatrix p20 (VMatrix x) { Rand(VRows(x),1,0,0) },
    69     VMatrix p02 (VMatrix x) { Rand(VRows(x),1,0,0) },
    70     VMatrix p11 (VMatrix x) { Rand(VRows(x),1,1,1) }
    71   )}
    72 ]]},
    73 {[[
    74   {SetOfCode(
    75     VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    76     VMatrix p10 (VMatrix x) { Rand(VRows(x),1,0,0) },
    77     VMatrix p01 (VMatrix x) { Rand(VRows(x),1,0,0) },
    78     VMatrix p20 (VMatrix x) { Rand(VRows(x),1,0,0) },
    79     VMatrix p02 (VMatrix x) { Rand(VRows(x),1,0,0) },
    80     VMatrix p11 (VMatrix x) { Rand(VRows(x),1,1,1) }
    81   )};
    82   {SetOfCode(
    83     VMatrix p00 (VMatrix x) { Rand(VRows(x),1,0,0) },
    84     VMatrix p10 (VMatrix x) { Rand(VRows(x),1,0,0) },
    85     VMatrix p01 (VMatrix x) { Rand(VRows(x),1,0,0) },
    86     VMatrix p20 (VMatrix x) { Rand(VRows(x),1,0,0) },
    87     VMatrix p02 (VMatrix x) { Rand(VRows(x),1,2,2) },
    88     VMatrix p11 (VMatrix x) { Rand(VRows(x),1,0,0) }
    89   )}
    90 ]]} ]]};
    91 
    92 Real K = Card(Base.VFun);
    93 
    94 /* */
    95 
    96 Real J = K*100;
     26Real maxDeg = 4;
     27
     28
     29MulVarFunAprox::@BaseC2FunRn2R.Monomial base =
     30  MulVarFunAprox::@BaseC2FunRn2R.Monomial::New(n,maxDeg);
     31
     32Real K = base::_.K;
     33Real J = K*1000;
    9734
    9835VMatrix X = Group("ConcatColumns",For(1,n,VMatrix(Real i)
    … …  
    12360VMatrix Fx = fun.eval.extra.base(X);
    12461
    125 Real lengthRatio = 1*(J/(K*n))^(1/n);
     62Real lengthRatio = 0.5*(J/(K*n))^(1/n);
    12663
    12764Set X.col.info = For(1,n,Set(Real i)
    … …  
    261198Matrix QX.triplet = Group("ConcatRows", For(1,X.maxNeighbour,Matrix(Real i)
    262199{
    263   VMatrix X.hiK = (SubCol(X.h,[[i]])-1)*K;
     200  VMatrix w.i = X.weight[i];
     201  Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(w.i),1.E-15),w.i*0));
     202  VMatrix wi = SubRow(w.i,sel.rows);
     203  VMatrix X.hiK = SubRow((SubCol(X.h,[[i]])-1)*K,sel.rows);
     204  VMatrix Xdif.i = SubRow(X.dif[i],sel.rows);
     205  VMatrix X.j.i = SubRow(X.j,sel.rows);
    264206  Group("ConcatRows", For(1,K,Matrix(Real k)
    265207  {
    266     Code bvf = Base.VFun[k];
    267     VMatrix pk = bvf(X.dif[i]);
    268     VMatrix qk = X.weight[i]$*pk;
    269     Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(qk),1.E-15),qk*0));
    270     VMat2Mat(
    271       SubRow(X.j,sel.rows) |
    272      (SubRow(X.hiK,sel.rows)+k) |
    273       SubRow(qk,sel.rows))
     208    VMatrix pk = base::function.v(k,Xdif.i);
     209    VMatrix qk = wi$*pk;
     210    VMat2Mat(X.j.i | (X.hiK+k) | qk)
    274211  }))
    275212}));
    276213
    277214VMatrix QX = Pack(Convert(Triplet(QX.triplet, J, N),"Cholmod.R.Sparse"));
     215
    278216
    279217VMatrix displ.Z.1 =
    … …  
    317255
    318256Real Z.maxNeighbour = If(Mz,2,0);
    319 VMatrix Z.j=DifEq(1/(1-B),Rand(T,1,1,1));
     257VMatrix Z.t=DifEq(1/(1-B),Rand(T,1,1,1));
    320258
    321259VMatrix Z.h=Z.h.1 | Z.h.2;
    … …  
    340278{
    341279  VMatrix Z.hiK = (SubCol(Z.h,[[i]])-1)*K;
     280  VMatrix Zdif.i = Z.dif[i];
     281  VMatrix Z.t.i = Z.t;
    342282  Group("ConcatRows", For(1,K,Matrix(Real k)
    343283  {
    344284    Real cumRows = 0;
    345     Code bvf = Base.VFun[k];
    346     VMatrix pk = bvf(Z.dif[i])*If(i==1,+1,-1);
    347     Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(pk),1.E-15),pk*0));
    348     VMatrix col.idx = (SubRow(Z.hiK,sel.rows)+k);
     285    VMatrix pk = base::function.v(k,Zdif.i)*If(i==1,+1,-1);
     286    VMatrix col.idx = (Z.hiK+k);
    349287    {
    350       VMatrix row.idx = SubRow(Z.j,sel.rows)+cumRows;
     288      VMatrix row.idx = Z.t.i+cumRows;
    351289      Real cumRows := cumRows + T;
    352       VMat2Mat(row.idx | col.idx | SubRow(pk,sel.rows))
     290      VMat2Mat(row.idx | col.idx | pk)
    353291    }  << If(prior.Z.order<1,Rand(0,3,0,0),
    354292    Group("ConcatRows",For(1,n,Matrix(Real d)
    355293    {
    356       Code bvfd = Base.VDerFst[d][k];
    357       VMatrix pkd = bvfd(Z.dif[i])*If(i==1,+1/2,-1/2);
    358       VMatrix row.idx = SubRow(Z.j,sel.rows)+cumRows;
     294      Real sign = If(i==1,+1/2,-1/2);
     295      VMatrix pkd = base::partial.derivative.1.v(k,Zdif.i,d)*sign;
     296      VMatrix row.idx = Z.t.i+cumRows;
    359297      Real cumRows := cumRows + T;
    360       VMat2Mat(row.idx | col.idx | SubRow(pkd,sel.rows))
     298      VMat2Mat(row.idx | col.idx | pkd)
    361299    })))<< If(prior.Z.order<2,Rand(0,3,0,0),
    362300    Group("ConcatRows",For(1,n,Matrix(Real d1)
    … …  
    364302      Group("ConcatRows",For(d1,n,Matrix(Real d2)
    365303      {
    366         Code bvfd2 = Base.VDerSnd[d1][d2][k];
    367         VMatrix pkd2 = bvfd2(Z.dif[i])*If(i==1,+1/4,-1/4);
    368         VMatrix row.idx = SubRow(Z.j,sel.rows)+cumRows;
     304        Real sign = If(i==1,+1/4,-1/4);
     305        VMatrix pkd2 = base::partial.derivative.2.v(k,Zdif.i,d1,d2)*sign;
     306        VMatrix row.idx = Z.t.i+cumRows;
    369307        Real cumRows := cumRows + T;
    370         VMat2Mat(row.idx | col.idx | SubRow(pkd2,sel.rows))
     308        VMat2Mat(row.idx | col.idx | pkd2)
    371309      }))
    372310    })))
    … …  
    377315Real M = J+Mz;
    378316
    379 VMatrix PZ = Pack(Convert(Triplet(PZ.triplet, Mz, N),"Cholmod.R.Sparse"));
     317VMatrix PZ = Convert(Triplet(PZ.triplet, Mz, N),"Cholmod.R.Sparse");
    380318
    381319VMatrix Fz = Rand(Mz,1,0,0);
Note: See TracChangeset for help on using the changeset viewer.