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
ImprovedLocalSecantLipschitz.m
Go to the documentation of this file.
1 namespace error{
2 namespace lipfun{
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 
20  :public error.lipfun.Base {
43  public: /* ( setObservable ) */
44 
58  private: /* ( Transient ) */
59 
60  oldrs = "[]";
61 
62 
63  public:
64 
65  precomp = "[]";
66 
67 
68  public:
69 
70 
72  this = this@error.lipfun.Base(bellfcn);
73  this.registerProps(" UseCachedSecants ");
74  }
75 
76 
77  function copy = clone() {
78  copy = error.lipfun.ImprovedLocalSecantLipschitz(this.bellfcn);
79  /* copy = clone@error.lipfun.Base(this, copy); */
80  copy.UseCachedSecants= this.UseCachedSecants;
81  }
82 
83 
84  function prepareConstants() {
85  }
92  function ci = evaluate(di,C) {
93  b = this.bellfcn;
94  r0 = b.r0;
95  if isempty(this.oldrs) || any(isnan(this.oldrs)) || size(this.oldrs,2) ~= size(di,2)
96  this.oldrs= r0+.2*sign(r0-di);
97  end
98 
99  /* Consider C=Inf case separately for speed reasons */
100  if isinf(C)
101  if this.UseCachedSecants
102  rs = this.CachedModifiedNewton(di);
103  else
104  rs = b.ModifiedNewton(this.oldrs,di);
105  end
106  ci = abs(b.evaluateD1(rs));
107  this.oldrs= rs;
108  else
109  rs = ones(size(di))*r0;
110  update = abs(di-r0) < C;
111  /* Choose suitable starting conditions if no old rs vectors
112  * are available */
113  if any(update)
114  if this.UseCachedSecants
115  rs(update) = this.CachedModifiedNewton(di(update));
116  else
117  rs(update) = b.ModifiedNewton(this.oldrs(update),di(update));
118  end
119  this.oldrs(update) = rs(update);
120  end
121  left = di + C - rs < 0;
122  right = di - C - rs > 0;
123  center = ~left & ~right;
124  /* If C is too small we just take the derivative at this
125  * spot */
126  if C < sqrt(eps)
127  ci(left | right) = abs(b.evaluateD1(di(left | right)));
128  else
129  ci(left) = (b.evaluateScalar((di(left))) - b.evaluateScalar((di(left)+C))) / C;
130  ci(right) = (b.evaluateScalar((di(right)-C)) - b.evaluateScalar((di(right)))) / C;
131  end
132  ci(center) = abs(b.evaluateD1(rs(center)));
133  end
134  }
135 
136 
137  function precompMaxSecants(maxDistance,num) {
138  if this.UseCachedSecants
139  di = linspace(0,maxDistance,num);
140  start = this.bellfcn.r0+.2*sign(this.bellfcn.r0-di);
141  if KerMor.App.Verbose > 1
142  fprintf(" Precomputing %d max local secants for BellFunction(Gamma=%f,r0=%f) in range [0, %f] ..\n ",num,this.Gamma,this.x0,maxDistance);
143  end
144  rs = this.bellfcn.ModifiedNewton(start,di);
145  t = BinTree;
146  if KerMor.App.Verbose > 1
147  fprintf(" Building tree data structure..\n ");
148  end
149  t.Insert(di,rs);
150  this.precomp= t;
151  end
152  }
153 
154 
155  private:
156 
157 
158  function rs = CachedModifiedNewton(s) {
159  if ~isempty(this.precomp)
160  t = this.precomp;
161  [l,u] = t.FindClosest(s);
162  low = s < this.bellfcn.r0;
163  rs = zeros(size(y));
164  rs(low) = u(low);
165  rs(~low) = l(~low);
166  else
167  error(" When using cached secants the method precompMaxSecants has to be run first. ");
168  end
169  }
170 
171 
172 
173  public: /* ( Static ) */
174 
175 
176 
177 
178 };
179 }
180 }
181 
BinTree: A weighted binary tree.
Definition: BinTree.m:17
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
Base:
Definition: Base.m:19
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
function ci = evaluate(di, C)
Evaluates the local lipschitz estimation function.
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910