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
BaseQPSVR.m
Go to the documentation of this file.
1 namespace general{
2 namespace regression{
3 
4 
5 /* (Autoinserted by mtoc++)
6  * This source code has been filtered by the mtoc++ executable,
7  * which generates code that can be processed by the doxygen documentation tool.
8  *
9  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
10  * Except for the comments, the function bodies of your M-file functions are untouched.
11  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
12  * attached source files that are highly readable by humans.
13  *
14  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
15  * the correct locations in the source code browser.
16  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
17  */
18 
19 class BaseQPSVR
39  public: /* ( setObservable ) */
40 
59  QuadProgOpts = optimset("'Display','off','Algorithm','active-set'");
75  public: /* ( setObservable ) */
76 
78  this = this@general.regression.BaseScalarSVR;
79 
80  this.registerProps(" MaxIterations "," QuadProgOpts ");
81  }
88  function copy = clone(copy) {
89  if nargin == 1
90  error(" Cannot call clone without subclass argument. ");
91  end
92  copy = clone@general.regression.BaseScalarSVR(this, copy);
93  copy.MaxIterations= this.MaxIterations;
94  copy.QuadProgOpts= this.QuadProgOpts;
95  }
96 
97 
98  protected: /* ( setObservable ) */
99 
100  function [p , d , info ] = solve(matrix Q,colvec c,colvec lb,colvec ub,matrix A,matrix Alb,matrix Aub,x0) {
101 
102  /* Check for MaxIterations */
103  if KerMor.App.Verbose > 0
104  it = 100*(size(Q,1)+size(A,1));
105  if KerMor.App.Verbose > 3 && this.MaxIterations < it
106  fprintf(" BaseQPSVR: MaxIterations of %d smaller than recommended value %d.\n ",this.MaxIterations,it);
107  end
108  end
109 
110  if nargin < 9
111  x0 = [];
112  end
113 
114  s = tic;
115  /* Call internal solver algorithm (currently: only matlab's quadprog) */
116  [p,d,cflag,info] = this.internal_solve(Q,c,lb,ub,A,Alb,Aub,x0);
117 
118  /* Adds a CompTime field */
119  info.CompTime= toc(s);
120  info.NumVariables= size(Q,1);
121  info.NumConstraints= size(A,1);
122 
123  /* Evaluate */
124  if ~cflag
125  disp(info);
126  if isfield(info," message ")
127  fprintf(" Message: %s\n ",info.message);
128  end
129  m = MException(" BaseQPSVR:notconverged "," quadprog solver did not converge. ");
130  m.throw;
131  end
132 
133  /* Verbose output */
134  if KerMor.App.Verbose > 2
135  fprintf(" QP-SVR finished after %d/%d Iterations and %f seconds. Info:\n ",info.Iterations,this.MaxIterations, info.CompTime);
136  disp(info);
137  end
138  }
174  private: /* ( setObservable ) */
175 
176  function [p , d , cflag , info ] = internal_solve(Q,c,lb,ub,A,lbA,ubA,x0) {
177 
178  /* Problem setup */
179  prog.H= Q;
180  prog.f= c;
181 
182  /* Bounds */
183  if ~isempty(A)
184  /* Convert to equality and inequality bounds for this
185  * interface (quadprog) */
186  eq = abs(lbA-ubA) < sqrt(eps);
187  if any(eq)
188  prog.Aeq= A(eq,:);
189  prog.beq= lbA(eq);
190  end
191  if any(~eq)
192  prog.Aineq= A(~eq,:);
193  prog.bineq= ubA(~eq,:);
194  end
195  end
196  prog.lb= lb;
197  prog.ub= ub;
198 
199  /* Set starting point if given */
200  if nargin == 9
201  prog.x0= x0;
202  end
203 
204  /* Further options */
205  opts = this.QuadProgOpts;
206  if ~isempty(this.MaxIterations)
207  opts = optimset(opts," MaxIter ",this.MaxIterations);
208  end
209  prog.options= opts;
210  prog.solver= " quadprog ";
211 
212  /* Solve QP */
213  [p, ~, exitflag, out, la] = quadprog(prog);
214 
215  /* CARE! The -la.eqlin is subject to investigation and has to be
216  * specified as soon as a suitable QP solver interface is
217  * fixed/found */
218  d = [la.lower + la.upper; -la.eqlin; la.ineqlin];
219  cflag = exitflag == 1;
220  info = out;
221  info.exitflag= exitflag;
222  info.Iterations= out.iterations; /* bummer! */
223 
224  }
236 };
237 }
238 }
239 
integer MaxIterations
The maximum number of iterations.
Definition: BaseQPSVR.m:41
function [ p , d , info ] = solve(matrix Q,colvec c,colvec lb,colvec ub,matrix A,matrix Alb,matrix Aub, x0)
Solves the given quadratic problem according to the subclasses' algorithm.
Definition: BaseQPSVR.m:100
A matlab matrix.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
An integer value.
function copy = clone(copy)
The interface method with returns a copy of the current class instance.
Definition: BaseQPSVR.m:88
BaseQPSVR: SVR variant that is solved using quadratic programs.
Definition: BaseQPSVR.m:19
QuadProgOpts
Options for quadprog-solver.
Definition: BaseQPSVR.m:59
function bool = eq(B)
Checks equality of two KerMor objects.
Definition: KerMorObject.m:81
A matlab column vector.
disp
Handle object disp method which is called by the display method. See the MATLAB disp function...
SCALARSVR Scalar support vector regression.
Definition: BaseScalarSVR.m:19
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
BaseQPSVR()
LargeScale,off, interior-point-convex, trust-region-reflective
Definition: BaseQPSVR.m:77