fix algo
This commit is contained in:
19
src/type.jl
19
src/type.jl
@@ -21,6 +21,7 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
|
||||
timeStep::Union{AbstractArray, Nothing} = nothing
|
||||
learningStage::Union{AbstractArray, Nothing} = nothing # 0 inference, 1 start, 2 during, 3 end learning
|
||||
inputSize::Union{AbstractArray, Nothing} = nothing
|
||||
zit::Union{AbstractArray, Nothing} = nothing # 3D activation matrix
|
||||
modelError::Union{AbstractArray, Nothing} = nothing # store RSNN error
|
||||
outputError::Union{AbstractArray, Nothing} = nothing # store output neurons error
|
||||
@@ -50,6 +51,7 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
lif_gammaPd::Union{AbstractArray, Nothing} = nothing
|
||||
lif_wRecChange::Union{AbstractArray, Nothing} = nothing
|
||||
lif_error::Union{AbstractArray, Nothing} = nothing
|
||||
lif_subscription::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
lif_firingCounter::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
@@ -85,6 +87,7 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
alif_gammaPd::Union{AbstractArray, Nothing} = nothing
|
||||
alif_wRecChange::Union{AbstractArray, Nothing} = nothing
|
||||
alif_error::Union{AbstractArray, Nothing} = nothing
|
||||
alif_subscription::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
alif_firingCounter::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
@@ -137,6 +140,7 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
on_gammaPd::Union{AbstractArray, Nothing} = nothing
|
||||
on_wOutChange::Union{AbstractArray, Nothing} = nothing
|
||||
on_error::Union{AbstractArray, Nothing} = nothing
|
||||
on_subscription::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
on_firingCounter::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
@@ -162,8 +166,8 @@ function kfn_1(params::Dict; device=cpu)
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# row*col is a 2D matrix represent all RSNN activation
|
||||
row, col, batch = kfn.params[:inputPort][:signal][:numbers] # z-axis represent signal batch number
|
||||
# row += kfn.params[:inputPort][:noise][:numbers][1]
|
||||
col += kfn.params[:inputPort][:noise][:numbers][2]
|
||||
kfn.inputSize = [row, col] |> device
|
||||
col += kfn.params[:computeNeuron][:lif][:numbers][2]
|
||||
col += kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
|
||||
@@ -208,6 +212,7 @@ function kfn_1(params::Dict; device=cpu)
|
||||
kfn.lif_gammaPd = (similar(kfn.lif_wRec) .= 0.3) |> device
|
||||
kfn.lif_wRecChange = (similar(kfn.lif_wRec) .= 0) |> device
|
||||
kfn.lif_error = (similar(kfn.lif_wRec) .= 0) |> device
|
||||
kfn.lif_subscription = (GeneralUtils.isNotEqual.(kfn.lif_wRec, 0)) |> device
|
||||
|
||||
kfn.lif_firingCounter = (similar(kfn.lif_wRec) .= 0) |> device
|
||||
|
||||
@@ -254,6 +259,7 @@ function kfn_1(params::Dict; device=cpu)
|
||||
kfn.alif_gammaPd = (similar(kfn.alif_wRec) .= 0.3) |> device
|
||||
kfn.alif_wRecChange = (similar(kfn.alif_wRec) .= 0) |> device
|
||||
kfn.alif_error = (similar(kfn.alif_wRec) .= 0) |> device
|
||||
kfn.alif_subscription = (GeneralUtils.isNotEqual.(kfn.alif_wRec, 0)) |> device
|
||||
|
||||
kfn.alif_firingCounter = (similar(kfn.alif_wRec) .= 0) |> device
|
||||
|
||||
@@ -286,9 +292,13 @@ function kfn_1(params::Dict; device=cpu)
|
||||
# subscription
|
||||
w = zeros(row, col, n)
|
||||
synapticConnectionPercent = kfn.params[:outputPort][:params][:synapticConnectionPercent]
|
||||
synapticConnection = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
for slice in eachslice(w, dims=3)
|
||||
pool = shuffle!([1:row*col...])[1:synapticConnection]
|
||||
subable = size(kfn.lif_wRec, 3) + size(kfn.alif_wRec, 3) # sub to lif, alif only
|
||||
synapticConnection = Int(floor(subable * synapticConnectionPercent/100))
|
||||
for slice in eachslice(w, dims=3) # each slice is a neuron
|
||||
startInd = row*col - subable + 1 # e.g. 100(row*col) - 50(subable) = 50 -> startInd = 51
|
||||
|
||||
# pool must contain only lif, alif neurons
|
||||
pool = shuffle!([startInd:row*col...])[1:synapticConnection]
|
||||
for i in pool
|
||||
slice[i] = randn()/10 # assign weight to synaptic connection
|
||||
end
|
||||
@@ -313,6 +323,7 @@ function kfn_1(params::Dict; device=cpu)
|
||||
kfn.on_gammaPd = (similar(kfn.on_wOut) .= 0.3) |> device
|
||||
kfn.on_wOutChange = (similar(kfn.on_wOut) .= 0) |> device
|
||||
kfn.on_error = (similar(kfn.on_wOut) .= 0) |> device
|
||||
kfn.on_subscription = (GeneralUtils.isNotEqual.(kfn.on_wOut, 0)) |> device
|
||||
|
||||
kfn.on_firingCounter = (similar(kfn.on_wOut) .= 0) |> device
|
||||
|
||||
|
||||
Reference in New Issue
Block a user