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
CombinationKernel.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 
19  :public kernels.BaseKernel {
27  public: /* ( setObservable ) */
28 
29  CombOp = @("a,b")a.*b;
48  private:
49 
50  Kernels = {""};
59  Weights = "[]";
60 
61 
62  public:
63 
64 
66  this = this@kernels.BaseKernel;
67  this.registerProps(" CombOp ");
68  }
69 
70 
71  function K = evaluate(colvec<double> x,varargin) {
72  if isempty(this.Kernels)
73  error(" No Kernels here to combine. Use addKernel for setup. ");
74  end
75  K = this.Weights(1)*this.Kernels[1].evaluate(x,varargin[:]);
76  for n = 2:length(this.Kernels)
77  K = this.CombOp(K, this.Weights(n)*this.Kernels[n].evaluate(x,varargin[:]));
78  end
79  }
80 
81 
82  function c = getGlobalLipschitz() {
83  error(" Not implemented yet ");
84  }
92  function Nabla = getNabla(colvec<double> x,matrix<double> y) {
93  error(" Not implemented yet ");
94  }
105  function this = addKernel(kernel,weight) {
106  if nargin == 2
107  weight = 1;
108  end
109  if ~isa(kernel," kernels.BaseKernel ")
110  error(" kernel param must be a kernels.BaseKernel! ");
111  end
112  this.Kernels[end+1] = kernel;
113  this.Weights(end+1) = weight;
114  }
115 
116 
117  public: /* ( Static ) */
118 
119  static function test_CombinationKernels() {
120  k1 = kernels.CombinationKernel;
121  k1.addKernel(kernels.GaussKernel(.7));
122  k1.addKernel(kernels.GaussKernel(.5));
123  /* k1.addKernel(kernels.PolyKernel(3),3); */
124  k1.addKernel(kernels.PolyKernel(2),2);
125  k1.CombOp= @(a,b)a.*b;
126  k2 = kernels.CombinationKernel;
127  k2.addKernel(kernels.LinearKernel,4);
128  k2.addKernel(kernels.PolyKernel(2));
129  k2.CombOp= @(a,b)a+b;
130  k = kernels.CombinationKernel;
131  k.addKernel(k1);
132  k.addKernel(k2);
133 
134  x = -1:.05:1;
135  fx = sinc(x);
136 
137  svr = general.regression.ScalarEpsSVR;
138  svr.Eps= .3;
139  svr.Lambda= 1/4;
140  svr.K= k.evaluate(x,x);
141 
142  figure(1);
143  plot(x,fx," r ",x,[fx-svr.Eps; fx+svr.Eps]," r-- ");
144 
145  [ai,svidx] = svr.computeKernelCoefficients(fx,[]);
146  sv = x(svidx);
147  svfun = @(x)ai^t * k.evaluate(sv,x);
148 
149  fsvr = svfun(x);
150 
151  hold on;
152 
153  /* Plot approximated function */
154  plot(x,fsvr," b ",x,[fsvr-svr.Eps; fsvr+svr.Eps]," b-- ");
155  skipped = setdiff(1:length(x),svidx);
156  plot(sv,fx(svidx)," .r ",x(skipped),fx(skipped)," xr ");
157 
158  hold off;
159  }
160 
161 
162 
163 };
164 }
165 
166 
CombOp
The combination operation for each kernel.
function c = getGlobalLipschitz()
function Nabla = getNabla(colvec< double > x,matrix< double > y)
SUMKERNEL Summary of this class goes here Detailed explanation goes here.
A variable number of input arguments.
static function test_CombinationKernels()
function this = addKernel(kernel, weight)
function K = evaluate(colvec< double > x, varargin)
Base class for all KerMor Kernels.
Definition: BaseKernel.m:18