Created
November 8, 2017 20:02
-
-
Save purzelrakete/53fc8616002030d6bd3faf9f08fff470 to your computer and use it in GitHub Desktop.
Deep
This file contains hidden or 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
# functions | |
sigmoid(x) = 1 ./ (1 + exp.(-x)) | |
relu(x) = max.(0, x) | |
predict(x, A, B) = sigmoid(B * relu(A * x)) | |
# training data | |
X = [ | |
1 0 1 1 | |
0 1 0 1 | |
0 1 0 0 | |
1 0 0 0 | |
] | |
y = [1 1 0 0] | |
# parameter search | |
A = 0.5 - rand(3, 4) | |
B = 0.5 - rand(1, 3) | |
best_likelihood = 0.0 | |
for i = 0:10_000 | |
A_next = A + (0.5 - rand(3, 4)) * 0.1 | |
B_next = B + (0.5 - rand(1, 3)) * 0.1 | |
y_pred = predict(X, A_next, B_next) | |
likelihoods = y .* y_pred + (1 - y) .* (1 - y_pred) | |
likelihood = prod(likelihoods, 2)[1] | |
if likelihood > best_likelihood | |
println() | |
println("Improved in iteration ", i) | |
println("Likelihoods: ", likelihoods) | |
println("Likelihood: ", likelihood, ". NLL: ", -log.(likelihood)) | |
A = A_next | |
B = B_next | |
best_likelihood = likelihood | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment