Last active
August 29, 2015 14:23
-
-
Save evanthebouncy/bde3e510e562da5db6a2 to your computer and use it in GitHub Desktop.
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
# 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