Created
January 15, 2014 05:37
-
-
Save Javran/8431352 to your computer and use it in GitHub Desktop.
gradient descent in haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
realworldFunc x = x * 0.5 + 1.23 | |
dataSize = 100 | |
dataSet = take dataSize $ map (\x -> (x,realworldFunc x)) [1..] | |
gdAlgo alpha (initT0, initT1) = (newT0,newT1) | |
where | |
hypo x = x * initT1 + initT0 | |
newT0 = initT0 - theConst * (sum theDiffs) | |
newT1 = initT1 - theConst * (sum $ zipWith (*) theDiffs (map fst dataSet)) | |
theDiffs = map (\(x,y) -> hypo x - y) dataSet | |
theConst = alpha / (fromIntegral dataSize) | |
theStream = iterate (gdAlgo 0.0004) (0,0) | |
main = print $ theStream !! 10000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment