minor fix

This commit is contained in:
ton
2023-07-05 10:53:06 +07:00
parent 4e23fc4d69
commit 4d7a3d5d5a
2 changed files with 45 additions and 7 deletions

View File

@@ -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 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 nonFlipedSign = isequal.(wSign_0, wSign_1) # 1 not fliped, 0 fliped
# normalize wRec peak to prevent input signal overwhelming neuron # normalize wRec peak to prevent input signal overwhelming neuron
# if sum(n.wRecChange) != 0 if sum(n.wRecChange) != 0
# normalizePeak!(n.wRec, n.wRecChange, 2) normRadius = Int(floor(0.1 * length(n.subscriptionList)))
# end normalizePeak!(n.wRec, n.wRecChange, normRadius)
end
# set weight that fliped sign to 0 for random new connection # set weight that fliped sign to 0 for random new connection
n.wRec .*= nonFlipedSign n.wRec .*= nonFlipedSign

View File

@@ -322,6 +322,43 @@ end
""" rewire of neuron synaptic connection that has 0 weight. Without connection's excitatory and """ rewire of neuron synaptic connection that has 0 weight. Without connection's excitatory and
inhabitory ratio constraint. 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, function neuroplasticity!(n::computeNeuron, firedNeurons::Vector,
nExInTypeList::Vector) nExInTypeList::Vector)
# if there is 0-weight then replace it with new connection # 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 """ conn that is being replaced has to go into nNonFiredPool so
nNonFiredPool isn't empty """ nNonFiredPool isn't empty """
push!(nNonFiredPool, n.subscriptionList[connIndex]) push!(nNonFiredPool, n.subscriptionList[connIndex])
pool = GeneralUtils.randomChoiceWithProb([nFiredPool, nNonFiredPool],[0.5, 0.5])
if length(nFiredPool) != 0 if length(pool) != 0
newConn = popfirst!(nFiredPool) newConn = popfirst!(pool)
else else
newConn = popfirst!(nNonFiredPool) newConn = popfirst!(nNonFiredPool)
end end
n.subscriptionList[connIndex] = newConn n.subscriptionList[connIndex] = newConn
n.wRec[connIndex] = w[i] #* nExInTypeList[newConn] n.wRec[connIndex] = w[i] * nExInTypeList[newConn]
n.synapticStrength[connIndex] = synapticStrength[i] n.synapticStrength[connIndex] = synapticStrength[i]
end end
end end