Created
October 25, 2020 14:04
-
-
Save jcbritobr/1308b6c8d573e3260a98e58df9e0ee0a to your computer and use it in GitHub Desktop.
Julia flux simple multilayer perceptron to solve xor problem
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
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