Flux.jl/examples/sketch.jl
Mike Innes e5856d8b27 init
2016-09-06 18:10:18 +01:00

58 lines
950 B
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Simple Perceptron Layer
@flux type Simple
weight
bias
x -> σ( weight*x + bias )
end
Simple(nx::Integer, ny::Integer; init = randn) =
Simple(init(nx, ny), init(ny))
# Time Delay Node
type Delay
n::Int
next
end
# feed(l::Delay, x) = ...
# back(l::Delay, y) = ...
# Simple Recurrent
@flux type RecurrentU
Wxh; Whh; Bh
Wxy; Why; By
function feed(x, hidden)
hidden = σ( Wxh*x + Whh*hidden + Bh )
y = σ( Wxy*x + Why*hidden + By )
y, hidden
end
end
Recurrent(nx, ny, nh; init = randn) =
Recurrent(init(nx, nh), init(nh, nh), init(nh),
init(nx, ny), init(nh, ny), init(ny))
@flux type Looped{T}
delay::Delay
layer::T
function (x)
y, hidden = layer(x, delay(hidden))
return y
end
end
type Recurrent
layer::Looped{RecurrentU}
end
Recurrent(nx, ny, nh; init = randn, delay = 10) =
Looped(Delay(delay, init(nh)), RecurrentU(nx, ny, nh))
@forward Recurrent.layer feed