refractoring

This commit is contained in:
2023-05-24 18:22:01 +07:00
parent ffd366d81a
commit 8c8ca60871

View File

@@ -23,40 +23,40 @@ end
""" knowledgeFn learn() """ knowledgeFn learn()
""" """
function learn!(kfn::kfn_1, correctAnswer::BitVector) function learn!(kfn::kfn_1, correctAnswer::BitVector)
# # compute kfn error for each neuron # compute kfn error for each neuron
# outs = [n.z_t1 for n in kfn.outputNeuronsArray]
# for (i, out) in enumerate(outs)
# if out != correctAnswer[i] # need to adjust weight
# kfnError = ( (kfn.outputNeuronsArray[i].v_th - kfn.outputNeuronsArray[i].vError) *
# 100 / kfn.outputNeuronsArray[i].v_th )
# Threads.@threads for n in kfn.neuronsArray
# # for n in kfn.neuronsArray
# learn!(n, kfnError)
# end
# learn!(kfn.outputNeuronsArray[i], kfnError)
# end
# end
#TESTING compute kfn error for each neuron
outs = [n.z_t1 for n in kfn.outputNeuronsArray] outs = [n.z_t1 for n in kfn.outputNeuronsArray]
for (i, out) in enumerate(outs) for (i, out) in enumerate(outs)
if out != correctAnswer[i] # need to adjust weight if out != correctAnswer[i] # need to adjust weight
kfnError = ( (kfn.outputNeuronsArray[i].v_th - kfn.outputNeuronsArray[i].vError) * kfnError = ( (kfn.outputNeuronsArray[i].v_th - kfn.outputNeuronsArray[i].vError) *
100 / kfn.outputNeuronsArray[i].v_th ) 100 / kfn.outputNeuronsArray[i].v_th )
if correctAnswer[i] == 1 # output neuron that associated with correctAnswer
Threads.@threads for n in kfn.neuronsArray Threads.@threads for n in kfn.neuronsArray
# for n in kfn.neuronsArray # for n in kfn.neuronsArray
learn!(n, kfnError) learn!(n, kfnError)
end end
learn!(kfn.outputNeuronsArray[i], kfnError)
else # output neuron that is NOT associated with correctAnswer
learn!(kfn.outputNeuronsArray[i], kfnError) learn!(kfn.outputNeuronsArray[i], kfnError)
end end
end end
end
# #TESTING compute kfn error for each neuron
# outs = [n.z_t1 for n in kfn.outputNeuronsArray]
# for (i, out) in enumerate(outs)
# if out != correctAnswer[i] # need to adjust weight
# kfnError = ( (kfn.outputNeuronsArray[i].v_th - kfn.outputNeuronsArray[i].vError) *
# 100 / kfn.outputNeuronsArray[i].v_th )
# if correctAnswer[i] == 1 # output neuron that associated with correctAnswer
# Threads.@threads for n in kfn.neuronsArray
# # for n in kfn.neuronsArray
# learn!(n, kfnError)
# end
# learn!(kfn.outputNeuronsArray[i], kfnError)
# else # output neuron that is NOT associated with correctAnswer
# learn!(kfn.outputNeuronsArray[i], kfnError)
# end
# end
# end
# wrap up learning session # wrap up learning session
if kfn.learningStage == "end_learning" if kfn.learningStage == "end_learning"