KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Wendland.m
Go to the documentation of this file.
1 namespace kernels{
2 
3 
4 /* (Autoinserted by mtoc++)
5  * This source code has been filtered by the mtoc++ executable,
6  * which generates code that can be processed by the doxygen documentation tool.
7  *
8  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
9  * Except for the comments, the function bodies of your M-file functions are untouched.
10  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
11  * attached source files that are highly readable by humans.
12  *
13  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
14  * the correct locations in the source code browser.
15  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
16  */
17 
18 class Wendland
19  :public kernels.ARBFKernel {
38  public: /* ( Dependent ) */
39 
40  d;
51  k;
62  private:
63 
64  fd = 1;
65 
66  fk = 0;
67 
68  expo;
69 
70  co;
71 
72  polystr;
73 
74  polyfun;
75 
76  polystrD1 = {" \
77  '\@(r)(l+1)' \
78  '\@(r)2*(l^2+4*l+3)*r/3+(l+2)' \
79  '\@(r)(3*(l^3+9*l^2+23*l+15)*r.^2 + 2*(6*l^2+36*l+45)*r)/15+(l+3)'"};
80 
81  polyfunD1;
82 
83 
84  public:
85 
86  Wendland() {
87  this.polystr= [...
88  " @(r)(l+1)*r+1 " ...
89  " @(r)(l^2+4*l+3)*r.^2/3+(l+2)*r+1 " ...
90  " @(r)((l^3+9*l^2+23*l+15)*r.^3 + (6*l^2+36*l+45)*r.^2)/15+(l+3)*r+1 "];
91  this.updateCoeffs;
92  }
93 
94 
95  function Kxy = evaluate(colvec<double> x,matrix<double> y) {
96  r = sqrt(this.getSqDiffNorm(x, y))/this.Gamma;
97  rp = max(1-r, 0);
98  p = 1;
99  if (this.fk > 0)
100  p = this.polyfun(r);
101  end
102  Kxy=(rp.^this.expo).*p;
103  }
104 
105 
106  function Kxy = evaluateScalar(r) {
107  error(" not implemented ");
108 /* rp = max(1-r,0);
109  * %rp = (1-r).*(r <= 1);
110  *
111  * p = 1;
112  * if (this.fk > 0)
113  * p = this.polyfun(r);
114  * end
115  * Kxy=(rp.^this.expo).*p; */
116  }
117 
118 
119 
120  function Nabla = getNabla(colvec<double> x,matrix<double> y) {
121  if ~isempty(this.fP)
122  error(" Not yet implemented correctly. ");
123  end
124  r = sqrt(this.getSqDiffNorm(x, y))/this.Gamma;
125  rp = max(1-r, 0);
126  p = 1;
127  dp = 0;
128  if (this.fk > 0)
129  p = this.polyfun(r);
130  dp = this.polyfunD1(r);
131  end
132  hlp = (-this.expo*(rp.^(this.expo-1)).*p + (rp.^this.expo).*dp)./(r*this.Gamma^2);
133  /* For exact center matches r=0, so we would have inf/-infs */
134  hlp(~isfinite(hlp)) = 0;
135  Nabla = bsxfun(@times,hlp,bsxfun(@minus,x,y));
136  }
147  function dx = evaluateD1(r) {
148  error(" not implemented ");
149  end
150 
151  function ddx = evaluateD2(this, r)
152  /* Method for second derivative evaluation */
153  error(" not implemented ");
154  end
155 
156  /* Returns the global lipschitz constant of this kernel.
157  *
158  * Exprimental state as not implemented & checked for all kernels. */
159  function c = getGlobalLipschitz(this)
160  error(" not implemented ");
161  end
162 
163  function copy = clone(this)
164  copy = clone@kernels.ARBFKernel(this, kernels.Wendland);
165  /* Triggers update of coeffs */
166  copy.d= this.fd;
167  copy.k= this.fk;
168  end
169  end
170 
171  methods(Access=private)
172  function updateCoeffs(this)
173  /* calculates coefficients and exponent for polynomial
174  * part p_{d,k}(r) of the Wendland kernel function. */
175  l = floor(this.fd/2) + this.fk + 1;
176  this.expo= l + this.fk;
177  this.polyfun= [];
178  if (this.fk > 0)
179  this.polyfun= eval(this.polystr[this.fk]);
180  this.polyfunD1= eval(this.polystrD1[this.fk]);
181  end
182  end
183  end
184 
185  /* % Getter & Setter */
186  methods
187  function set.k(this, value)
188  if value < 0 || value > 3
189  error(" Only k values in [0,3] are allowed ");
190  elseif round(value) ~= value
191  error(" Only the k values 0,1,2,3 are allowed ");
192  end
193  this.fk= value;
194  this.updateCoeffs;
195  end
196 
197  function set.d(this, value)
198  if round(value) ~= value
199  error(" The dimension must be an integer ");
200  end
201  this.fd= value;
202  this.updateCoeffs;
203  end
204 
205  function v = get.d(this)
206  v = this.fd;
207  end
208 
209  function v = get.k(this)
210  v = this.fk;
211  end
212  end
213 
214  methods(Static)
215  function res = test_WendlandKernel(pm)
216  if nargin < 1
217  pm = PlotManager(false,3,3);
218  pm.LeaveOpen= true;
219  end
220  c = 0;
221  x = (-1.2:.01:1.2)+c;
222  [X,Y] = meshgrid(x);
223  x2 = [X(:)" ; Y(:) "];
224  k = kernels.Wendland;
225  kexp = kernels.KernelExpansion;
226  kexp.Kernel= k;
227  kexp.Centers.xi= c;
228  kexp.Ma= 1;
229  conf = Utils.createCombinations([1 2 3 4 5],[0 1 2 3]);
230  for n = 1:length(conf)
231  k.d= conf(1,n);
232  k.k= conf(2,n);
233  tag = sprintf(" w_1d_d%d_k%d ",k.d,k.k);
234  h = pm.nextPlot(tag,sprintf(" Wendland kernel with d=%d,k=%d on 1D data ",k.d,k.k));
235  plot(h,x,kexp.evaluate(x));
236  end
237  kexp.Centers.xi= [c; c];
238  for n = 1:length(conf)
239  k.d= conf(1,n);
240  k.k= conf(2,n);
241  tag = sprintf(" w_2d_d%d_k%d ",k.d,k.k);
242  h = pm.nextPlot(tag,sprintf(" Wendland kernel with d=%d,k=%d on 2D data ",k.d,k.k));
243  surf(h,X,Y,reshape(kexp.evaluate(x2),length(x),[])," EdgeColor "," none ");
244  end
245  if nargin < 1
246  pm.done;
247  end
248  res = true;
249  end
250  end
251 
252  methods(Static,Access=protected)
253  function this = loadobj(this)
254  this = loadobj@kernels.ARBFKernel(this);
255  this.updateCoeffs;
256  end
257  end
258 end
259  }
267 };
Collection of generally useful functions.
Definition: Utils.m:17
An integer value.
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
#define X(i, j)
#define Y(i, j)
Abstract class for radial basis function / rotation- and translation invariant kernels.
Definition: ARBFKernel.m:18