add neuroplasticity
This commit is contained in:
49
src/types.jl
49
src/types.jl
@@ -111,6 +111,10 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
|
||||
avgNeuronsFiringRate::Union{Float64,Nothing} = 0.0 # for displaying average firing rate over all neurons
|
||||
avgNeurons_v_t1::Union{Float64,Nothing} = 0.0 # for displaying average v_t1 over all neurons
|
||||
nExcitatory::Union{Array,Nothing} = Vector{Integer}() # list of excitatory neuron id
|
||||
nInhabitory::Union{Array,Nothing} = Vector{Integer}() # list of inhabitory neuron id
|
||||
nExInType::Union{Array,Nothing} = Vector{Integer}() # list all neuron EX or IN
|
||||
excitatoryPercent::Integer = 60 # percentage of excitatory neuron, inhabitory percent will be 100-ExcitatoryPercent
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
@@ -229,7 +233,7 @@ function kfn_1(kfnParams::Dict)
|
||||
end
|
||||
|
||||
# excitatory neuron to inhabitory neuron = 60:40 % of computeNeuron
|
||||
ex_number = Int(floor(0.6 * kfn.kfnParams[:computeNeuronNumber]))
|
||||
ex_number = Int(floor((kfn.excitatoryPercent/100.0) * kfn.kfnParams[:computeNeuronNumber]))
|
||||
ex_n = [1 for i in 1:ex_number]
|
||||
in_number = kfn.kfnParams[:computeNeuronNumber] - ex_number
|
||||
in_n = [-1 for i in 1:in_number]
|
||||
@@ -237,17 +241,22 @@ function kfn_1(kfnParams::Dict)
|
||||
|
||||
# input neurons are always excitatory, compute_neurons are random between excitatory
|
||||
# and inhabitory
|
||||
for n in reverse(kfn.neuronsArray)
|
||||
for n in kfn.neuronsArray
|
||||
try n.ExInType = pop!(ex_in) catch end
|
||||
end
|
||||
|
||||
# add ExInType into each computeNeuron subExInType
|
||||
for n in reverse(kfn.neuronsArray)
|
||||
for n in kfn.neuronsArray
|
||||
try # input neuron doest have n.subscriptionList
|
||||
for (i, sub_id) in enumerate(n.subscriptionList)
|
||||
n_ExInType = kfn.neuronsArray[sub_id].ExInType
|
||||
# push!(n.subExInType, n_ExInType)
|
||||
n.wRec[i] *= n_ExInType
|
||||
# add id exin type to kfn
|
||||
if n_ExInType < 0
|
||||
push!(kfn.nInhabitory, sub_id)
|
||||
else
|
||||
push!(kfn.nExcitatory, sub_id)
|
||||
end
|
||||
end
|
||||
catch
|
||||
end
|
||||
@@ -258,13 +267,16 @@ function kfn_1(kfnParams::Dict)
|
||||
try # input neuron doest have n.subscriptionList
|
||||
for (i, sub_id) in enumerate(n.subscriptionList)
|
||||
n_ExInType = kfn.neuronsArray[sub_id].ExInType
|
||||
# push!(n.subExInType, n_ExInType)
|
||||
n.wRec[i] *= n_ExInType
|
||||
end
|
||||
catch
|
||||
end
|
||||
end
|
||||
|
||||
for n in kfn.neuronsArray
|
||||
push!(kfn.nExInType, n.ExInType)
|
||||
end
|
||||
|
||||
return kfn
|
||||
end
|
||||
|
||||
@@ -457,7 +469,6 @@ Base.@kwdef mutable struct alifNeuron <: computeNeuron
|
||||
reset epsilon_j.
|
||||
"reflect" = neuron will merge wRecChange into wRec then reset wRecChange. """
|
||||
learningStage::String = "inference"
|
||||
|
||||
end
|
||||
""" alif neuron outer constructor
|
||||
|
||||
@@ -604,10 +615,10 @@ end
|
||||
# n.id = id
|
||||
# n.knowledgeFnName = kfnParams[:knowledgeFnName]
|
||||
# subscription_options = shuffle!([1:(kfnParams[:input_neuron_number]+kfnParams[:computeNeuronNumber])...])
|
||||
# if typeof(kfnParams[:synaptic_connection_number]) == String
|
||||
# percent = parse(Int, kfnParams[:synaptic_connection_number][1:end-1]) / 100
|
||||
# synaptic_connection_number = floor(length(subscription_options) * percent)
|
||||
# n.subscriptionList = [pop!(subscription_options) for i = 1:synaptic_connection_number]
|
||||
# if typeof(kfnParams[:synapticConnectionPercent]) == String
|
||||
# percent = parse(Int, kfnParams[:synapticConnectionPercent][1:end-1]) / 100
|
||||
# synapticConnectionPercent = floor(length(subscription_options) * percent)
|
||||
# n.subscriptionList = [pop!(subscription_options) for i = 1:synapticConnectionPercent]
|
||||
# end
|
||||
# filter!(x -> x != n.id, n.subscriptionList)
|
||||
# n.epsilonRec = zeros(length(n.subscriptionList))
|
||||
@@ -621,13 +632,13 @@ function init_neuron!(id::Int64, n::lifNeuron, n_params::Dict, kfnParams::Dict)
|
||||
n.id = id
|
||||
n.knowledgeFnName = kfnParams[:knowledgeFnName]
|
||||
subscription_options = shuffle!([1:kfnParams[:totalNeurons]...])
|
||||
subscription_numbers = Int(floor(n_params[:synaptic_connection_number] *
|
||||
kfnParams[:totalNeurons] / 100.0))
|
||||
subscription_numbers = Int(floor((n_params[:synapticConnectionPercent] / 100.0) *
|
||||
kfnParams[:totalNeurons]))
|
||||
n.subscriptionList = [pop!(subscription_options) for i = 1:subscription_numbers]
|
||||
|
||||
# prevent subscription to itself by removing this neuron id
|
||||
filter!(x -> x != n.id, n.subscriptionList)
|
||||
n.synapticStrength = rand(-5:0.1:-3, length(n.subscriptionList))
|
||||
n.synapticStrength = rand(-5:0.01:-4, length(n.subscriptionList))
|
||||
|
||||
n.epsilonRec = zeros(length(n.subscriptionList))
|
||||
n.wRec = rand(-0.2:0.01:0.2, length(n.subscriptionList))
|
||||
@@ -641,13 +652,13 @@ function init_neuron!(id::Int64, n::alifNeuron, n_params::Dict,
|
||||
n.id = id
|
||||
n.knowledgeFnName = kfnParams[:knowledgeFnName]
|
||||
subscription_options = shuffle!([1:kfnParams[:totalNeurons]...])
|
||||
subscription_numbers = Int(floor(n_params[:synaptic_connection_number] *
|
||||
kfnParams[:totalNeurons] / 100.0))
|
||||
subscription_numbers = Int(floor((n_params[:synapticConnectionPercent] / 100.0) *
|
||||
kfnParams[:totalNeurons]))
|
||||
n.subscriptionList = [pop!(subscription_options) for i = 1:subscription_numbers]
|
||||
|
||||
# prevent subscription to itself by removing this neuron id
|
||||
filter!(x -> x != n.id, n.subscriptionList)
|
||||
n.synapticStrength = rand(-5:0.1:-3, length(n.subscriptionList))
|
||||
n.synapticStrength = rand(-5:0.01:-4, length(n.subscriptionList))
|
||||
|
||||
n.epsilonRec = zeros(length(n.subscriptionList))
|
||||
n.wRec = rand(-0.2:0.01:0.2, length(n.subscriptionList))
|
||||
@@ -667,10 +678,10 @@ function init_neuron!(id::Int64, n::linearNeuron, n_params::Dict, kfnParams::Dic
|
||||
n.knowledgeFnName = kfnParams[:knowledgeFnName]
|
||||
|
||||
subscription_options = shuffle!([kfnParams[:totalInputPort]+1 : kfnParams[:totalNeurons]...])
|
||||
subscription_numbers = Int(floor(n_params[:synaptic_connection_number] *
|
||||
kfnParams[:totalComputeNeuron] / 100.0))
|
||||
subscription_numbers = Int(floor((n_params[:synapticConnectionPercent] / 100.0) *
|
||||
kfnParams[:totalNeurons]))
|
||||
n.subscriptionList = [pop!(subscription_options) for i = 1:subscription_numbers]
|
||||
n.synapticStrength = rand(-5:0.1:-3, length(n.subscriptionList))
|
||||
n.synapticStrength = rand(-5:0.01:-4, length(n.subscriptionList))
|
||||
|
||||
n.epsilonRec = zeros(length(n.subscriptionList))
|
||||
n.wRec = rand(-0.2:0.01:0.2, length(n.subscriptionList))
|
||||
|
||||
Reference in New Issue
Block a user