dev
This commit is contained in:
404
src/learn.jl
404
src/learn.jl
@@ -267,30 +267,32 @@ end
|
||||
|
||||
function learn!(kfn::kfn_1, device=cpu)
|
||||
# lif learn
|
||||
kfn.lif_wRec, kfn.lif_neuronInactivityCounter, kfn.lif_synapticActivityCounter =
|
||||
kfn.lif_wRec, kfn.lif_neuronInactivityCounter, kfn.lif_synapseReconnectDelayCounter =
|
||||
lifLearn(kfn.lif_wRec,
|
||||
kfn.lif_exInType,
|
||||
kfn.lif_wRecChange,
|
||||
kfn.lif_exInType,
|
||||
kfn.lif_arrayProjection4d,
|
||||
kfn.lif_neuronInactivityCounter,
|
||||
kfn.lif_synapticActivityCounter,
|
||||
kfn.lif_synapseReconnectDelayCounter,
|
||||
kfn.lif_synapseConnectionNumber,
|
||||
kfn.lif_synapticWChangeCounter,
|
||||
kfn.lif_eta,
|
||||
kfn.lif_vt,
|
||||
kfn.zitCumulative,
|
||||
device)
|
||||
|
||||
# alif learn
|
||||
kfn.alif_wRec, kfn.alif_neuronInactivityCounter, kfn.alif_synapticActivityCounter =
|
||||
kfn.alif_wRec, kfn.alif_neuronInactivityCounter, kfn.alif_synapseReconnectDelayCounter =
|
||||
alifLearn(kfn.alif_wRec,
|
||||
kfn.alif_exInType,
|
||||
kfn.alif_wRecChange,
|
||||
kfn.alif_exInType,
|
||||
kfn.alif_arrayProjection4d,
|
||||
kfn.alif_neuronInactivityCounter,
|
||||
kfn.alif_synapticActivityCounter,
|
||||
kfn.alif_synapseReconnectDelayCounter,
|
||||
kfn.alif_synapseConnectionNumber,
|
||||
kfn.alif_synapticWChangeCounter,
|
||||
kfn.alif_eta,
|
||||
kfn.alif_vt,
|
||||
kfn.zitCumulative,
|
||||
device)
|
||||
|
||||
@@ -306,146 +308,178 @@ function learn!(kfn::kfn_1, device=cpu)
|
||||
# error("DEBUG -> kfn learn! $(Dates.now())")
|
||||
end
|
||||
|
||||
# function lifLearn(wRec,
|
||||
# exInType,
|
||||
# wRecChange,
|
||||
# arrayProjection4d,
|
||||
# neuronInactivityCounter,
|
||||
# synapseReconnectDelayCounter,
|
||||
# synapseConnectionNumber,
|
||||
# synapticWChangeCounter, #TODO
|
||||
# eta,
|
||||
# zitCumulative,
|
||||
# device)
|
||||
|
||||
# # merge learning weight with average learning weight of all batch
|
||||
# wch = sum(wRecChange, dims=4) ./ (size(wRec, 4)) .* arrayProjection4d
|
||||
# wRec .= (exInType .* wRec) .+ wch
|
||||
|
||||
# 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)
|
||||
# synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter |> cpu
|
||||
# synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu[:,:,:,1]
|
||||
# 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(synapseReconnectDelayCounter[:,:,i]) / length(synapseReconnectDelayCounter[:,:,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
|
||||
|
||||
# # neuroplasticity, work on CPU side
|
||||
# wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
# zitCumulative_cpu,
|
||||
# wRec_cpu,
|
||||
# neuronInactivityCounter_cpu,
|
||||
# synapseReconnectDelayCounter_cpu)
|
||||
|
||||
# wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
# wRec = wRec_cpu |> device
|
||||
|
||||
# neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
# neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
# synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu .* arrayProjection4d_cpu
|
||||
# synapseReconnectDelayCounter = synapseReconnectDelayCounter_cpu |> device
|
||||
|
||||
# return wRec, neuronInactivityCounter, synapseReconnectDelayCounter
|
||||
# end
|
||||
|
||||
function lifLearn(wRec,
|
||||
exInType,
|
||||
wRecChange,
|
||||
exInType,
|
||||
arrayProjection4d,
|
||||
neuronInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
synapseReconnectDelayCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
eta,
|
||||
vt,
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
# merge learning weight with average learning weight of all batch
|
||||
wch = sum(wRecChange, dims=4) ./ (size(wRec, 4)) .* arrayProjection4d
|
||||
wRec .= (exInType .* wRec) .+ wch
|
||||
|
||||
# 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
|
||||
eta_cpu = eta_cpu[:,:,:,1]
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter |> cpu
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu[:,:,:,1] # (row, col, n)
|
||||
synapticActivityCounter_cpu = synapticActivityCounter |> cpu
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu[:,:,:,1]
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter |> cpu
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu[:,:,:,1]
|
||||
zitCumulative_cpu = zitCumulative |> cpu
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col)
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1]
|
||||
|
||||
# -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
|
||||
#TODO neuroplasticity, work on CPU side
|
||||
wRec_cpu, neuronInactivityCounter_cpu, synapseReconnectDelayCounter_cpu,
|
||||
= neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
wRecChange_cpu,
|
||||
vt,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapseReconnectDelayCounter_cpu)
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# # merge learning weight with average learning weight of all batch
|
||||
# wch = sum(wRecChange, dims=4) ./ (size(wRec, 4)) .* arrayProjection4d
|
||||
# wRec .= (exInType .* wRec) .+ wch
|
||||
|
||||
# # (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(synapseReconnectDelayCounter[:,:,i]) / length(synapseReconnectDelayCounter[:,:,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
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapticActivityCounter_cpu)
|
||||
# wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
# zitCumulative_cpu,
|
||||
# wRec_cpu,
|
||||
# wRecChange_cpu,
|
||||
# vt,
|
||||
# neuronInactivityCounter_cpu,
|
||||
# synapseReconnectDelayCounter_cpu)
|
||||
|
||||
# transfer data backto gpu
|
||||
wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
wRec = wRec_cpu |> device
|
||||
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticActivityCounter = synapticActivityCounter_cpu |> device
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu .* arrayProjection4d_cpu
|
||||
synapseReconnectDelayCounter = synapseReconnectDelayCounter_cpu |> device
|
||||
|
||||
return wRec, neuronInactivityCounter, synapticActivityCounter
|
||||
end
|
||||
|
||||
function alifLearn(wRec,
|
||||
exInType,
|
||||
wRecChange,
|
||||
arrayProjection4d,
|
||||
neuronInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
eta,
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
# merge learning weight with average learning weight of all batch
|
||||
wch = sum(wRecChange, dims=4) ./ (size(wRec, 4)) .* arrayProjection4d
|
||||
wRec .= (exInType .* wRec) .+ wch
|
||||
|
||||
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
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu[:,:,:,1]
|
||||
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
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapticActivityCounter_cpu)
|
||||
|
||||
wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
wRec = wRec_cpu |> device
|
||||
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticActivityCounter = synapticActivityCounter_cpu |> device
|
||||
|
||||
# error("DEBUG -> alifLearn! $(Dates.now())")
|
||||
return wRec, neuronInactivityCounter, synapticActivityCounter
|
||||
end
|
||||
|
||||
function onLearn!(wOut,
|
||||
wOutChange,
|
||||
arrayProjection4d)
|
||||
# merge learning weight with average learning weight
|
||||
wOut .+= (sum(wOutChange, dims=4) ./ (size(wOut, 4))) .* arrayProjection4d
|
||||
|
||||
# adaptive wOut to help convergence using c_decay
|
||||
wOut .-= 0.001 .* wOut
|
||||
|
||||
#TODO synaptic strength
|
||||
|
||||
#TODO neuroplasticity
|
||||
|
||||
return wRec, neuronInactivityCounter, synapseReconnectDelayCounter
|
||||
end
|
||||
|
||||
#TODO
|
||||
function neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative, # (row, col)
|
||||
wRec, # (row, col, n)
|
||||
wRecChange,
|
||||
vt,
|
||||
neuronInactivityCounter,
|
||||
synapticActivityCounter) # (row, col, n)
|
||||
|
||||
synapseReconnectDelayCounter) # (row, col, n)
|
||||
i1,i2,i3 = size(wRec)
|
||||
|
||||
# merge weight
|
||||
|
||||
|
||||
|
||||
|
||||
# adjust weight based on vt progress and repeatition (90% +w, 10% -w)
|
||||
|
||||
|
||||
|
||||
# -w all non-fire connection except mature connection
|
||||
|
||||
|
||||
|
||||
# prune weak connection
|
||||
|
||||
|
||||
|
||||
|
||||
# rewire synapse connection
|
||||
|
||||
|
||||
|
||||
# for each neuron, find total number of synaptic conn that should draw
|
||||
# new connection to firing and non-firing neurons pool
|
||||
subToFireNeuron_toBe = Int(floor(0.7 * synapseConnectionNumber))
|
||||
@@ -460,7 +494,7 @@ function neuroplasticity(synapseConnectionNumber,
|
||||
println("neuroplasticity, from $(synapseConnectionNumber*size(totalNewConn, 3)) conn, $(sum(totalNewConn)) are replaced")
|
||||
|
||||
# clear -1.0 marker
|
||||
GeneralUtils.replaceElements!(wRec, -1.0, synapticActivityCounter, -0.99)
|
||||
GeneralUtils.replaceElements!(wRec, -1.0, synapseReconnectDelayCounter, -0.99)
|
||||
GeneralUtils.replaceElements!(wRec, -1.0, 0.0) # -1.0 marker is no longer required
|
||||
|
||||
for i in 1:i3
|
||||
@@ -473,7 +507,7 @@ function neuroplasticity(synapseConnectionNumber,
|
||||
a = similar(w) .= -0.99 # synapseConnectionNumber of this neuron
|
||||
mask = (!iszero).(w)
|
||||
GeneralUtils.replaceElements!(mask, 1, a, 0)
|
||||
synapticActivityCounter[:,:,i] = a
|
||||
synapseReconnectDelayCounter[:,:,i] = a
|
||||
else
|
||||
remaining = 0
|
||||
if subToFireNeuron_current[1,1,i] < subToFireNeuron_toBe
|
||||
@@ -482,7 +516,7 @@ function neuroplasticity(synapseConnectionNumber,
|
||||
# add new conn to firing neurons pool
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
@view(synapseReconnectDelayCounter[:,:,i]),
|
||||
toAddConn)
|
||||
totalNewConn[1,1,i] += remaining
|
||||
end
|
||||
@@ -490,12 +524,12 @@ function neuroplasticity(synapseConnectionNumber,
|
||||
# add new conn to non-firing neurons pool
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 0,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
@view(synapseReconnectDelayCounter[:,:,i]),
|
||||
totalNewConn[1,1,i])
|
||||
if remaining > 0 # final get-all round if somehow non-firing pool has not enough slot
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
@view(synapseReconnectDelayCounter[:,:,i]),
|
||||
remaining)
|
||||
end
|
||||
end
|
||||
@@ -505,6 +539,146 @@ function neuroplasticity(synapseConnectionNumber,
|
||||
return wRec
|
||||
end
|
||||
|
||||
function alifLearn(wRec,
|
||||
wRecChange,
|
||||
exInType,
|
||||
arrayProjection4d,
|
||||
neuronInactivityCounter,
|
||||
synapseReconnectDelayCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
eta,
|
||||
vt,
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
# merge learning weight with average learning weight of all batch
|
||||
wch = sum(wRecChange, dims=4) ./ (size(wRec, 4)) .* arrayProjection4d
|
||||
wRec .= (exInType .* wRec) .+ wch
|
||||
|
||||
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)
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter |> cpu
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu[:,:,:,1]
|
||||
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(synapseReconnectDelayCounter[:,:,i]) / length(synapseReconnectDelayCounter[:,:,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
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapseReconnectDelayCounter_cpu)
|
||||
|
||||
wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
wRec = wRec_cpu |> device
|
||||
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
synapseReconnectDelayCounter_cpu = synapseReconnectDelayCounter_cpu .* arrayProjection4d_cpu
|
||||
synapseReconnectDelayCounter = synapseReconnectDelayCounter_cpu |> device
|
||||
|
||||
# error("DEBUG -> alifLearn! $(Dates.now())")
|
||||
return wRec, neuronInactivityCounter, synapseReconnectDelayCounter
|
||||
end
|
||||
|
||||
function onLearn!(wOut,
|
||||
wOutChange,
|
||||
arrayProjection4d)
|
||||
# merge learning weight with average learning weight
|
||||
wOut .+= (sum(wOutChange, dims=4) ./ (size(wOut, 4))) .* arrayProjection4d
|
||||
|
||||
# adaptive wOut to help convergence using c_decay
|
||||
wOut .-= 0.001 .* wOut
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
# function neuroplasticity(synapseConnectionNumber,
|
||||
# zitCumulative, # (row, col)
|
||||
# wRec, # (row, col, n)
|
||||
# neuronInactivityCounter,
|
||||
# synapseReconnectDelayCounter) # (row, col, n)
|
||||
|
||||
# i1,i2,i3 = size(wRec)
|
||||
|
||||
# # for each neuron, find total number of synaptic conn that should draw
|
||||
# # new connection to firing and non-firing neurons pool
|
||||
# subToFireNeuron_toBe = Int(floor(0.7 * synapseConnectionNumber))
|
||||
|
||||
# # for each neuron, count how many synap already subscribed to firing-neurons
|
||||
# zw = zitCumulative .* wRec
|
||||
# subToFireNeuron_current = sum(GeneralUtils.isBetween.(zw, 0.0, 100.0), dims=(1,2)) # (1, 1, n)
|
||||
# zitMask = (!iszero).(zitCumulative) # zitMask of firing neurons = 1, non-firing = 0
|
||||
# projection = ones(i1,i2,i3)
|
||||
# zitMask = zitMask .* projection # (row, col, n)
|
||||
# totalNewConn = sum(isequal.(wRec, -1.0), dims=(1,2)) # count new conn mark (-1.0), (1, 1, n)
|
||||
# println("neuroplasticity, from $(synapseConnectionNumber*size(totalNewConn, 3)) conn, $(sum(totalNewConn)) are replaced")
|
||||
|
||||
# # clear -1.0 marker
|
||||
# GeneralUtils.replaceElements!(wRec, -1.0, synapseReconnectDelayCounter, -0.99)
|
||||
# GeneralUtils.replaceElements!(wRec, -1.0, 0.0) # -1.0 marker is no longer required
|
||||
|
||||
# for i in 1:i3
|
||||
# if neuronInactivityCounter[1:1:i][1] < -10000 # neuron die i.e. reset all weight
|
||||
# println("neuron die")
|
||||
# neuronInactivityCounter[:,:,i] .= 0 # reset
|
||||
# w = random_wRec(i1,i2,1,synapseConnectionNumber)
|
||||
# wRec[:,:,i] .= w
|
||||
|
||||
# a = similar(w) .= -0.99 # synapseConnectionNumber of this neuron
|
||||
# mask = (!iszero).(w)
|
||||
# GeneralUtils.replaceElements!(mask, 1, a, 0)
|
||||
# synapseReconnectDelayCounter[:,:,i] = a
|
||||
# else
|
||||
# remaining = 0
|
||||
# if subToFireNeuron_current[1,1,i] < subToFireNeuron_toBe
|
||||
# toAddConn = subToFireNeuron_toBe - subToFireNeuron_current[1,1,i]
|
||||
# totalNewConn[1,1,i] = totalNewConn[1,1,i] - toAddConn
|
||||
# # add new conn to firing neurons pool
|
||||
# remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
# @view(wRec[:,:,i]),
|
||||
# @view(synapseReconnectDelayCounter[:,:,i]),
|
||||
# toAddConn)
|
||||
# totalNewConn[1,1,i] += remaining
|
||||
# end
|
||||
|
||||
# # add new conn to non-firing neurons pool
|
||||
# remaining = addNewSynapticConn!(zitMask[:,:,i], 0,
|
||||
# @view(wRec[:,:,i]),
|
||||
# @view(synapseReconnectDelayCounter[:,:,i]),
|
||||
# totalNewConn[1,1,i])
|
||||
# if remaining > 0 # final get-all round if somehow non-firing pool has not enough slot
|
||||
# remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
# @view(wRec[:,:,i]),
|
||||
# @view(synapseReconnectDelayCounter[:,:,i]),
|
||||
# remaining)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# # error("DEBUG -> neuroplasticity $(Dates.now())")
|
||||
# return wRec
|
||||
# end
|
||||
|
||||
# learningLiquidity(x) = -0.0001x + 1 # -10000 to +10000; f(x) = -5e-05x+0.5
|
||||
|
||||
function learningLiquidity(x)
|
||||
|
||||
Reference in New Issue
Block a user