source: tol/tol_pkg/FunRn2R/BaseC2.LinComb.tol @ 17d3fef

1941-docker-image-to-testdevel
Last change on this file since 17d3fef was eddd23a, checked in by Víctor de Buen <vdebuen@…>, 17 years ago

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

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/* -*- mode: C++ -*- */
2//////////////////////////////////////////////////////////////////////////////
3// FILE   : BaseC2.LinComb.tol
4// PURPOSE: Defines class @BaseC2.LinComb
5//////////////////////////////////////////////////////////////////////////////
6
7//////////////////////////////////////////////////////////////////////////////
8Text _.autodoc.member.BaseC2.LinComb = "Defines a new base B2 of "
9"order K2 as a linear combination B2=B1*V of functions of a previous base "
10"B1 of order K1>=K2. The matrix of change V must have rank K2 to ensure "
11"linear independence.";
12Class @BaseC2.LinComb : @BaseC2.Cache
13//////////////////////////////////////////////////////////////////////////////
14{
15  @BaseC2 _.base;
16  VMatrix _.V;
17
18  ////////////////////////////////////////////////////////////////////////////
19  Static Text _.autodoc.member.New = "Creates an instance B2 of "
20  "@BaseC2.LinComb as B2 = B1*V";
21  Static @BaseC2.LinComb New(@BaseC2 B1, VMatrix V)
22  ////////////////////////////////////////////////////////////////////////////
23  {
24    Real n = B1::_.n;
25   
26    @BaseC2.LinComb aux = [[
27      Real _.n = B1::_.n;
28      Real _.K = VColumns(V);
29      @BaseC2 _.base = base;
30      VMatrix _.V = V
31  ]]};
32
33  ////////////////////////////////////////////////////////////////////////////
34  Static Text _.autodoc.member.Compact = "Creates an instance of "
35  "@BaseC2.LinComb that is close to be orthonormal and has at least "
36  "the specified ratio of information of original base";
37  Static @BaseC2.LinComb Compact(
38    @BaseC2 base,
39    Real informationRatio)
40  ////////////////////////////////////////////////////////////////////////////
41  {
42    Real K1 = base::_.K;
43
44    VMatrix u = Rand(K1*10, K1, -1, 1);
45
46    VMatrix Pu = Group("ConcatColumns", For(1, K1, VMatrix(Real k)
47    {
48      base::function.v(k,u)
49    }));
50
51    Set Pu.svd = SVD(VMat2Mat(Pu));
52
53    Matrix Pu.eigenvalue = RPow(Tra(SubDiag(Pu.svd[2],0)),1);
54    Matrix Pu.eigenvalueCum =
55    {
56       Matrix aux = DifEq(1/(1-B),Pu.eigenvalue);
57       aux*(1/MatSum(Pu.eigenvalue))
58    };
59    Matrix ratio = Rand(K1,1,informationRatio,informationRatio);
60    Real K.new = MatSum(LE(Pu.eigenvalueCum,ratio));
61    VMatrix V = Mat2VMat(SubCol(Pu.svd[3],Range(1,K.new,1)));
62    New(base, V)
63  };
64
65  ////////////////////////////////////////////////////////////////////////////
66  Real _build.cache(VMatrix X, Real order)
67  ////////////////////////////////////////////////////////////////////////////
68  {
69    Real _.base::upgrade.cache(X,order);
70    VMatrix If(order>=0, { _.function :=
71      _.base::function.m(X)*_.V
72    });
73    Set If(order>=1, { _.partial.derivative.1 :=
74      For(1, _.n, VMatrix(Real i)
75      {
76        _.base::partial.derivative.1.m(X,i)*_.V
77      })
78    });
79    Set If(order>=2, { _.partial.derivative.2 :=
80      For(1, _.n, Set(Real i)
81      {
82        For(1, i, VMatrix(Real j)
83        {
84          _.base::partial.derivative.2.m(X,i,j)*_.V
85        })
86      })
87    });
88    True
89  }
90
91};
Note: See TracBrowser for help on using the repository browser.