Changeset 972bf92 in tol


Ignore:
Timestamp:
Nov 27, 2009, 7:32:58 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
a62df64
Parents:
0f8f0fa
Message:

New classes @BaseC2FunRn2R.Map and @BaseC2FunRn2R.Concat to build transformed bases
Fixed some bugs in @BaseC2FunRn2R.Monomial

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MulVarFunAprox/MulVarFunAprox.tol

    r0f8f0fa r972bf92  
    5050  //array of points given as the rows of a matrix
    5151  VMatrix partial.derivative.2.v(Real k, VMatrix X, Real i, Real j)
     52};
     53
     54//////////////////////////////////////////////////////////////////////////////
     55Class @BaseC2FunRn2R.Map : @BaseC2FunRn2R
     56//////////////////////////////////////////////////////////////////////////////
     57{
     58  @BaseC2FunRn2R _.base;
     59  Set _.map;
     60
     61  Static Text _.autodoc.description = "Extracts a sub-base of a given base "
     62  "whose k-th basic function are given by _.map[k] basic function of "
     63  "_.base. Of course _.map cannot have repated indexes to ensure linear "
     64  "independence.";
     65
     66  ////////////////////////////////////////////////////////////////////////////
     67  Static Text _.autodoc.member.New = "Creates an instance of "
     68  "@BaseC2FunRn2R.Map on R^n with specified maximum degree.";
     69  Static @BaseC2FunRn2R.Map New(@BaseC2FunRn2R base, Set map)
     70  ////////////////////////////////////////////////////////////////////////////
     71  {
     72    @BaseC2FunRn2R.Map aux = [[
     73      Real _.n = base::_.n;
     74      Real _.K = Card(map);
     75      @BaseC2FunRn2R _.base = base;
     76      Set _.map = map   
     77  ]]};
     78  ////////////////////////////////////////////////////////////////////////////
     79  Static Text _.autodoc.member.function.r =
     80  "Evaluates the k-th basic function for a point x given as a row matrix";
     81  Real function.r(Real k, VMatrix x)
     82  ////////////////////////////////////////////////////////////////////////////
     83  {
     84    _.base::function.r(_.map[k], x)
     85  };
     86  ////////////////////////////////////////////////////////////////////////////
     87  Static Text _.autodoc.member.partial.derivative.1.r =
     88  "Evaluates the first partial derivative of k-th basic function for a " 
     89  "point x given as a row matrix";
     90  Real partial.derivative.1.r(Real k, VMatrix x, Real i)
     91  ////////////////////////////////////////////////////////////////////////////
     92  {
     93    partial.derivative.1.r(_.map[k], x, i)
     94  };
     95  ////////////////////////////////////////////////////////////////////////////
     96  Static Text _.autodoc.member.partial.derivative.2.r =
     97  "Evaluates the second partial derivative of k-th basic function for a "
     98  "point x given as a row matrix";
     99  Real partial.derivative.2.r(Real k, VMatrix x, Real i, Real j)
     100  ////////////////////////////////////////////////////////////////////////////
     101  {
     102    _.base::partial.derivative.2.r(_.map[k], x, i, j)
     103  };
     104
     105  //For efficience reasonsthe base has specific method for evaluation over
     106  //massive data stored in a matrix
     107
     108  ////////////////////////////////////////////////////////////////////////////
     109  Static Text _.autodoc.member.function.v =
     110  "Evaluates the k-th basic function for an "
     111  "array of points given as the rows of a matrix ";
     112  VMatrix function.v(Real k, VMatrix X)
     113  ////////////////////////////////////////////////////////////////////////////
     114  {
     115    _.base::function.v(_.map[k], X)
     116  };
     117  ////////////////////////////////////////////////////////////////////////////
     118  Static Text _.autodoc.member.partial.derivative.1.v =
     119  "Evaluates the first partial derivative of k-th basic function for an "
     120  "array of points given as the rows of a matrix";
     121  VMatrix partial.derivative.1.v(Real k, VMatrix X, Real i)
     122  ////////////////////////////////////////////////////////////////////////////
     123  {
     124    _.base::partial.derivative.1.v(_.map[k], X, i)
     125  };
     126  ////////////////////////////////////////////////////////////////////////////
     127  Static Text _.autodoc.member.partial.derivative.2.v =
     128  "Evaluates the second partial derivative of k-th basic function for an "
     129  "array of points given as the rows of a matrix";
     130  VMatrix partial.derivative.2.v(Real k, VMatrix X, Real i, Real j)
     131  ////////////////////////////////////////////////////////////////////////////
     132  {
     133    _.base::partial.derivative.2.v(_.map[k], X, i, j)
     134  }
     135};
     136
     137//////////////////////////////////////////////////////////////////////////////
     138Class @BaseC2FunRn2R.Concat : @BaseC2FunRn2R
     139//////////////////////////////////////////////////////////////////////////////
     140{
     141  Static Text _.autodoc.description = "Concats a set of linearly independent "
     142  "bases over the same domain vectorial space.";
     143
     144  Set _.base;   //Set of @BaseC2FunRn2R
     145
     146  //Auxiliar member to map concatenated bases
     147  Set _.map;
     148
     149  ////////////////////////////////////////////////////////////////////////////
     150  Static Text _.autodoc.member.New = "Creates an instance of "
     151  "@BaseC2FunRn2R.Concat on R^n with specified maximum degree.";
     152  Static @BaseC2FunRn2R.Concat New(Set base)
     153  ////////////////////////////////////////////////////////////////////////////
     154  {
     155    Real n = (base[1])::_.n;
     156    Set map = BinGroup("<<", For(1,Card(base),Set(Real h)
     157    {
     158      If((base[h])::_.n!=n,WriteLn("[@BaseC2FunRn2R.Concat::New] "
     159      "Cannot concat bases with different domain vectorial space dimension "
     160      <<n+"!="<<(base[h])::_.n),"E");
     161      For(1,(base[h])::_.K,Set(Real k)
     162      {
     163        [[h,k]]
     164      })
     165    }));
     166    @BaseC2FunRn2R.Concat aux = [[
     167      Real _.n = base::_.n;
     168      Real _.K = Card(map);
     169      Set _.base = base;
     170      Set _.map = map
     171  ]]};
     172  ////////////////////////////////////////////////////////////////////////////
     173  Static Text _.autodoc.member.function.r =
     174  "Evaluates the k-th basic function for a point x given as a row matrix";
     175  Real function.r(Real k, VMatrix x)
     176  ////////////////////////////////////////////////////////////////////////////
     177  {
     178    Set aux = _.map[k];
     179    (_.base[aux::h])::function.r(aux::k, x)
     180  };
     181  ////////////////////////////////////////////////////////////////////////////
     182  Static Text _.autodoc.member.partial.derivative.1.r =
     183  "Evaluates the first partial derivative of k-th basic function for a " 
     184  "point x given as a row matrix";
     185  Real partial.derivative.1.r(Real k, VMatrix x, Real i)
     186  ////////////////////////////////////////////////////////////////////////////
     187  {
     188    Set aux = _.map[k];
     189    (_.base[aux::h])::partial.derivative.1.r(aux::k, x, i)
     190  };
     191  ////////////////////////////////////////////////////////////////////////////
     192  Static Text _.autodoc.member.partial.derivative.2.r =
     193  "Evaluates the second partial derivative of k-th basic function for a "
     194  "point x given as a row matrix";
     195  Real partial.derivative.2.r(Real k, VMatrix x, Real i, Real j)
     196  ////////////////////////////////////////////////////////////////////////////
     197  {
     198    Set aux = _.map[k];
     199    (_.base[aux::h])::_.base::partial.derivative.2.r(aux::k, x, i, j)
     200  };
     201
     202  //For efficience reasonsthe base has specific method for evaluation over
     203  //massive data stored in a matrix
     204
     205  ////////////////////////////////////////////////////////////////////////////
     206  Static Text _.autodoc.member.function.v =
     207  "Evaluates the k-th basic function for an "
     208  "array of points given as the rows of a matrix ";
     209  VMatrix function.v(Real k, VMatrix X)
     210  ////////////////////////////////////////////////////////////////////////////
     211  {
     212    Set aux = _.map[k];
     213    (_.base[aux::h])::_.base::function.v(aux::k, X)
     214  };
     215  ////////////////////////////////////////////////////////////////////////////
     216  Static Text _.autodoc.member.partial.derivative.1.v =
     217  "Evaluates the first partial derivative of k-th basic function for an "
     218  "array of points given as the rows of a matrix";
     219  VMatrix partial.derivative.1.v(Real k, VMatrix X, Real i)
     220  ////////////////////////////////////////////////////////////////////////////
     221  {
     222    Set aux = _.map[k];
     223    (_.base[aux::h])::_.base::partial.derivative.1.v(aux::k, X, i)
     224  };
     225  ////////////////////////////////////////////////////////////////////////////
     226  Static Text _.autodoc.member.partial.derivative.2.v =
     227  "Evaluates the second partial derivative of k-th basic function for an "
     228  "array of points given as the rows of a matrix";
     229  VMatrix partial.derivative.2.v(Real k, VMatrix X, Real i, Real j)
     230  ////////////////////////////////////////////////////////////////////////////
     231  {
     232    Set aux = _.map[k];
     233    (_.base[aux::h])::_.base::partial.derivative.2.v(aux::k, X, i, j)
     234  }
    52235};
    53236
    … …  
    178361  ////////////////////////////////////////////////////////////////////////////
    179362  {
    180     BinGroup("$*", For(1,_.n, Real(Real i)
    181     {
    182       RPow(SubCol(x,[[i]]),_.degComb[k][i])
     363    BinGroup("$*", For(1,_.n, VMatrix(Real i)
     364    {
     365      RPow(SubCol(X,[[i]]),_.degComb[k][i])
    183366    }))
    184367  };
    … …  
    191374  {
    192375    Real d = _.degComb[k][i];
    193     If(d==0, 0,
    194     {
    195       (RPow(SubCol(x,[[i]]),d-1)*d) $*
    196       BinGroup("$*", EvalSet(_.range.der.1[i], Real(Real h)
    197       {
    198         RPow(SubCol(x,[[h]]),_.degComb[k][h])
    199       }))
     376    If(d==0, Rand(VRows(X),1,0,0),
     377    {
     378      VMatrix aux = (RPow(SubCol(X,[[i]]),d-1)*d);
     379      If(!Card(_.range.der.1[i]),aux,aux $*
     380      BinGroup("$*", EvalSet(_.range.der.1[i], VMatrix rd1(Real h)
     381      {
     382        RPow(SubCol(X,[[h]]),_.degComb[k][h])
     383      })))
    200384    })
    201385  };
    … …  
    210394    {
    211395      Real d = _.degComb[k][i];
    212       If(d<=1, 0,
    213       {
    214         (RPow(SubCol(x,[[h]]),d-2)*((d-1)*d)) $*
    215         BinGroup("$*", EvalSet(_.range.der.1[i], Real(Real h)
     396      If(d<=1, Rand(VRows(X),1,0,0),
     397      {
     398        VMatrix aux = (RPow(SubCol(X,[[i]]),d-2)*((d-1)*d));
     399        If(!Card(_.range.der.1[i]),aux,aux $*
     400        BinGroup("$*", EvalSet(_.range.der.1[i], VMatrix rd21(Real h)
    216401        {
    217           RPow(SubCol(x,[[h]]),_.degComb[k][h])
    218         }))
     402          RPow(SubCol(X,[[h]]),_.degComb[k][h])
     403        })))
    219404      })
    220405    },
    … …  
    222407      Real d.i = _.degComb[k][i];
    223408      Real d.j = _.degComb[k][j];
    224       If(Or(d.i==0, d.j==0), 0,
    225       {
    226         (RPow(SubCol(x,[[i]]),d.i-1)*d.i) $*
    227         (RPow(SubCol(x,[[j]]),d.j-1)*d.j) $*
    228         BinGroup("$*", (_.range.der.2[i][j], Real(Real h)
     409      If(Or(d.i==0, d.j==0), Rand(VRows(X),1,0,0),
     410      {
     411        VMatrix aux = (RPow(SubCol(X,[[i]]),d.i-1)*d.i) $*
     412                      (RPow(SubCol(X,[[j]]),d.j-1)*d.j);
     413        If(!Card(_.range.der.2[i][j]),aux,aux $*
     414        BinGroup("$*", EvalSet(_.range.der.2[i][j], VMatrix rd22(Real h)
    229415        {
    230           RPow(SubCol(x,[[h]]),_.degComb[k][h])
    231         }))
     416          RPow(SubCol(X,[[h]]),_.degComb[k][h])
     417        })))
    232418      })
    233419    })
Note: See TracChangeset for help on using the changeset viewer.