This commit is contained in:
ton
2023-09-15 09:03:02 +07:00
parent d85edf5a19
commit 1eca740395
2 changed files with 958 additions and 6 deletions

View File

@@ -422,7 +422,6 @@ function lifLearn(wRec,
# transfer data to cpu
arrayProjection4d_cpu = arrayProjection4d |> cpu
wRec_cpu = wRec |> cpu
wRec_cpu = wRec_cpu[:,:,:,1] # since every batch has the same neuron wRec, (row, col, n)
wRecChange_cpu = wRecChange |> cpu
wRecChange_cpu = wRecChange_cpu[:,:,:,1]
eta_cpu = eta |> cpu
@@ -446,6 +445,7 @@ function lifLearn(wRec,
exInType_cpu,
wRecChange_cpu,
vt,
eta,
neuronInactivityCounter_cpu,
synapseReconnectDelay_cpu,
synapticActivityCounter_cpu,
@@ -566,6 +566,8 @@ function onLearn!(wOut,
wOut .-= 0.001 .* wOut
end
alltrue(args...) = false [args...] ? false : true
#WORKING 1) implement 90% +w, 10% -w 2) rewrite this function
function neuroplasticity(synapseConnectionNumber,
zitCumulative, # (row, col)
@@ -573,13 +575,16 @@ function neuroplasticity(synapseConnectionNumber,
exInType,
wRecChange,
vt,
eta,
neuronInactivityCounter,
synapseReconnectDelay,
synapticActivityCounter,
progress,) # (row, col, n)
i1,i2,i3 = size(wRec)
println("eta $(size(eta))")
println("wRec $(size(wRec))")
error("DEBUG -> neuroplasticity $(Dates.now())")
#WORKING DEPEND ON modelError
if progress == 2 # no need to learn
# skip neuroplasticity
#TODO I may need to do something with neuronInactivityCounter and other variables
@@ -588,10 +593,33 @@ function neuroplasticity(synapseConnectionNumber,
# merge learning weight with average learning weight of all batch
wRec .= abs.((exInType .* wRec) .+ wRecChange) # abs because wRec doesn't carry sign
# seperate active synapse out of inactive in this signal
mask_inactiveSynapse = isequal.(synapticActivityCounter, 0)
mask_activeSynapse = (!isequal).(synapticActivityCounter, 0)
# adjust weight based on vt progress and repeatition (90% +w, 10% -w) depend on epsilonRec
mask = isless.()
avgActivity = sum(synapticActivityCounter) / length(synapticActivityCounter)
lowerlimit = 0.1 * avgActivity
# +w, synapse with more than 10% of avg activity get increase weight by eta
mask_more = (!isless).(synapticActivityCounter, lowerlimit)
mask_2 = alltrue.(mask_activeSynapse, mask_more)
mask_2 .*= 1 .+ eta # minor activity synapse weight will be reduced by eta
wRec .*= mask_2
#WORKING should i -w only for activated synapse only or ALL synapse. activated synapse representing this signal e.g. number 3
# -w, synapse with less than 10% of avg activity get reduced weight by eta
mask_less = isless.(synapticActivityCounter, lowerlimit) # 1st criteria
mask_3 = alltrue.(mask_activeSynapse, mask_less)
mask_3 .*= 1 .- eta # minor activity synapse weight will be reduced by eta
wRec .*= mask_3
# -w all non-fire connection except mature connection
mask_notmature = isless.(wRec, 0.1) # 2nd criteria, weak synapse has weight < 0.1
mask_1 = alltrue.(mask_inactiveSynapse, mask_notmature)
mask_1 .*= 1 .- eta
wRec .*= mask_1
# prune weak connection
@@ -810,9 +838,6 @@ end