Changeset 9002d5f in tol


Ignore:
Timestamp:
Jan 6, 2010, 11:40:22 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
f1a9d95
Parents:
43068ca
Message:

Preparing for new spheric evaluation methods

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

Location:
tol_pkg/MulVarFunAprox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MulVarFunAprox/DesignC2.Monomial.Spheric.Grid.tol

    r43068ca r9002d5f  
    5252  {
    5353    Text _MID = "[@DesignC2.Monomial.Spheric.Grid::build.reference.points] ";
    54     VMatrix _.Y := _.grid::_.Y;
     54    Real _.X.maxNeighbour := 1+2*_.n;
     55    Real set.reference.points(_.grid::_.Y);
    5556    VMatrix Y.h = Mat2VMat(_.grid::_.Y.h);
    5657    VMatrix _.Y.neighbourhood := Y.h | Group("ConcatColumns",
    … …  
    6263    Set X.class = Classify(Col2Set(_.grid::point2index(_.X)),Compare);
    6364    VMatrix _.Yj := Mat2VMat(SetMat([[EvalSet(X.class,Card)]]),1);
    64     Real _.X.maxNeighbour := 1+2*_.n;
    65     Real _.H := _.grid::_.H
     65    Real _.H
    6666  };
    6767
    … …  
    7373    WriteLn("TRACE "+_MID+"1");
    7474    Real _.Z.maxNeighbour := If(prior.Z.order>=0,2,0);
     75    If(!_.Z.maxNeighbour,
     76    {
     77      VMatrix _.Yt := Zeros(_.H,1);
     78      Real _.Tz := 0
     79    },{
     80    WriteLn("TRACE "+_MID+"2.1");
    7581    Matrix Y.neighbour.triplet = Group("ConcatRows", For(1,_.H,Matrix(Real h)
    7682    {
    … …  
    8187    }));
    8288
    83     WriteLn("TRACE "+_MID+"2");
     89    WriteLn("TRACE "+_MID+"2.2");
    8490    VMatrix Y.neighbour.1.map = Triplet(Y.neighbour.triplet,_.H,_.H);
    8591    VMatrix Y.neighbour.2.map = Y.neighbour.1.map*Y.neighbour.1.map;
    … …  
    140146      prior.Z.order==2, _.Tz*(1+_.n*3/2+(1/2)*_.n^2));
    141147    _.Tz
    142   };
     148  })};
    143149
    144150  //////////////////////////////////////////////////////////////////////////////
    … …  
    203209  }
    204210
    205 
    206211};
  • tol_pkg/MulVarFunAprox/DesignC2.Monomial.Spheric.MeshFree.tol

    r43068ca r9002d5f  
    1717//Configuration parameters
    1818//////////////////////////////////////////////////////////////////////////////
    19   MatQuery::@ANN.KDTree _.ann;
    2019  Real stress.maxDistance;
    21 
    22 //////////////////////////////////////////////////////////////////////////////
    23 //Auxiliar members
    24 //////////////////////////////////////////////////////////////////////////////
    25   VMatrix _.R =Rand(0,0,0,0);
    26   MatQuery::@KNN.Neighbourhood _.ngbh;
    2720
    2821  ////////////////////////////////////////////////////////////////////////////
    … …  
    3023    VMatrix X,
    3124    Real maxNeighbour,
    32     Real stress.maxDistance_,
    33     Real radius.margin)
     25    Real radius.margin,
     26    Real stress.maxDistance_)
    3427  ////////////////////////////////////////////////////////////////////////////
    3528  {
    … …  
    4033      Real _.J = VRows(X);
    4134      Real _.X.maxNeighbour = maxNeighbour+1;
    42       Real stress.maxDistance = stress.maxDistance_;
    4335      Real _.radius.margin = radius.margin;
    44       MatQuery::@ANN.KDTree _.ann =
    45         MatQuery::@ANN.KDTree::New(VMat2Mat(X));
    46       MatQuery::@KNN.Neighbourhood _.ngbh =
    47         _.ann::search(_.ann::_.X,_.X.maxNeighbour)
     36      Real stress.maxDistance = stress.maxDistance_
    4837    ]]
    4938  };
    … …  
    5443  {
    5544    Text _MID = "[@DesignC2.Monomial.Spheric.MeshFree::build.reference.points] ";
    56     VMatrix _.Y := _.X;
    57     Real _.H := VRows(_.Y);
    58     VMatrix _.R :=
    59       Mat2VMat(Sqrt(SubCol(_.ngbh::_.distance2,[[_.X.maxNeighbour]])))*
    60       (1+Min(0,_.radius.margin));
     45    Real set.reference.points(_.X);
    6146    VMatrix _.Yj := Constant(_.H,1,_.X.maxNeighbour-1);
    6247    _.H
    … …  
    136121    VMatrix _.Yb := Zeros(_.H,1);
    137122    Real _.Tb := 0
    138   };
    139 /*
    140   //////////////////////////////////////////////////////////////////////////////
    141     Real build.base(Real void)
    142   //////////////////////////////////////////////////////////////////////////////
    143   {
    144     Text _MID = "[@DesignC2.Monomial::build.base] ";
    145     VMatrix _.Yn :=
    146       Floor(Min(Rand(_.H,1,_.K0,_.K0),Max(_.Ym/min.contrast.surface,_.Ym*0+1)));
    147    
    148     Set Append(_.base, [[base.feasible]]);
    149     Real _.base.sel := Card(_.base);
    150     _.K
    151   };
    152 */
    153   ////////////////////////////////////////////////////////////////////////////
    154     VMatrix match.evaluable(VMatrix X)
    155   ////////////////////////////////////////////////////////////////////////////
    156   {
    157     MatQuery::@KNN.Neighbourhood ngbh =
    158       _.ann::search(VMat2Mat(X),1);
    159     VMatrix Y = SubRow(_.Y,Col2Set(ngbh::_.neighbour));
    160     VMatrix dist = Mat2VMat(Sqrt(ngbh::_.distance2));
    161     VMatrix X.h = Mat2VMat(ngbh::_.neighbour);
    162     LE(dist,get.radius(X.h))$*
    163     LE(dist,Constant(VRows(dist),1,stress.maxDistance))
    164    
    165   };
    166 
    167   //////////////////////////////////////////////////////////////////////////////
    168   VMatrix closest.reference.index(VMatrix X)
    169   //////////////////////////////////////////////////////////////////////////////
    170   {
    171     MatQuery::@KNN.Neighbourhood ngbh =
    172       _.ann::search(VMat2Mat(X),_.X.maxNeighbour);
    173     Mat2VMat(ngbh::_.neighbour)
    174   };
    175 
    176   //////////////////////////////////////////////////////////////////////////////
    177   VMatrix get.radius(VMatrix Y.idx)
    178   //////////////////////////////////////////////////////////////////////////////
    179   {
    180     SubRow(_.R,VCol2Set(Y.idx))
    181   };
    182 
    183   ///////////////////////////////////////////////////////////////////////////
    184     VMatrix generate.internal.points(Real m)
    185   ///////////////////////////////////////////////////////////////////////////
    186   {
    187     Text _MID = "[@DesignC2.Monomial.Spheric.MeshFree::generate.internal.points] ";
    188     WriteLn("TRACE "+_MID+"1 m="<<m);
    189     VMatrix h = Round(Rand(m,1,0.5,_.H+0.499999999));
    190     WriteLn("TRACE "+_MID+"2 h:\n"<<h);
    191     VMatrix y = SubRow(_.Y,VCol2Set(h));
    192     WriteLn("TRACE "+_MID+"3 y:\n"<<y);
    193     VMatrix v = Gaussian(m,_.n,0,1);
    194     WriteLn("TRACE "+_MID+"4 v:\n"<<v);
    195     VMatrix u = v*(VMatDat(MtMSqr(v),1,1)^-0.5);
    196     WriteLn("TRACE "+_MID+"5 u:\n"<<u);
    197     VMatrix rnd = get.radius(h)$*Rand(m,1,0,1);
    198     WriteLn("TRACE "+_MID+"5 rnd:\n"<<rnd);
    199     VMatrix r = Eye(m,m,0,rnd);
    200     WriteLn("TRACE "+_MID+"6 r:\n"<<r);
    201     y + r * u
    202123  }
    203124
    204 
    205125};
  • tol_pkg/MulVarFunAprox/DesignC2.Spheric.tol

    r43068ca r9002d5f  
    1818  Real _.radius.margin;
    1919
     20//////////////////////////////////////////////////////////////////////////////
     21//Auxiliar members
     22//////////////////////////////////////////////////////////////////////////////
     23  VMatrix _.R =Rand(0,0,0,0);
     24  MatQuery::@ANN.KDTree _.ann =
     25    MatQuery::@ANN.KDTree::Default(0);
     26  MatQuery::@KNN.Neighbourhood _.ngbh =
     27    MatQuery::@KNN.Neighbourhood::Default(0);
     28
    2029  //////////////////////////////////////////////////////////////////////////////
    21   //Virtual methods
     30  //Methods
    2231  //////////////////////////////////////////////////////////////////////////////
    23   VMatrix get.radius(VMatrix Y.idx);
     32
     33  //////////////////////////////////////////////////////////////////////////////
     34  Real set.reference.points(VMatrix Y)
     35  //////////////////////////////////////////////////////////////////////////////
     36  {
     37    VMatrix _.Y := Y;
     38    Real _.H := VRows(_.Y);
     39    Real _.ann::set.data(VMat2Mat(_.Y));
     40    Real _.ann::update.search(_.ann::_.X,_.X.maxNeighbour,_.ngbh);
     41    VMatrix _.R :=
     42      Mat2VMat(Sqrt(SubCol(_.ngbh::_.distance2,[[_.X.maxNeighbour]])))*
     43      (1+Min(0,_.radius.margin));
     44    True
     45  };
     46
     47  ////////////////////////////////////////////////////////////////////////////
     48    VMatrix match.evaluable(VMatrix X)
     49  ////////////////////////////////////////////////////////////////////////////
     50  {
     51    MatQuery::@KNN.Neighbourhood ngbh =
     52      _.ann::search(VMat2Mat(X),1);   
     53    VMatrix dist = Mat2VMat(Sqrt(ngbh::_.distance2));
     54    VMatrix X.h = Mat2VMat(ngbh::_.neighbour);
     55    LE(dist,get.radius(X.h))$*
     56    LE(dist,Constant(VRows(dist),1,stress.maxDistance))
     57  };
     58
     59  //////////////////////////////////////////////////////////////////////////////
     60  VMatrix closest.reference.index(VMatrix X)
     61  //////////////////////////////////////////////////////////////////////////////
     62  {
     63    MatQuery::@KNN.Neighbourhood ngbh =
     64      _.ann::search(VMat2Mat(X),_.X.maxNeighbour);
     65    Mat2VMat(ngbh::_.neighbour)
     66  };
     67
     68  //////////////////////////////////////////////////////////////////////////////
     69  VMatrix get.radius(VMatrix Y.idx)
     70  //////////////////////////////////////////////////////////////////////////////
     71  {
     72    SubRow(_.R,VCol2Set(Y.idx))
     73  };
     74
     75  ///////////////////////////////////////////////////////////////////////////
     76    VMatrix generate.internal.points(Real m)
     77  ///////////////////////////////////////////////////////////////////////////
     78  {
     79    Text _MID = "[@DesignC2.Monomial.Spheric.MeshFree::generate.internal.points] ";
     80    WriteLn("TRACE "+_MID+"1 m="<<m);
     81    VMatrix h = Round(Rand(m,1,0.5,_.H+0.499999999));
     82    WriteLn("TRACE "+_MID+"2 h:\n"<<h);
     83    VMatrix y = SubRow(_.Y,VCol2Set(h));
     84    WriteLn("TRACE "+_MID+"3 y:\n"<<y);
     85    VMatrix v = Gaussian(m,_.n,0,1);
     86    WriteLn("TRACE "+_MID+"4 v:\n"<<v);
     87    VMatrix u = v*(VMatDat(MtMSqr(v),1,1)^-0.5);
     88    WriteLn("TRACE "+_MID+"5 u:\n"<<u);
     89    VMatrix rnd = get.radius(h)$*Rand(m,1,0,1);
     90    WriteLn("TRACE "+_MID+"5 rnd:\n"<<rnd);
     91    VMatrix r = Eye(m,m,0,rnd);
     92    WriteLn("TRACE "+_MID+"6 r:\n"<<r);
     93    y + r * u
     94  };
    2495
    2596  ///////////////////////////////////////////////////////////////////////////
    … …  
    2899  {
    29100    Real m = VRows(X.dif[1]);
    30     Set X.tao = For(1,_.X.maxNeighbour,VMatrix(Real i)
     101    Real numNeighbour = Card(X.h);
     102    Set X.tao = For(1,numNeighbour,VMatrix(Real i)
    31103    {
    32104      VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(_.n,1,1,1);
    33105      RPow(X.norm2,0.5)$/get.radius(X.h[i])
    34106    });
    35     Set X.tao2 = For(1,_.X.maxNeighbour,VMatrix(Real i)
     107    Set X.tao2 = For(1,numNeighbour,VMatrix(Real i)
    36108    {
    37109      RPow(X.tao[i],2)
    38110    });
    39     Set X.match = For(1,_.X.maxNeighbour,VMatrix(Real i)
     111    Set X.match = For(1,numNeighbour,VMatrix(Real i)
    40112    {
    41113      LE(X.tao[i],Rand(m,1,1,1))
    42114    });
    43     Set X.lambda = For(1,_.X.maxNeighbour,VMatrix(Real i)
     115    Set X.lambda = For(1,numNeighbour,VMatrix(Real i)
    44116    {
    45117      RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),4)
    … …  
    47119    VMatrix X.lambda.sum = SetSum(X.lambda);
    48120   
    49     For(1,_.X.maxNeighbour,VMatrix(Real i)
     121    For(1,numNeighbour,VMatrix(Real i)
    50122    {
    51123      X.lambda[i] $/ X.lambda.sum
    … …  
    57129  {
    58130    Real m = VRows(X.dif[1]);
    59     Set X.tao = For(1,_.X.maxNeighbour,VMatrix(Real i)
     131    Real numNeighbour = Card(X.h);
     132    Set X.tao = For(1,numNeighbour,VMatrix(Real i)
    60133    {
    61134      VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(_.n,1,1,1);
    62135      RPow(X.norm2,0.5)$/get.radius(X.h[i])
    63136    });
    64     Set X.tao2 = For(1,_.X.maxNeighbour,VMatrix(Real i)
     137    Set X.tao2 = For(1,numNeighbour,VMatrix(Real i)
    65138    {
    66139      RPow(X.tao[i],2)
    67140    });
    68     Set X.match = For(1,_.X.maxNeighbour,VMatrix(Real i)
     141    Set X.match = For(1,numNeighbour,VMatrix(Real i)
    69142    {
    70143      LE(X.tao[i],Rand(m,1,1,1))
    71144    });
    72     Set X.lambda = For(1,_.X.maxNeighbour,VMatrix(Real i)
     145    Set X.lambda = For(1,numNeighbour,VMatrix(Real i)
    73146    {
    74147      RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),4)
    75148    });
    76     Set X.lambda.der = For(1,_.X.maxNeighbour,VMatrix(Real i)
     149    Set X.lambda.der = For(1,numNeighbour,VMatrix(Real i)
    77150    {
    78151      RPow(X.match[i] $*
    … …  
    83156    VMatrix X.lambda.sum.2 = RPow(X.lambda.sum,2);
    84157    VMatrix X.lambda.der.sum = SetSum(X.lambda.der);
    85     For(1,_.X.maxNeighbour,VMatrix(Real i)
     158    For(1,numNeighbour,VMatrix(Real i)
    86159    {
    87160      (X.lambda.der[i]$*X.lambda.sum-X.lambda[i]$*X.lambda.der.sum)
  • tol_pkg/MulVarFunAprox/DesignC2.tol

    r43068ca r9002d5f  
    9393    VMatrix X.j=DifEq(1/(1-B),Rand(m,1,1,1));
    9494    WriteLn("TRACE "+_MID+"3 X.h:\n"<<X.h);
    95     Set X.h_ = For(1,_.X.maxNeighbour,VMatrix(Real i) { SubCol(X.h,[[i]]) });
     95    Real numNeighbour = VColumns(X.h);
     96    Set X.h_ = For(1,numNeighbour,VMatrix(Real i) { SubCol(X.h,[[i]]) });
    9697    WriteLn("TRACE "+_MID+"3.1");
    97     Set X.dif = For(1,_.X.maxNeighbour,VMatrix(Real i)
     98    Set X.dif = For(1,numNeighbour,VMatrix(Real i)
    9899    {
    99100      Set X.h.i = VCol2Set(X.h_[i]);
    … …  
    105106    VMatrix YnCum = DifEq(1/(1-B),_.Yn);
    106107    VMatrix YnCumB = Sub(SetCol([[0]])<<YnCum,1,1,_.H,1);
    107     Matrix QX.triplet = Group("ConcatRows", For(1,_.X.maxNeighbour,Matrix(Real i)
     108    Matrix QX.triplet = Group("ConcatRows", For(1,numNeighbour,Matrix(Real i)
    108109    {
    109110      VMatrix w.i = X.weight[i];
    … …  
    129130    Pack(Convert(Triplet(QX.triplet, m, _.N),"Cholmod.R.Sparse"))
    130131  })};
     132
    131133
    132134  //////////////////////////////////////////////////////////////////////////////
    … …  
    146148    VMatrix X.j=DifEq(1/(1-B),Rand(m,1,1,1));
    147149    WriteLn("TRACE "+_MID+"4");
    148     Set X.h_ = For(1,_.X.maxNeighbour,VMatrix(Real i) { SubCol(X.h,[[i]]) });
    149     Set X.dif = For(1,_.X.maxNeighbour,VMatrix(Real i)
     150    Real numNeighbour = VColumns(X.h);
     151    Set X.h_ = For(1,numNeighbour,VMatrix(Real i) { SubCol(X.h,[[i]]) });
     152    Set X.dif = For(1,numNeighbour,VMatrix(Real i)
    150153    {
    151154      Set X.h.i = VCol2Set(X.h_[i]);
    … …  
    158161    VMatrix YnCum = DifEq(1/(1-B),_.Yn);
    159162    VMatrix YnCumB = Sub(SetCol([[0]])<<YnCum,1,1,_.H,1);
    160     Matrix QX.triplet = Group("ConcatRows", For(1,_.X.maxNeighbour,Matrix(Real i)
     163    Matrix QX.triplet = Group("ConcatRows", For(1,numNeighbour,Matrix(Real i)
    161164    {
    162165      VMatrix w.i = X.weight[i];
    … …  
    360363    WriteLn("TRACE "+_MID+"6");
    361364    VMatrix _.QtQ := MtMSqr(_.Q);
    362     VMatrix _.LQ := CholeskiFactor(_.QtQ,"X",False,False);
     365    VMatrix _.LQ := CholeskiFactor(_.Q,"XtX");
     366/*
     367    VMatrix _.LQ := CholeskiFactor(_.QtQ,"X",False,True);
    363368    Real iter = 1;
    364369    Real lambda = 1.e-15;
    … …  
    366371    {
    367372      VMatrix _.QtQ := _.QtQ + Eye(_.N,_.N,0,lambda);
    368       VMatrix _.LQ := CholeskiFactor(_.QtQ,"X",False,False);
     373      VMatrix _.LQ := CholeskiFactor(_.QtQ,"X",False,True);
    369374      Real lambda := lambda * 2;
    370375      Real iter := iter+1
    371376    });
    372   //VMatrix _.LQ := CholeskiFactor(_.Q,"XtX");
     377*/
    373378    WriteLn("TRACE "+_MID+"7");
    374379    True
  • tol_pkg/MulVarFunAprox/test/test_0001/test.tol

    r43068ca r9002d5f  
    4242  MulVarFunAprox::@DesignC2.Monomial.Spheric.Grid::New(
    4343    VMatrix X,
    44     Real radius.margin = Sqrt(2)-1,
     44    Real radius.margin = Sqrt(2)-1+0.00001,
    4545    Real radius = 0.5,
    4646    Real do.build.border = False)};
    … …  
    268268");
    269269
    270 Real OSCmdWait("Rgui CMD BATCH --vanilla show.R show.R.log");
    271270/*
    272271Real numErr1 = Copy(NError);
  • tol_pkg/MulVarFunAprox/test/test_0002/test.tol

    r43068ca r9002d5f  
    3333  }))
    3434};
    35 VMatrix X = generate.nodal.points(500,2);
     35VMatrix X = generate.nodal.points(200,2);
    3636/* * /
    3737MulVarFunAprox::@DesignC2 design = {
    … …  
    4444    VMatrix X,
    4545    Real maxNeighbour = 4*VColumns(X),
     46    Real radius.margin = 0.0001;
    4647    Real stress.maxDistance_ = 5) };
    4748/* */
Note: See TracChangeset for help on using the changeset viewer.