building forwared()
This commit is contained in:
103
src/type.jl
103
src/type.jl
@@ -20,16 +20,35 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
params::Dict = Dict() # store params of knowledgeFn itself for later use
|
||||
|
||||
timeStep::AbstractArray = [0]
|
||||
refractory::Union{AbstractArray, Nothing} = nothing
|
||||
learningStage::AbstractArray = [0] # 0 inference, 1 start, 2 during, 3 end learning
|
||||
z_i_t1::Union{AbstractArray, Nothing} = nothing # 2D activation matrix
|
||||
z_i_t0::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
# LIF
|
||||
lif_w::Union{AbstractArray, Nothing} = nothing
|
||||
lif_recSignal::Union{AbstractArray, Nothing} = nothing
|
||||
lif_vt0::Union{AbstractArray, Nothing} = nothing
|
||||
lif_vt1::Union{AbstractArray, Nothing} = nothing
|
||||
lif_vth::Union{AbstractArray, Nothing} = nothing
|
||||
lif_zt0::Union{AbstractArray, Nothing} = nothing
|
||||
lif_zt1::Union{AbstractArray, Nothing} = nothing
|
||||
lif_refractoryCounter::Union{AbstractArray, Nothing} = nothing
|
||||
lif_refractoryActive::Union{AbstractArray, Nothing} = nothing
|
||||
lif_refractoryInactive::Union{AbstractArray, Nothing} = nothing
|
||||
lif_alpha::Union{AbstractArray, Nothing} = nothing
|
||||
lif_delta::AbstractFloat = 1.0
|
||||
lif_tau_m::AbstractFloat = 20.0
|
||||
|
||||
# ALIF
|
||||
alif_w::Union{AbstractArray, Nothing} = nothing
|
||||
alif_recSignal::Union{AbstractArray, Nothing} = nothing
|
||||
alif_zt0::Union{AbstractArray, Nothing} = nothing
|
||||
alif_zt1::Union{AbstractArray, Nothing} = nothing
|
||||
alif_refractoryCounter::Union{AbstractArray, Nothing} = nothing
|
||||
alif_refractoryActive::Union{AbstractArray, Nothing} = nothing
|
||||
alif_refractoryInactive::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
|
||||
end
|
||||
|
||||
# outer constructor
|
||||
@@ -43,20 +62,25 @@ function kfn_1(params::Dict)
|
||||
col += kfn.params[:computeNeuron][:lif][:numbers][2]
|
||||
col += kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
|
||||
kfn.z_i_t1 = zeros(row, col, batch)
|
||||
kfn.z_i_t0 = zeros(row, col, batch)
|
||||
# activation matrix
|
||||
kfn.z_i_t0 = zeros(row, col, batch)
|
||||
kfn.z_i_t1 = zeros(row, col, batch)
|
||||
|
||||
# LIF
|
||||
z = kfn.params[:computeNeuron][:lif][:numbers][1] * kfn.params[:computeNeuron][:lif][:numbers][2]
|
||||
kfn.lif_w = zeros(row, col, z) # matrix z-axis represent each neurons
|
||||
kfn.lif_recSignal = zeros(row, col, z, batch)
|
||||
kfn.lif_recSignal = zeros(1, 1, z, batch)
|
||||
kfn.lif_vt0 = zeros(1, 1, z, batch)
|
||||
kfn.lif_vt1 = zeros(1, 1, z, batch)
|
||||
kfn.lif_vth = ones(1, 1, z, batch)
|
||||
kfn.lif_zt0 = zeros(1, 1, z, batch)
|
||||
kfn.lif_zt1 = zeros(1, 1, z, batch)
|
||||
kfn.lif_refractoryCounter = zeros(1, 1, z, batch)
|
||||
kfn.lif_refractoryActive = zeros(1, 1, z, batch)
|
||||
kfn.lif_refractoryInactive = zeros(1, 1, z, batch)
|
||||
kfn.lif_alpha = ones(1, 1, z, batch) .* (exp(-kfn.lif_delta / kfn.lif_tau_m))
|
||||
|
||||
# ALIF
|
||||
z = kfn.params[:computeNeuron][:alif][:numbers][1] * kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
kfn.alif_w = zeros(row, col, z)
|
||||
kfn.alif_recSignal = zeros(row, col, z, batch)
|
||||
|
||||
# lif subscription
|
||||
# subscription
|
||||
row, col, _ = size(kfn.lif_w) # row*col is synaptic subscribe weight for each neuron in z-axis
|
||||
synapticConnectionPercent = kfn.params[:computeNeuron][:lif][:params][:synapticConnectionPercent]
|
||||
synapticConnection = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
@@ -67,7 +91,17 @@ function kfn_1(params::Dict)
|
||||
end
|
||||
end
|
||||
|
||||
# alif subscription
|
||||
# ALIF
|
||||
z = kfn.params[:computeNeuron][:alif][:numbers][1] * kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
kfn.alif_w = zeros(row, col, z)
|
||||
kfn.alif_recSignal = zeros(1, 1, z, batch)
|
||||
kfn.alif_zt0 = zeros(1, 1, z, batch)
|
||||
kfn.alif_zt1 = zeros(1, 1, z, batch)
|
||||
kfn.alif_refractoryCounter = zeros(1, 1, z, batch)
|
||||
kfn.alif_refractoryActive = zeros(1, 1, z, batch)
|
||||
kfn.alif_refractoryInactive = zeros(1, 1, z, batch)
|
||||
|
||||
# subscription
|
||||
row, col, _ = size(kfn.alif_w) # row*col is synaptic subscribe weight for each neuron in z-axis
|
||||
synapticConnectionPercent = kfn.params[:computeNeuron][:alif][:params][:synapticConnectionPercent]
|
||||
synapticConnection = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
@@ -92,53 +126,6 @@ function kfn_1(params::Dict)
|
||||
return kfn
|
||||
end
|
||||
|
||||
# kfn forward
|
||||
function (kfn::kfn_1)(input::AbstractArray)
|
||||
kfn.timeStep .+= 1
|
||||
|
||||
# time step forward
|
||||
|
||||
|
||||
|
||||
# row, col = size(input) # if input is a 2D matrix
|
||||
println(">>> 1 ", size(input))
|
||||
println(">>> 2 ", size(kfn.z_i_t1))
|
||||
|
||||
# multiply input with kfn.z_i_t1 may be using cartesian coordinates
|
||||
GeneralUtils.cartesianAssign!(kfn.z_i_t1, input)
|
||||
println(">>> 3 ", sum(kfn.z_i_t1))
|
||||
println(">>> 4 ", size(kfn.lif_recSignal))
|
||||
println(">>> 5 ", size(kfn.lif_w))
|
||||
kfn.lif_recSignal .= GeneralUtils.batchMatEleMul(kfn.z_i_t1, kfn.lif_w)
|
||||
kfn.alif_recSignal .= GeneralUtils.batchMatEleMul(kfn.z_i_t1, kfn.alif_w)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
error("debug end kfn forward")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user