Created
July 31, 2012 21:06
-
-
Save DavidSouther/3220550 to your computer and use it in GitHub Desktop.
Timing functions in LiveScript
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
polynomial = (coefficients) -> | |
n = 0 | |
coefficients = reverse coefficients | |
(x = n++) -> | |
sum = 0 | |
for c, i in coefficients | |
sum += c * Math.pow(x, i) | |
sum | |
linear = (a = 1, b = 0) -> | |
polynomial([a, b]) | |
quadratic = (a = 1, b = 0, c = 0) -> | |
polynomial([a, b, c]) | |
sigmoid = (min = 0.5, max = 1, scale = 0.5, step = linear!) -> | |
-> (1 / (1 + Math.exp -step!) - (0.5 - min)) * 2 * max * scale | |
inc = quadratic 0.1 | |
s = sigmoid 0, 2, 1000, inc | |
log = "" | |
for i from 0 to 20 | |
log += "#{i}:\t#{s!}\n" | |
log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment