Created
January 16, 2014 13:19
-
-
Save fredyr/8454877 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
f x = (42-x)^2 | |
impr = [(x, f x) | x <- [0, 0.1 ..]] | |
opt goal = head $ dropWhile (\(x, err) -> err >= goal) impr |
Author
fredyr
commented
Jan 16, 2014
from itertools import *
def f(x):
return (42-x)**2
def improve_gen():
x, err = 0, f(0)
while True:
yield x, err
new_x = x + 0.1
x, err = new_x, f(new_x)
def opt(goal):
return dropwhile(lambda (x,err): err >= goal, improve_gen()).next()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment