From a114935b2dbbed67bec3f89970c0f0d85a8722ee Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Wed, 17 May 2023 15:55:25 +0700 Subject: [PATCH] bug fix --- src/forward.jl | 7 ++++--- src/learn.jl | 9 ++++----- src/types.jl | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/forward.jl b/src/forward.jl index 8e62121..ea55d44 100644 --- a/src/forward.jl +++ b/src/forward.jl @@ -52,6 +52,7 @@ function (kfn::kfn_1)(m::model, input_data::AbstractVector) kfn.firedNeurons_t1 = Vector{Bool}() kfn.learningStage = "learning" + m.learningStage = kfn.learningStage end # generate noise @@ -131,7 +132,7 @@ function (n::lifNeuron)(kfn::knowledgeFn) 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) + n.v_t1 = no_negative!(n.v_t1) if n.v_t1 > n.v_th 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.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) + n.v_t1 = no_negative!(n.v_t1) if n.v_t1 > n.av_th n.z_t1 = true 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.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 n.z_t1 = true diff --git a/src/learn.jl b/src/learn.jl index ef0bea8..db303fc 100644 --- a/src/learn.jl +++ b/src/learn.jl @@ -11,7 +11,6 @@ export learn! #------------------------------------------------------------------------------------------------100 function learn!(m::model, modelRespond, correctAnswer=nothing) - m.knowledgeFn[:I].learningStage = m.learningStage if correctAnswer === nothing correctAnswer_I = zeros(length(modelRespond)) else @@ -84,7 +83,7 @@ end """ passthroughNeuron learn() """ -function learn!(n::passthroughNeuron, kfn::knowledgeFn) +function learn!(n::passthroughNeuron, error::Number) # skip end @@ -94,7 +93,7 @@ function learn!(n::lifNeuron, error::Number) n.eRec = n.phi * n.epsilonRec ΔwRecChange = n.eta * error * n.eRec - n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange + n.wRecChange .+= ΔwRecChange reset_epsilonRec!(n) end @@ -106,7 +105,7 @@ function learn!(n::alifNeuron, error::Number) n.eRec = n.eRec_v + n.eRec_a ΔwRecChange = n.eta * error * n.eRec - n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange + n.wRecChange .+= ΔwRecChange reset_epsilonRec!(n) reset_epsilonRecA!(n) end @@ -117,7 +116,7 @@ function learn!(n::linearNeuron, error::Number) n.eRec = n.phi * n.epsilonRec ΔwRecChange = n.eta * error * n.eRec - n.wRecChange = (n.subExInType * n.wRecChange) + ΔwRecChange + n.wRecChange .+= ΔwRecChange reset_epsilonRec!(n) end diff --git a/src/types.jl b/src/types.jl index eb3ecef..62d6d70 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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 type::String = "lifNeuron" 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 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 @@ -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 type::String = "alifNeuron" 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 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