building knowledgeFn in GPU format
This commit is contained in:
38
src/type.jl
38
src/type.jl
@@ -21,10 +21,14 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
|
||||
timeStep::AbstractArray = [0]
|
||||
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
|
||||
z_i_t::Union{AbstractArray, Nothing} = nothing # 3D activation matrix
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# LIF #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# a projection of kfn.z_i_t into lif dimension for broadcasting later)
|
||||
lif_z_i_t::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
# LIF
|
||||
lif_w::Union{AbstractArray, Nothing} = nothing
|
||||
lif_recSignal::Union{AbstractArray, Nothing} = nothing
|
||||
lif_vt0::Union{AbstractArray, Nothing} = nothing
|
||||
@@ -39,7 +43,9 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
lif_delta::AbstractFloat = 1.0
|
||||
lif_tau_m::AbstractFloat = 20.0
|
||||
|
||||
# ALIF
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# ALIF #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
alif_w::Union{AbstractArray, Nothing} = nothing
|
||||
alif_recSignal::Union{AbstractArray, Nothing} = nothing
|
||||
alif_zt0::Union{AbstractArray, Nothing} = nothing
|
||||
@@ -55,7 +61,8 @@ end
|
||||
function kfn_1(params::Dict)
|
||||
kfn = kfn_1()
|
||||
kfn.params = params
|
||||
# initialize activation matrix
|
||||
# ----------------------- initialize activation matrix ----------------------- #
|
||||
# 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][:signal][:numbers][2]
|
||||
@@ -63,12 +70,13 @@ function kfn_1(params::Dict)
|
||||
col += kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
|
||||
# activation matrix
|
||||
kfn.z_i_t0 = zeros(row, col, batch)
|
||||
kfn.z_i_t1 = zeros(row, col, batch)
|
||||
kfn.z_i_t = zeros(row, col, batch)
|
||||
|
||||
# LIF
|
||||
# -------------------------------- LIF config -------------------------------- #
|
||||
# In 3D LIF matrix, z-axis represent each neuron while each 2D slice represent that neuron's
|
||||
# synaptic subscription to other neurons (via activation matrix)
|
||||
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(1, 1, z, batch)
|
||||
kfn.lif_vt0 = zeros(1, 1, z, batch)
|
||||
kfn.lif_vt1 = zeros(1, 1, z, batch)
|
||||
@@ -81,19 +89,23 @@ function kfn_1(params::Dict)
|
||||
kfn.lif_alpha = ones(1, 1, z, batch) .* (exp(-kfn.lif_delta / kfn.lif_tau_m))
|
||||
|
||||
# subscription
|
||||
row, col, _ = size(kfn.lif_w) # row*col is synaptic subscribe weight for each neuron in z-axis
|
||||
w = zeros(row, col, z)
|
||||
synapticConnectionPercent = kfn.params[:computeNeuron][:lif][:params][:synapticConnectionPercent]
|
||||
synapticConnection = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
for slice in eachslice(kfn.lif_w, dims=3)
|
||||
for slice in eachslice(w, dims=3)
|
||||
pool = shuffle!([1:row*col...])[1:synapticConnection]
|
||||
for i in pool
|
||||
slice[i] = randn()/10
|
||||
slice[i] = randn()/10 # assign weight to synaptic connection
|
||||
end
|
||||
end
|
||||
#WORKING project 3D w into 4D kfn.lif_w
|
||||
kfn.lif_w = reshape(w, (row, col, z, 1)) .* ones(row, col, z, batch)
|
||||
println(">>> lif_w ", size(kfn.lif_w))
|
||||
error("end WORKING")
|
||||
|
||||
# ALIF
|
||||
z = kfn.params[:computeNeuron][:alif][:numbers][1] * kfn.params[:computeNeuron][:alif][:numbers][2]
|
||||
kfn.alif_w = zeros(row, col, z)
|
||||
kfn.alif_w = zeros(row, col, z) # matrix z-axis represent each neurons
|
||||
kfn.alif_recSignal = zeros(1, 1, z, batch)
|
||||
kfn.alif_zt0 = zeros(1, 1, z, batch)
|
||||
kfn.alif_zt1 = zeros(1, 1, z, batch)
|
||||
|
||||
Reference in New Issue
Block a user