Skip to content

Instantly share code, notes, and snippets.

@masterdezign
Last active December 10, 2018 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterdezign/5b0cbc6987552d08e5c86d46dd657303 to your computer and use it in GitHub Desktop.
Save masterdezign/5b0cbc6987552d08e5c86d46dd657303 to your computer and use it in GitHub Desktop.
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