From 4d7a3d5d5ac538c4d53f71ccc819114244e51124 Mon Sep 17 00:00:00 2001 From: ton Date: Wed, 5 Jul 2023 10:53:06 +0700 Subject: [PATCH] minor fix --- src/learn.jl | 7 ++++--- src/snn_utils.jl | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/learn.jl b/src/learn.jl index 4baf8b9..c7566e4 100644 --- a/src/learn.jl +++ b/src/learn.jl @@ -198,9 +198,10 @@ function learn!(n::T, firedNeurons, nExInType) where T<:computeNeuron wSign_1 = sign.(n.wRec) # check for fliped sign, 1 indicates non-fliped sign nonFlipedSign = isequal.(wSign_0, wSign_1) # 1 not fliped, 0 fliped # normalize wRec peak to prevent input signal overwhelming neuron - # if sum(n.wRecChange) != 0 - # normalizePeak!(n.wRec, n.wRecChange, 2) - # end + if sum(n.wRecChange) != 0 + normRadius = Int(floor(0.1 * length(n.subscriptionList))) + normalizePeak!(n.wRec, n.wRecChange, normRadius) + end # set weight that fliped sign to 0 for random new connection n.wRec .*= nonFlipedSign diff --git a/src/snn_utils.jl b/src/snn_utils.jl index 2f88fa1..cb6679c 100644 --- a/src/snn_utils.jl +++ b/src/snn_utils.jl @@ -322,6 +322,43 @@ end """ rewire of neuron synaptic connection that has 0 weight. Without connection's excitatory and inhabitory ratio constraint. """ +# function neuroplasticity!(n::computeNeuron, firedNeurons::Vector, +# nExInTypeList::Vector) +# # if there is 0-weight then replace it with new connection +# zeroWeightConnIndex = findall(iszero.(n.wRec)) # connection that has 0 weight +# if length(zeroWeightConnIndex) != 0 +# # new synaptic connection must sample fron neuron that fires +# nFiredPool = filter(x -> x ∉ [n.id], firedNeurons) # exclude this neuron id from the id list +# filter!(x -> x ∉ n.subscriptionList, nFiredPool) # exclude this neuron's subscriptionList from the list + +# nNonFiredPool = setdiff!([1:length(nExInTypeList)...], nFiredPool) +# filter!(x -> x ∉ [n.id], nNonFiredPool) # exclude this neuron id from the id list +# filter!(x -> x ∉ n.subscriptionList, nNonFiredPool) # exclude this neuron's subscriptionList from the list + +# w = randn(length(zeroWeightConnIndex)) / 10 +# synapticStrength = rand(-4.5:0.1:-3.5, length(zeroWeightConnIndex)) + +# shuffle!(nFiredPool) +# shuffle!(nNonFiredPool) + +# # add new synaptic connection to neuron +# for (i, connIndex) in enumerate(zeroWeightConnIndex) +# """ conn that is being replaced has to go into nNonFiredPool so +# nNonFiredPool isn't empty """ +# push!(nNonFiredPool, n.subscriptionList[connIndex]) + +# if length(nFiredPool) != 0 +# newConn = popfirst!(nFiredPool) +# else +# newConn = popfirst!(nNonFiredPool) +# end +# n.subscriptionList[connIndex] = newConn +# n.wRec[connIndex] = w[i] * nExInTypeList[newConn] +# n.synapticStrength[connIndex] = synapticStrength[i] +# end +# end +# end + function neuroplasticity!(n::computeNeuron, firedNeurons::Vector, nExInTypeList::Vector) # if there is 0-weight then replace it with new connection @@ -346,14 +383,14 @@ function neuroplasticity!(n::computeNeuron, firedNeurons::Vector, """ conn that is being replaced has to go into nNonFiredPool so nNonFiredPool isn't empty """ push!(nNonFiredPool, n.subscriptionList[connIndex]) - - if length(nFiredPool) != 0 - newConn = popfirst!(nFiredPool) + pool = GeneralUtils.randomChoiceWithProb([nFiredPool, nNonFiredPool],[0.5, 0.5]) + if length(pool) != 0 + newConn = popfirst!(pool) else newConn = popfirst!(nNonFiredPool) end n.subscriptionList[connIndex] = newConn - n.wRec[connIndex] = w[i] #* nExInTypeList[newConn] + n.wRec[connIndex] = w[i] * nExInTypeList[newConn] n.synapticStrength[connIndex] = synapticStrength[i] end end