Ich versuche, Code aus diesem tutorial auf Python zu Julia umschreiben und bekomme ein unerwartetes Ergebnis - [0.5; 0.5; 0.5; 0.5]
Ich schaue auf die Linie wieder und wieder, aber sehe keinen Unterschied.Einfaches neuronales Netzwerk in Julia
Python-Code:
from numpy import exp, array, random, dot
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
random.seed(1)
synaptic_weights = 2 * random.random((3, 1)) - 1
for iteration in xrange(10000):
output = 1/(1 + exp(-(dot(training_set_inputs, synaptic_weights))))
synaptic_weights += dot(training_set_inputs.T, (training_set_outputs - output) * output * (1 - output))
print 1/(1 + exp(-(dot(array([1, 0, 0]), synaptic_weights))))
Meine julia Code:
function activate(x)
return 1./(1+exp(-x))
end
function g_activate(x)
return x.*(1-x)
end
function test(iter)
Input = [0 0 1;0 1 1;1 0 1;1 1 1]
TInput = transpose(Input)
Test = [0, 1, 1, 0]
Weights = 2 * rand(3, 1) - 1
for i in 1:iter
output = activate(Input*Weights)
error = Test - output
delta = error.*g_activate(output)
Weights += TInput*delta
end
println(activate(Input*Weights))
end
Was ich tue, falsch und wie es noch mehr idiomatischer Weg in Julia
@khelwood, ja. Es ist die Transponierte der Matrix. – CamFerry
Das macht Sinn. – khelwood
Ich habe mit einer anderen Syntax bearbeitet. – CamFerry