43 bfun = kernels.GaussKernel(2);
46 r0 = bfun.
r0; rm = bfun.
rm;
56 r = linspace(0,maxR,70);
59 alls = [.2*r0 1.5*rm];
65 pm.SaveFormats= [
" eps "];
69 h = pm.nextPlot(sprintf(
" secant_demo_%d ",
k),...
70 sprintf(
" Maximum secant gradient selection for bell functions, s=%f, rs=%f ",s,rs(
k)));
73 plot(h,r,f(r),
" r ",
" LineWidth ",lw);
78 plot(h,[0 maxR],f(s) + drs(
k)*[s (s-maxR)],
" b-- ",
" LineWidth ",lw);
82 plot(h,[r0 r0],[0 f(r0)],
" blacks ",
" MarkerSize ",6,
" MarkerFaceColor ",
" black ");
83 text(r0,-yoff,
" r_0 ",
" FontSize ",fs,
" Parent ",h);
84 text(r0+xoff,f(r0)+yoff,
" \phi(r_0) ",
" FontSize ",fs,
" Parent ",h);
86 plot(h,[rm rm],[0 f(rm)],
" bs ",
" MarkerSize ",6,
" MarkerFaceColor ",
" blue ");
87 text(rm,-yoff,
" r_m ",
" FontSize ",fs,
" Parent ",h);
88 text(rm+xoff,f(rm)+yoff,
" \phi(r_m) ",
" FontSize ",fs,
" Parent ",h);
90 plot(h,[s s],[0 f(s)],
" ro ",
" MarkerSize ",6,
" MarkerFaceColor ",
" red ");
91 text(s,-yoff,
" s ",
" FontSize ",fs,
" Parent ",h);
92 text(s+xoff,f(s)+yoff,
" \phi(s) ",
" FontSize ",fs,
" Parent ",h);
94 plot(h,[rs(
k) rs(
k)],[0 f(rs(
k))],
" mo ",
" MarkerSize ",6,
" MarkerFaceColor ",
" magenta ");
95 text(rs(
k),-yoff,
" r_s ",
" FontSize ",fs,
" Parent ",h);
96 text(rs(
k)+xoff,f(rs(
k))+yoff,
" \phi(r_s) ",
" FontSize ",fs,
" Parent ",h);
98 plot(h,r,0,
" black ");
100 axis(h,[0 maxR -.5 f(r0)+abs(df(r0))*r0]);
102 lh = legend(h,
" \phi ",
" \phi(r_s) + \phi "" (r_s)(x-r_s) ");
104 set(lh,
" FontSize ",fs);
134 b = kernels.GaussKernel(Gamma);
135 r0 = b.r0; rm = b.rm;
136 lfun = error.lipfun.ImprovedLocalSecantLipschitz(b);
137 b.NewtonTolerance= 1e-3;
138 lfun.prepareConstants;
144 r = linspace(0,maxR,70);
145 r =
union(r,[r0,rm]);
147 rstart = repmat(r0/2,1,size(r,2));
148 rss = b.ModifiedNewton(rstart,r);
150 f = @b.evaluateScalar;
165 n(1,1:m) = b.evaluateD1(0) - (b.evaluateScalar(0)-b.evaluateScalar(s))./(eps-s);
166 n(2,1:m) = b.evaluateD1(r0) - (b.evaluateScalar(r0)-b.evaluateScalar(s))./(b.r0-s+eps);
167 n(3,1:m) = b.evaluateD1(rm) - (b.evaluateScalar(rm)-b.evaluateScalar(s))./(b.rm-s+eps);
170 dn(1,1:m) = b.evaluateD2(0) - n(1,:)./-s;
171 dn(1,isnan(dn(1,:))) = b.evaluateD2(0)/2;
172 dn(2,1:m) = b.evaluateD2(r0) - n(2,:)./(r0-s);
173 dn(2,isinf(dn(2,:))) = 0;
175 dn(3,1:m) = b.evaluateD2(rm) - n(3,:)./(rm-s);
176 dn(3,isinf(dn(3,:))) = b.evaluateD2(rm)/2;
179 [opt,~,inner,l0,gxr] = b.optFun(r,repmat(s,1,size(r,2)),n,dn);
180 std = ~inner & ~l0 & ~gxr;
183 plot(r,f(r),
" r ",r,abs(df(r)),
" m ",
" LineWidth ",lw);
185 st(1:2) = [
" \phi ",
" |\phi "" | "];
191 plot(r,abs(drf),
" g ",
" LineWidth ",lw);
192 st[end+1] =
" |\phi "" (r_s)| = |S_s(r_s))| \forall s ";
195 plot([0 maxR],f(s) + drf(
k)*[s (s-maxR)],
" k-- ",
" LineWidth ",lw);
196 st[end+1] =
" \phi(r_s) + \phi "" (r_s)(x-r_s) ";
199 plot(r(std),opt(std),
" b ",
" LineWidth ",lw);
200 st[end+1] =
" n(r) ";
203 plot(r(inner),opt(inner),
" b-- ",
" LineWidth ",lw);
204 st[end+1] =
" c(r_0)(r+d(r_0))^2 ";
207 plot(r(l0),opt(l0),
" b-. ",
" LineWidth ",lw);
208 st[end+1] =
" c(0)(r+d(0))^2 ";
211 plot(r(gxr),opt(gxr),
" b-. ",
" LineWidth ",lw);
212 st[end+1] =
" c(r_m)(r+d(r_m))^2 ";
214 plot([rss(
k) rss(
k)],[f(rss(
k)) abs(drf(
k))],
" --black ",
" LineWidth ",lw);
216 plot([rss(
k) s],[abs(drf(
k)) abs(drf(
k))],
" --black ",
" LineWidth ",lw);
218 st[end+1] =
" \phi(r_s) <-> d\phi(rs) = |S_s(r_s)| ";
221 off = .04; off2 = .07;
222 plot([r0 r0],[0 f(r0)],
" blacks ",
" MarkerSize ",6,
" MarkerFaceColor ",
" black ");
223 text(r0+off,f(r0)+off,
" \phi(r_0) ",
" FontSize ",fs);
224 text(r0,-off2,
" r_0 ",
" FontSize ",fs);
225 plot([rm rm],[0 f(rm)],
" bs ",
" MarkerSize ",6,
" MarkerFaceColor ",
" blue ");
226 text(rm+off,f(rm)+off,
" \phi(r_m) ",
" FontSize ",fs);
227 text(rm,-off2,
" r_m ",
" FontSize ",fs);
228 plot([s s],[0 f(s)],
" ro ",
" MarkerSize ",6,
" MarkerFaceColor ",
" red ");
229 text(s+off,f(s)+off,
" \phi(s) ",
" FontSize ",fs);
230 text(s,-off2,
" s ",
" FontSize ",fs);
231 plot([rss(
k) rss(
k)],[0 f(rss(
k))],
" mo ",
" MarkerSize ",6,
" MarkerFaceColor ",
" magenta ");
232 text(rss(
k)+off,f(rss(
k))+off,
" \phi(r_s) ",
" FontSize ",fs);
233 text(rss(
k),-off2,
" r_s ",
" FontSize ",fs);
239 title(sprintf(
" Maximum secant gradient r_s=%g for s=%g ",rss(
k),s));
241 axis([0 maxR -.5 f(r0)+abs(df(r0))*r0]);
282 bfun = kernels.GaussKernel(b);
284 f = @(x)bfun.evaluateScalar(x);
285 df = @(x)bfun.evaluateD1(x);
286 ddf = @(x)bfun.evaluateD2(x);
296 maxder = ones(size(x))*abs(df(bfun.r0));
299 minder = zeros(size(x));
300 maxd = zeros(size(x));
307 LGL(i) = abs(df(d-C));
308 LSE(i) = (f(d-C) - f(d)) / C;
309 elseif d + C - maxR < 0
310 LGL(i) = abs(df(d+C));
311 LSE(i) = (f(d) - f(d+C)) / C;
313 xfeat = bfun.ModifiedNewton(bfun.r0/2,d);
315 LSE(i) = (f(d) - f(d+C)) / C;
316 elseif d - C - xfeat > 0
317 LSE(i) = (f(d-C) - f(d)) / C;
319 LSE(i) = abs(df(xfeat));
343 minder(i) = max(abs(fx(idx) - exp(-x(i).^2/b)) ./ di(idx));
347 maxd(i) = (fx(i)-exp(-x0.^2/b))/d;
351 ph = plot(x,f(x),
" r ",x,abs(df(x)),
" r-- ",x,LGL,
" b ",x,LSE,
" g ");
352 set(ph,
" LineWidth ",2);
354 title(sprintf(
" C=%f ",C));
356 skip = round(1/(3*dt));
357 plot(x(1:skip:end),minder(1:skip:end),
" m^ ",
" MarkerSize ",6);
358 legend(
" Gaussian ",
" Abs. Gaussian derivative ",...
359 " Local Gradient estimate (LGL) ",
" Local secant estimate (LSL) ",...
360 " Minimal Lipschitz constant ");
363 plot([x0-C x0-C+eps], [0 1],
" black-- ",[x0 x0+eps], [0 1],
" black ",[x0+C x0+C+eps], [0 1],
" black-- ");
367 plot(maxR,bfun.evaluateScalar(maxR),
" r. ",
" MarkerSize ",15);
function rtmp = ModifiedNewton(rstart, s)
static function PlotManager pm = SecantGradientPlots(kernels.BellFunction bfun)
Produces the demo images for maximum secant gradient positions.
BELLFUNCTION Summary of this class goes here Detailed explanation goes here.
static function NewtonPenalty(double Gamma)
Demonstrates the error estimator penalized newton function and maximum secant gradients.
rm
The maximum ("right") value for any .
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
static function LocalLipschitzDemo(x0, C)
ERRORESTDEMO Demo for the monotone radial basis functions error estimator.
r0
Point of maximum first derivative on scalar evaluation.
virtual function phir = evaluateScalar(matrix< double > r)
Allows the evaluation of the function for scalar directly.
BellFunctions: Demos regarding the Bell function local Lipschitz estimations.
virtual function dr = evaluateD1()
Method for first derivative evaluation.