train compute neuron with associated output neuron

This commit is contained in:
2023-05-24 08:53:48 +07:00
parent d0d85f5edf
commit ed5bdff935
2 changed files with 29 additions and 10 deletions

View File

@@ -34,10 +34,9 @@ using .interface
""" """
Todo: Todo:
[1] implement connection strength based on right or wrong answer [2] implement connection strength based on right or wrong answer
[2] during 0 training if 1-9 output neuron fires, adjust weight only those neurons [4] implement dormant connection
[3] implement dormant connection [3] Δweight * connection strength
[4] Δweight * connection strength
[] using RL to control learning signal [] using RL to control learning signal
[] consider using Dates.now() instead of timestamp because time_stamp may overflow [] consider using Dates.now() instead of timestamp because time_stamp may overflow
[5] training should include adjusting α, neuron membrane potential decay factor [5] training should include adjusting α, neuron membrane potential decay factor
@@ -62,6 +61,7 @@ using .interface
[DONE] wRec should not normalized whole. it should be local 5 conn normalized. [DONE] wRec should not normalized whole. it should be local 5 conn normalized.
[DONE] neuroplasticity() i.e. change connection [DONE] neuroplasticity() i.e. change connection
[DONE] add multi threads [DONE] add multi threads
[DONE] during 0 training if 1-9 output neuron fires, adjust weight only those neurons
Change from version: v06_36a Change from version: v06_36a
- -

View File

@@ -23,19 +23,38 @@ end
""" knowledgeFn learn() """ knowledgeFn learn()
""" """
function learn!(kfn::kfn_1, correctAnswer::BitVector) function learn!(kfn::kfn_1, correctAnswer::BitVector)
# compute kfn error # # 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
# for n in kfn.neuronsArray
learn!(n, kfnError)
end
Threads.@threads for n in kfn.neuronsArray learn!(kfn.outputNeuronsArray[i], kfnError)
# for n in kfn.neuronsArray else # output neuron that is NOT associated with correctAnswer
learn!(n, kfnError) learn!(kfn.outputNeuronsArray[i], kfnError)
end end
learn!(kfn.outputNeuronsArray[i], kfnError)
end end
end end