This commit is contained in:
2023-05-17 15:55:25 +07:00
parent 95cad151dc
commit a114935b2d
3 changed files with 8 additions and 10 deletions

View File

@@ -52,6 +52,7 @@ function (kfn::kfn_1)(m::model, input_data::AbstractVector)
kfn.firedNeurons_t1 = Vector{Bool}() kfn.firedNeurons_t1 = Vector{Bool}()
kfn.learningStage = "learning" kfn.learningStage = "learning"
m.learningStage = kfn.learningStage
end end
# generate noise # generate noise
@@ -131,7 +132,7 @@ function (n::lifNeuron)(kfn::knowledgeFn)
n.alpha_v_t = n.alpha * n.v_t n.alpha_v_t = n.alpha * n.v_t
n.v_t1 = n.alpha_v_t + n.recSignal n.v_t1 = n.alpha_v_t + n.recSignal
n.v_t1 = no_negative!.(n.v_t1) n.v_t1 = no_negative!(n.v_t1)
if n.v_t1 > n.v_th if n.v_t1 > n.v_th
n.z_t1 = true n.z_t1 = true
@@ -176,7 +177,7 @@ function (n::alifNeuron)(kfn::knowledgeFn)
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 .* n.subExInType) # signal from other neuron that this neuron subscribed
n.alpha_v_t = n.alpha * n.v_t n.alpha_v_t = n.alpha * n.v_t
n.v_t1 = n.alpha_v_t + n.recSignal n.v_t1 = n.alpha_v_t + n.recSignal
n.v_t1 = no_negative!.(n.v_t1) n.v_t1 = no_negative!(n.v_t1)
if n.v_t1 > n.av_th if n.v_t1 > n.av_th
n.z_t1 = true n.z_t1 = true
n.refractoryCounter = n.refractoryDuration n.refractoryCounter = n.refractoryDuration
@@ -221,7 +222,7 @@ function (n::linearNeuron)(kfn::T) where T<:knowledgeFn
n.alpha_v_t = n.alpha * n.v_t n.alpha_v_t = n.alpha * n.v_t
n.v_t1 = n.alpha_v_t + n.recSignal n.v_t1 = n.alpha_v_t + n.recSignal
n.v_t1 = no_negative!.(n.v_t1) n.v_t1 = no_negative!(n.v_t1)
if n.v_t1 > n.v_th if n.v_t1 > n.v_th
n.z_t1 = true n.z_t1 = true

View File

@@ -11,7 +11,6 @@ export learn!
#------------------------------------------------------------------------------------------------100 #------------------------------------------------------------------------------------------------100
function learn!(m::model, modelRespond, correctAnswer=nothing) function learn!(m::model, modelRespond, correctAnswer=nothing)
m.knowledgeFn[:I].learningStage = m.learningStage
if correctAnswer === nothing if correctAnswer === nothing
correctAnswer_I = zeros(length(modelRespond)) correctAnswer_I = zeros(length(modelRespond))
else else
@@ -84,7 +83,7 @@ end
""" passthroughNeuron learn() """ passthroughNeuron learn()
""" """
function learn!(n::passthroughNeuron, kfn::knowledgeFn) function learn!(n::passthroughNeuron, error::Number)
# skip # skip
end end
@@ -94,7 +93,7 @@ function learn!(n::lifNeuron, error::Number)
n.eRec = n.phi * n.epsilonRec n.eRec = n.phi * n.epsilonRec
ΔwRecChange = n.eta * error * n.eRec ΔwRecChange = n.eta * error * n.eRec
n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange n.wRecChange .+= ΔwRecChange
reset_epsilonRec!(n) reset_epsilonRec!(n)
end end
@@ -106,7 +105,7 @@ function learn!(n::alifNeuron, error::Number)
n.eRec = n.eRec_v + n.eRec_a n.eRec = n.eRec_v + n.eRec_a
ΔwRecChange = n.eta * error * n.eRec ΔwRecChange = n.eta * error * n.eRec
n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange n.wRecChange .+= ΔwRecChange
reset_epsilonRec!(n) reset_epsilonRec!(n)
reset_epsilonRecA!(n) reset_epsilonRecA!(n)
end end
@@ -117,7 +116,7 @@ function learn!(n::linearNeuron, error::Number)
n.eRec = n.phi * n.epsilonRec n.eRec = n.phi * n.epsilonRec
ΔwRecChange = n.eta * error * n.eRec ΔwRecChange = n.eta * error * n.eRec
n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange n.wRecChange .+= ΔwRecChange
reset_epsilonRec!(n) reset_epsilonRec!(n)
end end

View File

@@ -304,7 +304,6 @@ Base.@kwdef mutable struct lifNeuron <: computeNeuron
id::Union{Int64,Nothing} = nothing # this neuron ID i.e. position of this neuron in knowledgeFn id::Union{Int64,Nothing} = nothing # this neuron ID i.e. position of this neuron in knowledgeFn
type::String = "lifNeuron" type::String = "lifNeuron"
ExInType::Integer = 1 # 1 excitatory, -1 inhabitory ExInType::Integer = 1 # 1 excitatory, -1 inhabitory
# Bn::Union{Float64,Nothing} = Random.rand() # Bias for neuron error
knowledgeFnName::Union{String,Nothing} = nothing # knowledgeFn that this neuron belongs to 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 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
@@ -396,7 +395,6 @@ Base.@kwdef mutable struct alifNeuron <: computeNeuron
id::Union{Int64,Nothing} = nothing # this neuron ID i.e. position of this neuron in knowledgeFn id::Union{Int64,Nothing} = nothing # this neuron ID i.e. position of this neuron in knowledgeFn
type::String = "alifNeuron" type::String = "alifNeuron"
ExInType::Integer = -1 # 1 excitatory, -1 inhabitory ExInType::Integer = -1 # 1 excitatory, -1 inhabitory
# Bn::Union{Float64,Nothing} = Random.rand() # Bias for neuron error
knowledgeFnName::Union{String,Nothing} = nothing # knowledgeFn that this neuron belongs to 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 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