add alif repeat weight adjust
This commit is contained in:
25
src/learn.jl
25
src/learn.jl
@@ -290,6 +290,7 @@ function learn!(kfn::kfn_1, device=cpu)
|
||||
kfn.alif_synapticActivityCounter,
|
||||
kfn.alif_synapseConnectionNumber,
|
||||
kfn.alif_synapticWChangeCounter,
|
||||
kfn.alif_eta,
|
||||
kfn.zitCumulative,
|
||||
device)
|
||||
|
||||
@@ -334,7 +335,6 @@ function lifLearn(wRec,
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col)
|
||||
|
||||
# -W if less than 10% of repeat avg, +W otherwise
|
||||
println("wRec_cpu 1 ", wRec_cpu)
|
||||
_, _, i3 = size(wRec_cpu)
|
||||
for i in 1:i3
|
||||
x = 0.1 * (sum(synapticActivityCounter[:,:,i]) / length(synapticActivityCounter[:,:,i]))
|
||||
@@ -345,12 +345,6 @@ function lifLearn(wRec,
|
||||
# weak / negative synaptic connection will get randomed in neuroplasticity()
|
||||
wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.01, -1.0) # mark with -1.0
|
||||
|
||||
# # synaptic connection that has no activity will get randomed in neuroplasticity()
|
||||
# mask = isless.(synapticActivityCounter_cpu, -100000)
|
||||
# GeneralUtils.replaceElements!(mask, 1, wRec_cpu, -1.0)
|
||||
# # reset lif_inactivity elements to base value
|
||||
# GeneralUtils.replaceElements!(mask, 1, synapticActivityCounter_cpu, 0.0)
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
@@ -379,6 +373,7 @@ function alifLearn(wRec,
|
||||
synapticActivityCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
eta,
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
@@ -389,6 +384,8 @@ function alifLearn(wRec,
|
||||
arrayProjection4d_cpu = arrayProjection4d |> cpu
|
||||
wRec_cpu = wRec |> cpu
|
||||
wRec_cpu = wRec_cpu[:,:,:,1] # since every batch has the same neuron wRec, (row, col, n)
|
||||
eta_cpu = eta |> cpu
|
||||
eta_cpu = eta_cpu[:,:,:,1]
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter |> cpu
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu[:,:,:,1] # (row, col, n)
|
||||
synapticActivityCounter_cpu = synapticActivityCounter |> cpu
|
||||
@@ -396,15 +393,17 @@ function alifLearn(wRec,
|
||||
zitCumulative_cpu = zitCumulative |> cpu
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col)
|
||||
|
||||
# -W if less than 10% of repeat avg, +W otherwise
|
||||
_, _, i3 = size(wRec_cpu)
|
||||
for i in 1:i3
|
||||
x = 0.1 * (sum(synapticActivityCounter[:,:,i]) / length(synapticActivityCounter[:,:,i]))
|
||||
mask = GeneralUtils.replaceLessThan.(wRec_cpu[:,:,i], x, -1, 1)
|
||||
wRec_cpu[:,:,i] .+= mask .* eta_cpu[:,:,i] .* wRec_cpu[:,:,i]
|
||||
end
|
||||
|
||||
# weak / negative synaptic connection will get randomed in neuroplasticity()
|
||||
wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.01, -1.0) # mark with -1.0
|
||||
|
||||
# synaptic connection that has no activity will get randomed in neuroplasticity()
|
||||
mask = isless.(synapticActivityCounter_cpu, -100000)
|
||||
GeneralUtils.replaceElements!(mask, 1, wRec_cpu, -1.0)
|
||||
# reset alif_inactivity elements to base value
|
||||
GeneralUtils.replaceElements!(mask, 1, synapticActivityCounter_cpu, 0.0)
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
|
||||
Reference in New Issue
Block a user