bug fix
This commit is contained in:
@@ -128,7 +128,7 @@ function (n::lifNeuron)(kfn::knowledgeFn)
|
||||
# decay of v_t1
|
||||
n.v_t1 = n.alpha * n.v_t
|
||||
else
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t .* n.subExInType) # signal from other neuron that this neuron subscribed
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t) # signal from other neuron that this neuron subscribed
|
||||
|
||||
n.alpha_v_t = n.alpha * n.v_t
|
||||
n.v_t1 = n.alpha_v_t + n.recSignal
|
||||
@@ -174,7 +174,7 @@ function (n::alifNeuron)(kfn::knowledgeFn)
|
||||
n.z_t = isnothing(n.z_t) ? false : n.z_t
|
||||
n.a = (n.rho * n.a) + ((1 - n.rho) * n.z_t)
|
||||
n.av_th = n.v_th + (n.beta * n.a)
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t .* n.subExInType) # signal from other neuron that this neuron subscribed
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t) # signal from other neuron that this neuron subscribed
|
||||
n.alpha_v_t = n.alpha * n.v_t
|
||||
n.v_t1 = n.alpha_v_t + n.recSignal
|
||||
n.v_t1 = no_negative!(n.v_t1)
|
||||
@@ -218,7 +218,7 @@ function (n::linearNeuron)(kfn::T) where T<:knowledgeFn
|
||||
# decay of v_t1
|
||||
n.v_t1 = n.alpha * n.v_t
|
||||
else
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t .* n.subExInType) # signal from other neuron that this neuron subscribed
|
||||
n.recSignal = sum(n.wRec .* n.z_i_t) # signal from other neuron that this neuron subscribed
|
||||
|
||||
n.alpha_v_t = n.alpha * n.v_t
|
||||
n.v_t1 = n.alpha_v_t + n.recSignal
|
||||
|
||||
22
src/learn.jl
22
src/learn.jl
@@ -42,14 +42,14 @@ function learn!(kfn::kfn_1, correctAnswer::AbstractVector)
|
||||
# wrap up learning session
|
||||
if kfn.learningStage == "end_learning"
|
||||
# Threads.@threads for n in kfn.neuronsArray
|
||||
for n in kfn.neuronsArray
|
||||
for n in kfn.neuronsArray
|
||||
wSign_0 = sign.(n.wRec) # original sign
|
||||
n.wRec += n.wRecChange # merge wRecChange into wRec
|
||||
wSign = sign.(n.wRec) # check for fliped sign, 1 indicates non-fliped sign
|
||||
nonFlipedSign = isequal.(n.subExInType, wSign) # 1 not fliped, 0 fliped
|
||||
LinearAlgebra.normalize!(n.wRec, 1)
|
||||
n.wRec .*= nonFlipedSign # set weight that fliped sign to 0 for random new connection
|
||||
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
|
||||
normalizePeak!(n.wRec, 2)
|
||||
n.wRec .*= nonFlipedSign # set weight that fliped sign to 0 for random new connection
|
||||
|
||||
|
||||
synapticConnStrength!(n)
|
||||
@@ -58,12 +58,12 @@ function learn!(kfn::kfn_1, correctAnswer::AbstractVector)
|
||||
end
|
||||
|
||||
for n in kfn.outputNeuronsArray # merge wRecChange into wRec
|
||||
wSign_0 = sign.(n.wRec) # original sign
|
||||
n.wRec += n.wRecChange
|
||||
wSign = sign.(n.wRec) # check for fliped sign, 1 indicates non-fliped sign
|
||||
nonFlipedSign = isequal.(n.subExInType, wSign) # 1 not fliped, 0 fliped
|
||||
LinearAlgebra.normalize!(n.wRec, 1)
|
||||
n.wRec .*= nonFlipedSign # set weight that fliped sign to 0 for random new connection
|
||||
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
|
||||
normalizePeak!(n.wRec, 2)
|
||||
n.wRec .*= nonFlipedSign # set weight that fliped sign to 0 for random new connection
|
||||
|
||||
synapticConnStrength!(n)
|
||||
#TODO neuroplasticity
|
||||
@@ -91,7 +91,6 @@ end
|
||||
"""
|
||||
function learn!(n::lifNeuron, error::Number)
|
||||
n.eRec = n.phi * n.epsilonRec
|
||||
|
||||
ΔwRecChange = n.eta * error * n.eRec
|
||||
n.wRecChange .+= ΔwRecChange
|
||||
reset_epsilonRec!(n)
|
||||
@@ -103,7 +102,6 @@ function learn!(n::alifNeuron, error::Number)
|
||||
n.eRec_v = n.phi * n.epsilonRec
|
||||
n.eRec_a = -n.phi * n.beta * n.epsilonRecA
|
||||
n.eRec = n.eRec_v + n.eRec_a
|
||||
|
||||
ΔwRecChange = n.eta * error * n.eRec
|
||||
n.wRecChange .+= ΔwRecChange
|
||||
reset_epsilonRec!(n)
|
||||
@@ -114,7 +112,7 @@ end
|
||||
"""
|
||||
function learn!(n::linearNeuron, error::Number)
|
||||
n.eRec = n.phi * n.epsilonRec
|
||||
|
||||
|
||||
ΔwRecChange = n.eta * error * n.eRec
|
||||
n.wRecChange .+= ΔwRecChange
|
||||
reset_epsilonRec!(n)
|
||||
|
||||
@@ -321,7 +321,7 @@ end
|
||||
within its radius. radius must be odd number
|
||||
"""
|
||||
function normalizePeak!(v::Vector, radius::Integer=2)
|
||||
peak = findall(isequal.(n.wRec, maximum(n.wRec)))[1]
|
||||
peak = findall(isequal.(v, maximum(abs.(v))))[1]
|
||||
upindex = peak - radius
|
||||
upindex = upindex < 1 ? 1 : upindex
|
||||
downindex = peak + radius
|
||||
|
||||
16
src/types.jl
16
src/types.jl
@@ -244,9 +244,10 @@ function kfn_1(kfnParams::Dict)
|
||||
# add ExInType into each computeNeuron subExInType
|
||||
for n in reverse(kfn.neuronsArray)
|
||||
try # input neuron doest have n.subscriptionList
|
||||
for sub_id in n.subscriptionList
|
||||
for (i, sub_id) in enumerate(n.subscriptionList)
|
||||
n_ExInType = kfn.neuronsArray[sub_id].ExInType
|
||||
push!(n.subExInType, n_ExInType)
|
||||
# push!(n.subExInType, n_ExInType)
|
||||
n.wRec[i] *= n_ExInType
|
||||
end
|
||||
catch
|
||||
end
|
||||
@@ -255,9 +256,10 @@ function kfn_1(kfnParams::Dict)
|
||||
# add ExInType into each output neuron subExInType
|
||||
for n in kfn.outputNeuronsArray
|
||||
try # input neuron doest have n.subscriptionList
|
||||
for sub_id in n.subscriptionList
|
||||
for (i, sub_id) in enumerate(n.subscriptionList)
|
||||
n_ExInType = kfn.neuronsArray[sub_id].ExInType
|
||||
push!(n.subExInType, n_ExInType)
|
||||
# push!(n.subExInType, n_ExInType)
|
||||
n.wRec[i] *= n_ExInType
|
||||
end
|
||||
catch
|
||||
end
|
||||
@@ -306,7 +308,7 @@ Base.@kwdef mutable struct lifNeuron <: computeNeuron
|
||||
ExInType::Integer = 1 # 1 excitatory, -1 inhabitory
|
||||
knowledgeFnName::Union{String,Nothing} = nothing # knowledgeFn that this neuron belongs to
|
||||
subscriptionList::Union{Array{Int64},Nothing} = nothing # list of other neuron that this neuron synapse subscribed to
|
||||
subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
# subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
timeStep::Number = 0.0 # current time
|
||||
wRec::Union{Array{Float64},Nothing} = nothing # synaptic weight (for receiving signal from other neuron)
|
||||
v_t::Float64 = 0.0 # vᵗ, postsynaptic neuron membrane potential of previous timestep
|
||||
@@ -397,7 +399,7 @@ Base.@kwdef mutable struct alifNeuron <: computeNeuron
|
||||
ExInType::Integer = -1 # 1 excitatory, -1 inhabitory
|
||||
knowledgeFnName::Union{String,Nothing} = nothing # knowledgeFn that this neuron belongs to
|
||||
subscriptionList::Union{Array{Int64},Nothing} = nothing # list of other neuron that this neuron synapse subscribed to
|
||||
subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
# subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
timeStep::Union{Number,Nothing} = nothing # current time
|
||||
wRec::Union{Array{Float64},Nothing} = nothing # synaptic weight (for receiving signal from other neuron)
|
||||
v_t::Float64 = 0.0 # vᵗ, postsynaptic neuron membrane potential of previous timestep
|
||||
@@ -504,7 +506,7 @@ Base.@kwdef mutable struct linearNeuron <: outputNeuron
|
||||
knowledgeFnName::Union{String,Nothing} = nothing # knowledgeFn that this neuron belongs to
|
||||
subscriptionList::Union{Array{Int64},Nothing} = nothing # list of other neuron that this neuron synapse subscribed to
|
||||
timeStep::Union{Number,Nothing} = nothing # current time
|
||||
subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
# subExInType::Array{Int64} = Vector{Int64}() # store ExIn type of subscribed neurons
|
||||
wRec::Union{Array{Float64},Nothing} = nothing # synaptic weight (for receiving signal from other neuron)
|
||||
v_t::Float64 = 0.0 # vᵗ, postsynaptic neuron membrane potential of previous timestep
|
||||
v_t1::Float64 = rand() # vᵗ⁺¹, postsynaptic neuron membrane potential at current timestep
|
||||
|
||||
Reference in New Issue
Block a user