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
SVR.m
Go to the documentation of this file.
1 namespace demos{
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 SVR {
35  public: /* ( Static ) */
36 
37  static function PlotManagerpm = EpsLoss(double ep) {
38 
39  if nargin == 0
40  ep = .1;
41  end
42 
43  x = -5*ep:ep/10:5*ep;
44  lx = max(0, abs(x)-ep);
45  pm = PlotManager;
46  h = pm.nextPlot(" eps_loss ",...
47  sprintf(" \\epsilon-insensitive loss function for \\epsilon=%g ",ep),...
48  " value "," epsilon-norm ");
49  plot(h,x,zeros(size(x))," k-- ",x,lx," b ",[0 0+eps],[-ep/3 max(lx)]," black-- ");
50 
51  /* Create textbox */
52  annotation(gcf," textbox ",[0.4258 0.113 0.0461 0.07664],...
53  " String ",[" -\epsilon "],...
54  " FontWeight "," bold ",...
55  " FontSize ",20," LineStyle "," none ");
56 
57 
58  annotation(gcf," textbox ",[0.5858 0.1229 0.0394 0.06729],...
59  " String ",[" \epsilon "],...
60  " FontWeight "," bold ",...
61  " FontSize ",20," LineStyle "," none ");
62 
63  axis([x(1) x(end) -ep/3 max(lx)]);
64 
65  if nargout < 1
66  pm.done;
67  pm.LeaveOpen= true;
68  end
69  }
83  static function ScalarEpsSVR_SMO(integer version,PlotManager pm) {
84 
85  if nargin < 2
86  pm = PlotManager;
87  pm.LeaveOpen= true;
88  if nargin < 1
89  version = 2;
90  end
91  end
92 
93  x = -5:.1:5;
94 /* fx = sin(x)+.2*x; */
95  fx = sin(x-.5).*x;
96  fx = fx ./ max(abs(fx));
97 
98  svr = general.regression.ScalarEpsSVR_SMO;
99  svr.Version= version;
100  svr.Eps= .1;
101  svr.Lambda= 1/20;/* 1/20; % i.e. C=10 as in ScalarEpsSVR */
102 
103  svr.Vis= 1;
104 
105  kernel = kernels.GaussKernel(.8);
106  svr.K= kernel.evaluate(x,x);
107  kexp = kernels.KernelExpansion;
108  kexp.Kernel= kernel;
109  [ai, svidx] = svr.computeKernelCoefficients(fx,[]);
110  kexp.Centers.xi= x(:,svidx);
111  kexp.Ma= ai^t;
112  afx = kexp.evaluate(x);
113 
114  h = pm.nextPlot(" svr_smo ",sprintf(" It: %d, #SV=%d, eps=%f ",...
115  svr.LastIterations,length(svidx),svr.Eps)," x "," f(x) ");
116  demos.SVR.plotSVR(h, x, fx, afx, svr.Eps, svidx);
117  }
144 
145  ip.addParamValue('Version',2);
146  ip.addParamValue('Steps',8);
147  pmd = PlotManager(false,2,2);
148  pmd.LeaveOpen= true;
149  ip.addParamValue('PM',pmd);
150  ip.addParamValue('Gamma',.8);
151  ip.addParamValue('Eps',.1);
152  ip.parse(varargin[:]);
153  r = ip.Results;
154 
155  x = -5:.1:5;
156  fx = sin(x-.5).*x;
157  fx = fx ./ max(abs(fx));
158 
159  svr = general.regression.ScalarEpsSVR_SMO;
160  svr.Version= r.Version;
161  svr.Eps= r.Eps;
162  svr.Lambda= 1/20;
163  svr.Vis= 1;
164 
165  kernel = kernels.GaussKernel(r.Gamma);
166  svr.K= kernel.evaluate(x,x);
167  kexp = kernels.KernelExpansion;
168  kexp.Kernel= kernel;
169 
170  for l = 1:r.Steps
171  svr.MaxCount= l;
172 
173  [ai, svidx] = svr.computeKernelCoefficients(fx,[]);
174  kexp.Centers.xi= x(:,svidx);
175  kexp.Ma= ai^t;
176  afx = kexp.evaluate(x);
177 
178  h = r.PM.nextPlot(sprintf(" iter%d ",l),...
179  sprintf(" Iteration %d ",l)," x "," f(x) and approximation ");
180  demos.SVR.plotSVR(h, x, fx, afx, svr.Eps, svidx);
181  end
182  }
218  private: /* ( Static ) */
219 
220  static function plotSVR(h,colvec<double> x,fx,afx,eps,svidx) {
221  plot(h,x,fx," r ",x,[fx-eps; fx+eps]," r-- ");
222  hold(h," on ");
223  plot(h,x,afx," b ");
224  /* No need for eps-margin on approximation
225  * plot(h,x,[afx-eps; afx+eps],'b--'); */
226  skipped = setdiff(1:length(x),svidx);
227  plot(h,x(svidx),fx(svidx)," k. "," MarkerSize ",16);
228 /* plot(h,x(skipped),fx(skipped),'xr'); */
229  }
230 
231 
232 
233 };
234 }
235 
SVR: Support vector machine related KerMor demos.
Definition: SVR.m:18
static function ScalarEpsSVR_SMO(integer version,PlotManager pm)
Demonstrates the general.regression.ScalarEpsSVR_SMO class.
Definition: SVR.m:83
An integer value.
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
Definition: PlotManager.m:213
A variable number of input arguments.
function axes ax_handle = nextPlot(char tag,char caption,char xlab,char ylab,cell< char > leg_str,integer numsubplots)
Creates a new axis to plot in. Depending on the property tools.PlotMananger.Single this will either a...
Definition: PlotManager.m:365
static function ScalarEpsSVR_SMO_SingleSteps(varargin)
Demonstrates the general.regression.ScalarEpsSVR_SMO class.
Definition: SVR.m:143
static function PlotManager pm = EpsLoss(double ep)
Plots the epsilon-insensitive loss function for a given epsilon.
Definition: SVR.m:37