add neuroplasticity
This commit is contained in:
104
src/snn_utils.jl
104
src/snn_utils.jl
@@ -36,7 +36,7 @@ reset_epsilonRec!(n::computeNeuron) = n.epsilonRec = n.epsilonRec * 0.0
|
||||
reset_epsilonRec!(n::outputNeuron) = n.epsilonRec = n.epsilonRec * 0.0
|
||||
reset_epsilonRecA!(n::alifNeuron) = n.epsilonRecA = n.epsilonRecA * 0.0
|
||||
reset_epsilon_in!(n::computeNeuron) = n.epsilon_in = isnothing(n.epsilon_in) ? nothing : n.epsilon_in * 0.0
|
||||
reset_error!(n::Union{computeNeuron, linearNeuron}) = n.error = nothing
|
||||
reset_error!(n::Union{computeNeuron, outputNeuron}) = n.error = nothing
|
||||
reset_w_in_change!(n::computeNeuron) = n.w_in_change = isnothing(n.w_in_change) ? nothing : n.w_in_change * 0.0
|
||||
reset_wRecChange!(n::Union{computeNeuron, outputNeuron}) = n.wRecChange = n.wRecChange * 0.0
|
||||
reset_a!(n::alifNeuron) = n.a = n.a * 0.0
|
||||
@@ -44,7 +44,7 @@ reset_reg_voltage_a!(n::computeNeuron) = n.reg_voltage_a = n.reg_voltage_a * 0.0
|
||||
reset_reg_voltage_b!(n::computeNeuron) = n.reg_voltage_b = n.reg_voltage_b * 0.0
|
||||
reset_reg_voltage_error!(n::computeNeuron) = n.reg_voltage_error = n.reg_voltage_error * 0.0
|
||||
reset_firing_counter!(n::Union{computeNeuron, outputNeuron}) = n.firingCounter = n.firingCounter * 0.0
|
||||
reset_firing_diff!(n::Union{computeNeuron, linearNeuron}) = n.firingDiff = n.firingDiff * 0.0
|
||||
reset_firing_diff!(n::Union{computeNeuron, outputNeuron}) = n.firingDiff = n.firingDiff * 0.0
|
||||
reset_refractoryCounter!(n::Union{computeNeuron, outputNeuron}) = n.refractoryCounter = n.refractoryCounter * 0.0
|
||||
reset_z_i_t_commulative!(n::Union{computeNeuron, outputNeuron}) = n.z_i_t_commulative = n.z_i_t_commulative * 0.0
|
||||
|
||||
@@ -304,31 +304,6 @@ end
|
||||
|
||||
function synapticConnStrength!(n::inputNeuron) end
|
||||
|
||||
function neuroplasticity!(n::computeNeuron, firedNeurons::Vector)
|
||||
# if there is 0-weight then replace it with new connection
|
||||
zero_weight_index = findall(iszero.(n.wRec))
|
||||
if length(zero_weight_index) != 0
|
||||
""" sampling new connection from list of neurons that fires instead of ramdom choose from
|
||||
all compute neuron because there is no point to connect to neuron that not fires i.e.
|
||||
not fire = no information
|
||||
"""
|
||||
|
||||
subscribe_options = filter(x -> x ∉ [n.id], firedNeurons) # exclude this neuron id from the list
|
||||
filter!(x -> x ∉ n.subscriptionList, subscribe_options) # exclude this neuron's subscriptionList from the list
|
||||
shuffle!(subscribe_options)
|
||||
end
|
||||
|
||||
new_connection_percent = 10 - ((n.optimiser.eta / 0.0001) / 10) # percent is in range 0.1 to 10
|
||||
percentage = [new_connection_percent, 100.0 - new_connection_percent] / 100.0
|
||||
for i in zero_weight_index
|
||||
if Utils.random_choices([true, false], percentage)
|
||||
n.subscriptionList[i] = pop!(subscribe_options)
|
||||
n.wRec[i] = 0.01 # new connection should not send large signal otherwise it would throw
|
||||
# RSNN off path. Let weight grow by an optimiser
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
""" normalize a part of a vector centering at a vector's maximum value along with nearby value
|
||||
within its radius. radius must be odd number.
|
||||
v1 will be normalized based on v2's peak
|
||||
@@ -343,10 +318,85 @@ function normalizePeak!(v1::Vector, v2::Vector, radius::Integer=2)
|
||||
normalize!(subvector, 1)
|
||||
end
|
||||
|
||||
""" rewire of neuron synaptic connection that has 0 weight. With connection's excitatory and
|
||||
inhabitory ratio constraint.
|
||||
"""
|
||||
# function neuroplasticity!(n::Union{computeNeuron, outputNeuron}, firedNeurons::Vector,
|
||||
# nExcitatory::Vector, nInhabitory::Vector, excitatoryPercent::Integer)
|
||||
# # if there is 0-weight then replace it with new connection
|
||||
# zeroWeightConnIndex = findall(iszero.(n.wRec)) # connection that has 0 weight
|
||||
# desiredEx = Int(floor((excitatoryPercent / 100) * length(n.subscriptionList)))
|
||||
# desiredIn = length(n.subscriptionList) - desiredEx
|
||||
# wRecSign = sign.(n.wRec)
|
||||
# inConn = sum(isequal.(wRecSign, -1))
|
||||
|
||||
# # random new synaptic connection
|
||||
# inConnToAdd = desiredIn - inConn
|
||||
# if inConnToAdd <= 0
|
||||
# # skip all new Conn will be excitatory type
|
||||
# else
|
||||
# newConnVecSign = ones(length(zeroWeightConnIndex))
|
||||
# newConnVecSign = view(newConnVecSign, 1:inConnToAdd) * -1
|
||||
# end
|
||||
|
||||
# # new synaptic connection must sample fron neuron that fires
|
||||
# inPool = nInhabitory ∩ firedNeurons
|
||||
# filter!(x -> x ∉ [n.id], inPool) # exclude this neuron id from the list
|
||||
# filter!(x -> x ∉ n.subscriptionList, inPool) # exclude this neuron's subscriptionList from the list
|
||||
# exPool = nExcitatory ∩ firedNeurons
|
||||
# filter!(x -> x ∉ [n.id], exPool) # exclude this neuron id from the list
|
||||
# filter!(x -> x ∉ n.subscriptionList, exPool) # exclude this neuron's subscriptionList from the list
|
||||
|
||||
# w = [rand(0.01:0.01:0.2, length(zeroWeightConnIndex))] .* newConnVecSign
|
||||
# synapticStrength = [rand(-5:0.01:-4, length(zeroWeightConnIndex))]
|
||||
|
||||
# # add new synaptic connection to neuron
|
||||
# for (i, connIndex) in enumerate(zeroWeightConnIndex)
|
||||
# n.subscriptionList[connIndex] = newConnVecSign[i] < 0 ? pop!(inPool) : pop!(exPool)
|
||||
# n.wRec[connIndex] = w[i]
|
||||
# n.synapticStrength[connIndex] = synapticStrength[i]
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
""" rewire of neuron synaptic connection that has 0 weight. Without connection's excitatory and
|
||||
inhabitory ratio constraint.
|
||||
"""
|
||||
function neuroplasticity!(n::Union{computeNeuron, outputNeuron}, 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
|
||||
|
||||
# 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 = rand(0.01:0.01:0.2, length(zeroWeightConnIndex))
|
||||
synapticStrength = rand(-5:0.01:-4, length(zeroWeightConnIndex))
|
||||
|
||||
shuffle!(nFiredPool)
|
||||
shuffle!(nNonFiredPool)
|
||||
|
||||
# add new synaptic connection to neuron
|
||||
for (i, connIndex) in enumerate(zeroWeightConnIndex)
|
||||
if length(nFiredPool) != 0
|
||||
newConn = popfirst!(nFiredPool)
|
||||
else
|
||||
newConn = popfirst!(nNonFiredPool)
|
||||
end
|
||||
|
||||
""" conn that is being replaced has to go into nNonFiredPool so nNonFiredPool isn't empty
|
||||
"""
|
||||
push!(nNonFiredPool, n.subscriptionList[connIndex])
|
||||
n.subscriptionList[connIndex] = newConn
|
||||
n.wRec[connIndex] = w[i] * nExInTypeList[newConn]
|
||||
n.synapticStrength[connIndex] = synapticStrength[i]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user