Skip to content

Instantly share code, notes, and snippets.

@masterdezign

masterdezign/Grad.hs

Last active Dec 10, 2018
Embed
What would you like to do?
A brief gradient descent illustration in Haskell
descent1D gradF iterN gamma x0 = take iterN (iterate _descend x0)
where
_descend gamma' x = x - gamma' * gradF x
-- Suppose, we have a function F(x) = (x - 3)^2.
-- Therefore, Grad F(x) = 2 * (x - 3).
gradF_test x = 2 * (x - 3)
main = print (descent1D gradF_test 10 gamma 0.0)
where gamma = 0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment