version 0.0.9
This commit is contained in:
@@ -25,11 +25,11 @@ using .interface
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
|
||||
""" version 0.0.7
|
||||
""" version 0.0.9
|
||||
Todo:
|
||||
[] add voltage regulator
|
||||
[] synaptic liquidity range 0 to 100,000 -> 1.0 to 0.99
|
||||
[] add weight liquidity
|
||||
[1] +W 90% of most active conn
|
||||
[2] -W 10% of less active conn
|
||||
|
||||
[-] add temporal summation in addition to already used spatial summation.
|
||||
CANCELLED, spatial summation every second until membrane potential reach a threshold
|
||||
is in itself a temporal summation.
|
||||
@@ -46,6 +46,7 @@ using .interface
|
||||
All features
|
||||
- excitatory/inhabitory matrix
|
||||
- neuroplasticity
|
||||
- voltage regulator
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ function (kfn::kfn_1)(input::AbstractArray)
|
||||
kfn.lif_firingCounter .= 0
|
||||
kfn.lif_refractoryCounter .= 0
|
||||
kfn.lif_zt .= 0
|
||||
kfn.lif_synapticActivityCounter .= 0
|
||||
|
||||
kfn.alif_vt .= 0
|
||||
kfn.alif_a .= 0
|
||||
@@ -35,6 +36,7 @@ function (kfn::kfn_1)(input::AbstractArray)
|
||||
kfn.alif_firingCounter .= 0
|
||||
kfn.alif_refractoryCounter .= 0
|
||||
kfn.alif_zt .= 0
|
||||
kfn.alif_synapticActivityCounter .= 0
|
||||
|
||||
kfn.on_vt .= 0
|
||||
kfn.on_epsilonRec .= 0
|
||||
@@ -75,7 +77,7 @@ function (kfn::kfn_1)(input::AbstractArray)
|
||||
kfn.lif_exInType,
|
||||
kfn.lif_wRecChange,
|
||||
kfn.lif_neuronInactivityCounter,
|
||||
kfn.lif_synapticInactivityCounter,
|
||||
kfn.lif_synapticActivityCounter,
|
||||
)
|
||||
end
|
||||
@async begin
|
||||
@@ -101,7 +103,7 @@ function (kfn::kfn_1)(input::AbstractArray)
|
||||
kfn.alif_exInType,
|
||||
kfn.alif_wRecChange,
|
||||
kfn.alif_neuronInactivityCounter,
|
||||
kfn.alif_synapticInactivityCounter,
|
||||
kfn.alif_synapticActivityCounter,
|
||||
kfn.alif_epsilonRecA,
|
||||
kfn.alif_a,
|
||||
kfn.alif_avth,
|
||||
@@ -169,7 +171,7 @@ function lifForward( zit::CuArray,
|
||||
exInType::CuArray,
|
||||
wRecChange::CuArray,
|
||||
neuronInactivityCounter::CuArray,
|
||||
synapticInactivityCounter::CuArray,
|
||||
synapticActivityCounter::CuArray,
|
||||
)
|
||||
|
||||
kernel = @cuda launch=false lifForward( zit,
|
||||
@@ -189,7 +191,7 @@ function lifForward( zit::CuArray,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
GeneralUtils.linear_to_cartesian,
|
||||
)
|
||||
config = launch_configuration(kernel.fun)
|
||||
@@ -223,7 +225,7 @@ function lifForward( zit::CuArray,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
GeneralUtils.linear_to_cartesian; threads, blocks)
|
||||
end
|
||||
end
|
||||
@@ -246,7 +248,7 @@ function lifForward( zit,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
linear_to_cartesian,
|
||||
)
|
||||
i = (blockIdx().x - 1) * blockDim().x + threadIdx().x # gpu threads index
|
||||
@@ -297,12 +299,10 @@ function lifForward( zit,
|
||||
|
||||
# count synaptic inactivity
|
||||
if !iszero(wRec[i1,i2,i3,i4]) # check if this is wRec subscription
|
||||
if !iszero(zit[i1,i2,i3,i4]) # synapse is active, reset counter
|
||||
#WORKING should be function based. range +1.0 to +0.1
|
||||
synapticInactivityCounter[i1,i2,i3,i4] += 1
|
||||
else # synapse is inactive, counting
|
||||
#WORKING should be function based. range +1.0 to +0.01
|
||||
synapticInactivityCounter[i1,i2,i3,i4] -= 1
|
||||
if !iszero(zit[i1,i2,i3,i4]) # synapse is active
|
||||
synapticActivityCounter[i1,i2,i3,i4] += 1
|
||||
else # synapse is inactive
|
||||
synapticActivityCounter[i1,i2,i3,i4] += 0
|
||||
end
|
||||
end
|
||||
# voltage regulator
|
||||
@@ -331,7 +331,7 @@ function alifForward( zit::CuArray,
|
||||
exInType::CuArray,
|
||||
wRecChange::CuArray,
|
||||
neuronInactivityCounter::CuArray,
|
||||
synapticInactivityCounter::CuArray,
|
||||
synapticActivityCounter::CuArray,
|
||||
epsilonRecA::CuArray,
|
||||
a::CuArray,
|
||||
avth::CuArray,
|
||||
@@ -356,7 +356,7 @@ function alifForward( zit::CuArray,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
epsilonRecA,
|
||||
a,
|
||||
avth,
|
||||
@@ -394,7 +394,7 @@ function alifForward( zit::CuArray,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
epsilonRecA,
|
||||
a,
|
||||
avth,
|
||||
@@ -422,7 +422,7 @@ function alifForward( zit,
|
||||
exInType,
|
||||
wRecChange,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticActivityCounter,
|
||||
epsilonRecA,
|
||||
a,
|
||||
avth,
|
||||
@@ -492,10 +492,10 @@ function alifForward( zit,
|
||||
|
||||
# count synaptic inactivity
|
||||
if !iszero(wRec[i1,i2,i3,i4]) # check if this is wRec subscription
|
||||
if !iszero(zit[i1,i2,i3,i4]) # synapse is active, reset counter
|
||||
synapticInactivityCounter[i1,i2,i3,i4] += 1
|
||||
else # synapse is inactive, counting
|
||||
synapticInactivityCounter[i1,i2,i3,i4] -= 1
|
||||
if !iszero(zit[i1,i2,i3,i4]) # synapse is active
|
||||
synapticActivityCounter[i1,i2,i3,i4] += 1
|
||||
else # synapse is inactive
|
||||
synapticActivityCounter[i1,i2,i3,i4] += 0
|
||||
end
|
||||
end
|
||||
# voltage regulator
|
||||
|
||||
110
src/learn.jl
110
src/learn.jl
@@ -267,27 +267,28 @@ end
|
||||
|
||||
function learn!(kfn::kfn_1, device=cpu)
|
||||
# lif learn
|
||||
kfn.lif_wRec, kfn.lif_neuronInactivityCounter, kfn.lif_synapticInactivityCounter =
|
||||
kfn.lif_wRec, kfn.lif_neuronInactivityCounter, kfn.lif_synapticActivityCounter =
|
||||
lifLearn(kfn.lif_wRec,
|
||||
kfn.lif_exInType,
|
||||
kfn.lif_wRecChange,
|
||||
kfn.lif_arrayProjection4d,
|
||||
kfn.lif_neuronInactivityCounter,
|
||||
kfn.lif_synapticInactivityCounter,
|
||||
kfn.lif_synapticConnectionNumber,
|
||||
kfn.lif_synapticActivityCounter,
|
||||
kfn.lif_synapseConnectionNumber,
|
||||
kfn.lif_synapticWChangeCounter,
|
||||
kfn.lif_eta,
|
||||
kfn.zitCumulative,
|
||||
device)
|
||||
|
||||
# alif learn
|
||||
kfn.alif_wRec, kfn.alif_neuronInactivityCounter, kfn.alif_synapticInactivityCounter =
|
||||
kfn.alif_wRec, kfn.alif_neuronInactivityCounter, kfn.alif_synapticActivityCounter =
|
||||
alifLearn(kfn.alif_wRec,
|
||||
kfn.alif_exInType,
|
||||
kfn.alif_wRecChange,
|
||||
kfn.alif_arrayProjection4d,
|
||||
kfn.alif_neuronInactivityCounter,
|
||||
kfn.alif_synapticInactivityCounter,
|
||||
kfn.alif_synapticConnectionNumber,
|
||||
kfn.alif_synapticActivityCounter,
|
||||
kfn.alif_synapseConnectionNumber,
|
||||
kfn.alif_synapticWChangeCounter,
|
||||
kfn.zitCumulative,
|
||||
device)
|
||||
@@ -309,9 +310,10 @@ function lifLearn(wRec,
|
||||
wRecChange,
|
||||
arrayProjection4d,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticConnectionNumber,
|
||||
synapticWChangeCounter, #WORKING
|
||||
synapticActivityCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
eta,
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
@@ -322,28 +324,39 @@ function lifLearn(wRec,
|
||||
arrayProjection4d_cpu = arrayProjection4d |> cpu
|
||||
wRec_cpu = wRec |> cpu
|
||||
wRec_cpu = wRec_cpu[:,:,:,1] # since every batch has the same neuron wRec, (row, col, n)
|
||||
eta_cpu = eta |> cpu
|
||||
eta_cpu = eta_cpu[:,:,:,1]
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter |> cpu
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu[:,:,:,1] # (row, col, n)
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter |> cpu
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter_cpu[:,:,:,1]
|
||||
synapticActivityCounter_cpu = synapticActivityCounter |> cpu
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu[:,:,:,1]
|
||||
zitCumulative_cpu = zitCumulative |> cpu
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col)
|
||||
|
||||
# -W if less than 10% of repeat avg, +W otherwise
|
||||
println("wRec_cpu 1 ", wRec_cpu)
|
||||
_, _, i3 = size(wRec_cpu)
|
||||
for i in 1:i3
|
||||
x = 0.1 * (sum(synapticActivityCounter[:,:,i]) / length(synapticActivityCounter[:,:,i]))
|
||||
mask = GeneralUtils.replaceLessThan.(wRec_cpu[:,:,i], x, -1, 1)
|
||||
wRec_cpu[:,:,i] .+= mask .* eta_cpu[:,:,i] .* wRec_cpu[:,:,i]
|
||||
end
|
||||
|
||||
# weak / negative synaptic connection will get randomed in neuroplasticity()
|
||||
wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.01, -1.0) # mark with -1.0
|
||||
|
||||
# synaptic connection that has no activity will get randomed in neuroplasticity()
|
||||
mask = isless.(synapticInactivityCounter_cpu, -100000)
|
||||
GeneralUtils.replace_elements!(mask, 1, wRec_cpu, -1.0)
|
||||
# reset lif_inactivity elements to base value
|
||||
GeneralUtils.replace_elements!(mask, 1, synapticInactivityCounter_cpu, 0.0)
|
||||
# # synaptic connection that has no activity will get randomed in neuroplasticity()
|
||||
# mask = isless.(synapticActivityCounter_cpu, -100000)
|
||||
# GeneralUtils.replaceElements!(mask, 1, wRec_cpu, -1.0)
|
||||
# # reset lif_inactivity elements to base value
|
||||
# GeneralUtils.replaceElements!(mask, 1, synapticActivityCounter_cpu, 0.0)
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapticConnectionNumber,
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapticInactivityCounter_cpu)
|
||||
synapticActivityCounter_cpu)
|
||||
|
||||
wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
wRec = wRec_cpu |> device
|
||||
@@ -351,11 +364,11 @@ function lifLearn(wRec,
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticInactivityCounter = synapticInactivityCounter_cpu |> device
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticActivityCounter = synapticActivityCounter_cpu |> device
|
||||
|
||||
# error("DEBUG -> lifLearn! $(Dates.now())")
|
||||
return wRec, neuronInactivityCounter, synapticInactivityCounter
|
||||
|
||||
return wRec, neuronInactivityCounter, synapticActivityCounter
|
||||
end
|
||||
|
||||
function alifLearn(wRec,
|
||||
@@ -363,9 +376,9 @@ function alifLearn(wRec,
|
||||
wRecChange,
|
||||
arrayProjection4d,
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter,
|
||||
synapticConnectionNumber,
|
||||
synapticWChangeCounter,
|
||||
synapticActivityCounter,
|
||||
synapseConnectionNumber,
|
||||
synapticWChangeCounter, #TODO
|
||||
zitCumulative,
|
||||
device)
|
||||
|
||||
@@ -378,8 +391,8 @@ function alifLearn(wRec,
|
||||
wRec_cpu = wRec_cpu[:,:,:,1] # since every batch has the same neuron wRec, (row, col, n)
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter |> cpu
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu[:,:,:,1] # (row, col, n)
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter |> cpu
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter_cpu[:,:,:,1]
|
||||
synapticActivityCounter_cpu = synapticActivityCounter |> cpu
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu[:,:,:,1]
|
||||
zitCumulative_cpu = zitCumulative |> cpu
|
||||
zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col)
|
||||
|
||||
@@ -387,17 +400,17 @@ function alifLearn(wRec,
|
||||
wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.01, -1.0) # mark with -1.0
|
||||
|
||||
# synaptic connection that has no activity will get randomed in neuroplasticity()
|
||||
mask = isless.(synapticInactivityCounter_cpu, -100000)
|
||||
GeneralUtils.replace_elements!(mask, 1, wRec_cpu, -1.0)
|
||||
mask = isless.(synapticActivityCounter_cpu, -100000)
|
||||
GeneralUtils.replaceElements!(mask, 1, wRec_cpu, -1.0)
|
||||
# reset alif_inactivity elements to base value
|
||||
GeneralUtils.replace_elements!(mask, 1, synapticInactivityCounter_cpu, 0.0)
|
||||
GeneralUtils.replaceElements!(mask, 1, synapticActivityCounter_cpu, 0.0)
|
||||
|
||||
# neuroplasticity, work on CPU side
|
||||
wRec_cpu = neuroplasticity(synapticConnectionNumber,
|
||||
wRec_cpu = neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative_cpu,
|
||||
wRec_cpu,
|
||||
neuronInactivityCounter_cpu,
|
||||
synapticInactivityCounter_cpu)
|
||||
synapticActivityCounter_cpu)
|
||||
|
||||
wRec_cpu = wRec_cpu .* arrayProjection4d_cpu
|
||||
wRec = wRec_cpu |> device
|
||||
@@ -405,11 +418,11 @@ function alifLearn(wRec,
|
||||
neuronInactivityCounter_cpu = neuronInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
neuronInactivityCounter = neuronInactivityCounter_cpu |> device
|
||||
|
||||
synapticInactivityCounter_cpu = synapticInactivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticInactivityCounter = synapticInactivityCounter_cpu |> device
|
||||
synapticActivityCounter_cpu = synapticActivityCounter_cpu .* arrayProjection4d_cpu
|
||||
synapticActivityCounter = synapticActivityCounter_cpu |> device
|
||||
|
||||
# error("DEBUG -> alifLearn! $(Dates.now())")
|
||||
return wRec, neuronInactivityCounter, synapticInactivityCounter
|
||||
return wRec, neuronInactivityCounter, synapticActivityCounter
|
||||
end
|
||||
|
||||
function onLearn!(wOut,
|
||||
@@ -427,17 +440,17 @@ function onLearn!(wOut,
|
||||
|
||||
end
|
||||
|
||||
function neuroplasticity(synapticConnectionNumber,
|
||||
function neuroplasticity(synapseConnectionNumber,
|
||||
zitCumulative, # (row, col)
|
||||
wRec, # (row, col, n)
|
||||
neuronInactivityCounter,
|
||||
synapticInactivityCounter) # (row, col, n)
|
||||
synapticActivityCounter) # (row, col, n)
|
||||
|
||||
i1,i2,i3 = size(wRec)
|
||||
|
||||
# for each neuron, find total number of synaptic conn that should draw
|
||||
# new connection to firing and non-firing neurons pool
|
||||
subToFireNeuron_toBe = Int(floor(0.7 * synapticConnectionNumber))
|
||||
subToFireNeuron_toBe = Int(floor(0.7 * synapseConnectionNumber))
|
||||
|
||||
# for each neuron, count how many synap already subscribed to firing-neurons
|
||||
zw = zitCumulative .* wRec
|
||||
@@ -446,23 +459,23 @@ function neuroplasticity(synapticConnectionNumber,
|
||||
projection = ones(i1,i2,i3)
|
||||
zitMask = zitMask .* projection # (row, col, n)
|
||||
totalNewConn = sum(isequal.(wRec, -1.0), dims=(1,2)) # count new conn mark (-1.0), (1, 1, n)
|
||||
println("neuroplasticity, from $(synapticConnectionNumber*size(totalNewConn, 3)) conn, $(sum(totalNewConn)) are replaced")
|
||||
println("neuroplasticity, from $(synapseConnectionNumber*size(totalNewConn, 3)) conn, $(sum(totalNewConn)) are replaced")
|
||||
|
||||
# clear -1.0 marker
|
||||
GeneralUtils.replace_elements!(wRec, -1.0, synapticInactivityCounter, -0.99)
|
||||
GeneralUtils.replace_elements!(wRec, -1.0, 0.0) # -1.0 marker is no longer required
|
||||
GeneralUtils.replaceElements!(wRec, -1.0, synapticActivityCounter, -0.99)
|
||||
GeneralUtils.replaceElements!(wRec, -1.0, 0.0) # -1.0 marker is no longer required
|
||||
|
||||
for i in 1:i3
|
||||
if neuronInactivityCounter[1:1:i][1] < -10000 # neuron die i.e. reset all weight
|
||||
println("neuron die")
|
||||
neuronInactivityCounter[:,:,i] .= 0 # reset
|
||||
w = random_wRec(i1,i2,1,synapticConnectionNumber)
|
||||
w = random_wRec(i1,i2,1,synapseConnectionNumber)
|
||||
wRec[:,:,i] .= w
|
||||
|
||||
a = similar(w) .= -0.99 # synapticConnectionNumber of this neuron
|
||||
a = similar(w) .= -0.99 # synapseConnectionNumber of this neuron
|
||||
mask = (!iszero).(w)
|
||||
GeneralUtils.replace_elements!(mask, 1, a, 0)
|
||||
synapticInactivityCounter[:,:,i] = a
|
||||
GeneralUtils.replaceElements!(mask, 1, a, 0)
|
||||
synapticActivityCounter[:,:,i] = a
|
||||
else
|
||||
remaining = 0
|
||||
if subToFireNeuron_current[1,1,i] < subToFireNeuron_toBe
|
||||
@@ -471,7 +484,7 @@ function neuroplasticity(synapticConnectionNumber,
|
||||
# add new conn to firing neurons pool
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticInactivityCounter[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
toAddConn)
|
||||
totalNewConn[1,1,i] += remaining
|
||||
end
|
||||
@@ -479,12 +492,12 @@ function neuroplasticity(synapticConnectionNumber,
|
||||
# add new conn to non-firing neurons pool
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 0,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticInactivityCounter[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
totalNewConn[1,1,i])
|
||||
if remaining > 0 # final get-all round if somehow non-firing pool has not enough slot
|
||||
remaining = addNewSynapticConn!(zitMask[:,:,i], 1,
|
||||
@view(wRec[:,:,i]),
|
||||
@view(synapticInactivityCounter[:,:,i]),
|
||||
@view(synapticActivityCounter[:,:,i]),
|
||||
remaining)
|
||||
end
|
||||
end
|
||||
@@ -543,7 +556,6 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end # module
|
||||
@@ -75,9 +75,7 @@ function addNewSynapticConn!(mask::AbstractArray{<:Any}, x::Number, wRec::Abstra
|
||||
# replace the elements in wRec at the selected positions with a
|
||||
for i in selected
|
||||
wRec[i] = rand(0.01:0.01:0.1)
|
||||
if counter !== nothing
|
||||
counter[i] = 0 # counting start from 0
|
||||
end
|
||||
counter[i] = 0 # counting start from 0
|
||||
end
|
||||
# error("DEBUG addNewSynapticConn!")
|
||||
return remaining
|
||||
|
||||
50
src/type.jl
50
src/type.jl
@@ -58,8 +58,8 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
lif_firingCounter::Union{AbstractArray, Nothing} = nothing
|
||||
lif_firingTargetFrequency::Union{AbstractArray, Nothing} = nothing
|
||||
lif_neuronInactivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
lif_synapticInactivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
lif_synapticConnectionNumber::Union{Int, Nothing} = nothing
|
||||
lif_synapticActivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
lif_synapseConnectionNumber::Union{Int, Nothing} = nothing
|
||||
lif_synapticWChangeCounter::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
# pre-allocation array
|
||||
@@ -99,8 +99,8 @@ Base.@kwdef mutable struct kfn_1 <: knowledgeFn
|
||||
alif_firingCounter::Union{AbstractArray, Nothing} = nothing
|
||||
alif_firingTargetFrequency::Union{AbstractArray, Nothing} = nothing
|
||||
alif_neuronInactivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
alif_synapticInactivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
alif_synapticConnectionNumber::Union{Int, Nothing} = nothing
|
||||
alif_synapticActivityCounter::Union{AbstractArray, Nothing} = nothing
|
||||
alif_synapseConnectionNumber::Union{Int, Nothing} = nothing
|
||||
alif_synapticWChangeCounter::Union{AbstractArray, Nothing} = nothing
|
||||
|
||||
# pre-allocation array
|
||||
@@ -200,8 +200,8 @@ function kfn_1(params::Dict; device=cpu)
|
||||
|
||||
# subscription
|
||||
synapticConnectionPercent = kfn.params[:computeNeuron][:lif][:params][:synapticConnectionPercent]
|
||||
kfn.lif_synapticConnectionNumber = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
w = random_wRec(row, col, lif_n, kfn.lif_synapticConnectionNumber)
|
||||
kfn.lif_synapseConnectionNumber = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
w = random_wRec(row, col, lif_n, kfn.lif_synapseConnectionNumber)
|
||||
|
||||
# project 3D w into 4D kfn.lif_wRec (row, col, n, batch)
|
||||
kfn.lif_wRec = reshape(w, (row, col, lif_n, 1)) .* ones(row, col, lif_n, batch) |> device
|
||||
@@ -227,15 +227,19 @@ function kfn_1(params::Dict; device=cpu)
|
||||
kfn.lif_firingCounter = (similar(kfn.lif_wRec) .= 0)
|
||||
kfn.lif_firingTargetFrequency = (similar(kfn.lif_wRec) .= 0.1)
|
||||
kfn.lif_neuronInactivityCounter = (similar(kfn.lif_wRec) .= 0)
|
||||
kfn.lif_synapticInactivityCounter = Array(similar(kfn.lif_wRec) .= -0.99) # -9 for non-sub conn
|
||||
|
||||
# count subscribed synapse activity, just like epsilonRec but without decay.
|
||||
# use to adjust weight based on how often neural pathway is used
|
||||
kfn.lif_synapticActivityCounter = Array(similar(kfn.lif_wRec) .= -0.99) # -0.99 for non-sub conn
|
||||
mask = Array((!iszero).(kfn.lif_wRec))
|
||||
# initial value subscribed conn, synapticInactivityCounter range -10000 to +10000
|
||||
GeneralUtils.replace_elements!(mask, 1, kfn.lif_synapticInactivityCounter, 0)
|
||||
kfn.lif_synapticInactivityCounter = kfn.lif_synapticInactivityCounter |> device
|
||||
kfn.lif_synapticWChangeCounter = Array(similar(kfn.lif_wRec) .= -0.99) # -9 for non-sub conn
|
||||
# initial value subscribed conn, synapticActivityCounter range -10000 to +10000
|
||||
GeneralUtils.replaceElements!(mask, 1, kfn.lif_synapticActivityCounter, 0)
|
||||
kfn.lif_synapticActivityCounter = kfn.lif_synapticActivityCounter |> device
|
||||
|
||||
kfn.lif_synapticWChangeCounter = Array(similar(kfn.lif_wRec) .= -0.99) # -0.99 for non-sub conn
|
||||
mask = Array((!iszero).(kfn.lif_wRec))
|
||||
# initial value subscribed conn, synapticInactivityCounter range -10000 to +10000
|
||||
GeneralUtils.replace_elements!(mask, 1, kfn.lif_synapticWChangeCounter, 1.0)
|
||||
# initial value subscribed conn, synapticActivityCounter range -10000 to +10000
|
||||
GeneralUtils.replaceElements!(mask, 1, kfn.lif_synapticWChangeCounter, 1.0)
|
||||
kfn.lif_synapticWChangeCounter = kfn.lif_synapticWChangeCounter |> device
|
||||
|
||||
kfn.lif_arrayProjection4d = (similar(kfn.lif_wRec) .= 1)
|
||||
@@ -254,8 +258,8 @@ function kfn_1(params::Dict; device=cpu)
|
||||
|
||||
# subscription
|
||||
synapticConnectionPercent = kfn.params[:computeNeuron][:alif][:params][:synapticConnectionPercent]
|
||||
kfn.alif_synapticConnectionNumber = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
w = random_wRec(row, col, alif_n, kfn.alif_synapticConnectionNumber)
|
||||
kfn.alif_synapseConnectionNumber = Int(floor(row*col * synapticConnectionPercent/100))
|
||||
w = random_wRec(row, col, alif_n, kfn.alif_synapseConnectionNumber)
|
||||
|
||||
# project 3D w into 4D kfn.alif_wRec
|
||||
kfn.alif_wRec = reshape(w, (row, col, alif_n, 1)) .* ones(row, col, alif_n, batch) |> device
|
||||
@@ -281,15 +285,15 @@ function kfn_1(params::Dict; device=cpu)
|
||||
kfn.alif_firingCounter = (similar(kfn.alif_wRec) .= 0)
|
||||
kfn.alif_firingTargetFrequency = (similar(kfn.alif_wRec) .= 0.1)
|
||||
kfn.alif_neuronInactivityCounter = (similar(kfn.alif_wRec) .= 0)
|
||||
kfn.alif_synapticInactivityCounter = Array(similar(kfn.alif_wRec) .= -0.99) # -9 for non-sub conn
|
||||
kfn.alif_synapticActivityCounter = Array(similar(kfn.alif_wRec) .= -0.99) # -9 for non-sub conn
|
||||
mask = Array((!iszero).(kfn.alif_wRec))
|
||||
# initial value subscribed conn, synapticInactivityCounter range -10000 to +10000
|
||||
GeneralUtils.replace_elements!(mask, 1, kfn.alif_synapticInactivityCounter, 0)
|
||||
kfn.alif_synapticInactivityCounter = kfn.alif_synapticInactivityCounter |> device
|
||||
# initial value subscribed conn, synapticActivityCounter range -10000 to +10000
|
||||
GeneralUtils.replaceElements!(mask, 1, kfn.alif_synapticActivityCounter, 0)
|
||||
kfn.alif_synapticActivityCounter = kfn.alif_synapticActivityCounter |> device
|
||||
kfn.alif_synapticWChangeCounter = Array(similar(kfn.alif_wRec) .= -0.99) # -9 for non-sub conn
|
||||
mask = Array((!iszero).(kfn.alif_wRec))
|
||||
# initial value subscribed conn, synapticInactivityCounter range -10000 to +10000
|
||||
GeneralUtils.replace_elements!(mask, 1, kfn.alif_synapticWChangeCounter, 1.0)
|
||||
# initial value subscribed conn, synapticActivityCounter range -10000 to +10000
|
||||
GeneralUtils.replaceElements!(mask, 1, kfn.alif_synapticWChangeCounter, 1.0)
|
||||
kfn.alif_synapticWChangeCounter = kfn.alif_synapticWChangeCounter |> device
|
||||
|
||||
kfn.alif_arrayProjection4d = (similar(kfn.alif_wRec) .= 1)
|
||||
@@ -376,12 +380,12 @@ function kfn_1(params::Dict; device=cpu)
|
||||
return kfn
|
||||
end
|
||||
|
||||
function random_wRec(row, col, n, synapticConnectionNumber)
|
||||
function random_wRec(row, col, n, synapseConnectionNumber)
|
||||
# subscription
|
||||
w = zeros(row, col, n)
|
||||
|
||||
for slice in eachslice(w, dims=3)
|
||||
pool = shuffle!([1:row*col...])[1:synapticConnectionNumber]
|
||||
pool = shuffle!([1:row*col...])[1:synapseConnectionNumber]
|
||||
for i in pool
|
||||
slice[i] = rand(0.01:0.01:0.1) # assign weight to synaptic connection. /10 to start small,
|
||||
# otherwise RSNN's vt Usually stay negative (-)
|
||||
|
||||
Reference in New Issue
Block a user