Skip to content

Instantly share code, notes, and snippets.

@DavidSouther
Created July 31, 2012 21:06
Show Gist options
  • Save DavidSouther/3220550 to your computer and use it in GitHub Desktop.
Save DavidSouther/3220550 to your computer and use it in GitHub Desktop.
Timing functions in LiveScript
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