-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewtonRhapson.m
More file actions
34 lines (30 loc) · 1.08 KB
/
newtonRhapson.m
File metadata and controls
34 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%% This code is to implement the Newton-Rhapson one dimensional optimization
% to be able to find the derivative of purpose function with respect to sk
% by using the numerical approximation of differentiation
function sk = newtonRhapson(x0,pk,t,y,s,R)
xk = x0;
sk = 0.01; % initial sk
loop1 = 1;
tolerance = 1e-3;
tolerance_change = 1e-3;
stepSize = 1e-6;
while loop1
[Win,Wout,bin,bout] = devecotrization(xk+sk*pk,s,size(y,1),R);
[prediction] = ffnnetpredict(t, Win, Wout, bin, bout);
f = 0.5*(((y-prediction).^2));
df = diff(f)./stepSize;
ddf = diff(df)./stepSize;
df = sum(df); ddf = sum(ddf);
deltaXk = - df/ddf; % update parameter is found
sk = sk + deltaXk; % update rule
df_old = df;
[Win,Wout,bin,bout] = devecotrization(xk+sk*pk,s,size(y,1),R);
[prediction] = ffnnetpredict(t, Win, Wout, bin, bout);
f = 0.5*(((y-prediction).^2));
df = diff(f)./stepSize;
df = sum(df);
if df < tolerance || df - df_old < tolerance_change || deltaXk<tolerance
loop1 = 0;
end
end
end