Skip to content

Instantly share code, notes, and snippets.

@jcbritobr
Created October 25, 2020 14:04
Show Gist options
  • Save jcbritobr/1308b6c8d573e3260a98e58df9e0ee0a to your computer and use it in GitHub Desktop.
Save jcbritobr/1308b6c8d573e3260a98e58df9e0ee0a to your computer and use it in GitHub Desktop.
Julia flux simple multilayer perceptron to solve xor problem
using Flux
using Plots
x = [0f0 0 1 1; 0 1 0 1]
y = [0f0 1 1 0]
xornn_model = Chain(
Dense(2, 2, σ),
Dense(2, 1, σ)
)
params(xornn_model)
params(xornn_model)[1]
params(xornn_model)[3]
loss_fn(x, y) = Flux.mse(xornn_model(x), y)
opt = ADAM(0.1)
n = 500
loss = zeros(500)
for i in 1:500
Flux.train!(loss_fn, params(xornn_model), [(x, y)], opt)
loss[i] = loss_fn(x, y)
if i % 10 == 0
println(loss[i])
end
end
loss_fn(x, y)
xornn_model(x)
plot(1:n, loss, title="MSE vs Epochs of xor network")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment