Gradient descent: Difference between revisions

→‎{{header|Wren}}: Now uses new core library method.
(→‎{{header|Wren}}: Now uses new core library method.)
Line 1,104:
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/mathfmt" for MathFmt
import "/fmt" for Fmt
 
// Function for which minimum is to be found.
var g = Fn.new { |x|
return (x[0]-1)*(x[0]-1)*
Math.exp(-x[1]*x[1]).exp + x[1]*(x[1]+2)*
Math.exp(-2*x[0]*x[0]).exp
}
 
Line 1,120 ⟶ 1,118:
var x = p[0]
var y = p[1]
return [2*(x-1)*Math.exp(-y*y).exp - 4*x*Math.exp(-2*x*x).exp*y*(y+2),
-2*(x-1)*(x-1)*y*Math.exp(-y*y).exp + Math.exp(-2*x*x).exp*(y+2) + Math.exp(-2*x*x).exp*y]
}
 
9,479

edits