Skip to content

Instantly share code, notes, and snippets.

@evanthebouncy
Last active August 29, 2015 14: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 evanthebouncy/bde3e510e562da5db6a2 to your computer and use it in GitHub Desktop.
Save evanthebouncy/bde3e510e562da5db6a2 to your computer and use it in GitHub Desktop.
# you can copy/paste the code to here and run it in browser
# http://www.tutorialspoint.com/execute_julia_online.php
# a simple sigmoid shrink function that wraps x to a range between 0 and 1
shrink_fun(x) = 1 / (1 + e^-x)
# a random function generator,
# it makes a function that maps x to a random point between 0 and 1
function gen_fun()
n = -1.0 + 2*rand() # a random number between -1 and 1
function fun(x)
shrink_fun(n * x)
end
fun
end
# a function generator that creates n random functions f1...fn
# and chain them together x->fn(fn-1(...f1(x)))
function gen_chain(n)
funs = [gen_fun() for i in 1:n]
function chain(x)
ret = x
for i in 1:n
ret = funs[i](ret)
end
ret
end
chain
end
# get a chain and run it on some different inputs, what would you expect?
chain1 = gen_chain(100)
println(chain1(rand()*100))
println(chain1(rand()*123))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment