Gradient descent: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: changed comments and whitespace, simplified some statements, optimized the GRADG function,) |
m (→{{header|REXX}}: moved a function to the one-line function section.) |
||
Line 634: | Line 634: | ||
tolerance= 0.0000006 |
tolerance= 0.0000006 |
||
alpha= 0.1 |
alpha= 0.1 |
||
x.0= 0.1; x.1= -1 |
x.0= 0.1; x.1= -1 |
||
say center(' testing for the steepest descent method ', 79, "═") |
say center(' testing for the steepest descent method ', 79, "═") |
||
call steepestD /* ┌──◄── # digs past dec. point ─►───┐*/ |
call steepestD /* ┌──◄── # digs past dec. point ─►───┐*/ |
||
Line 640: | Line 640: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
⚫ | |||
g: return (x.0-1)**2 * exp(- (x.1**2) ) + x.1 * (x.1 + 2) * exp(-2 * x.0**2) |
g: return (x.0-1)**2 * exp(- (x.1**2) ) + x.1 * (x.1 + 2) * exp(-2 * x.0**2) |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 662: | Line 663: | ||
end /*while*/ |
end /*while*/ |
||
return |
return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
exp: procedure; parse arg x; ix= x%1; if abs(x-ix)>.5 then ix= ix + sign(x); x= x - ix |
exp: procedure; parse arg x; ix= x%1; if abs(x-ix)>.5 then ix= ix + sign(x); x= x - ix |