From 9b67a69612e1cc450c1c473eea2e81ac18cd0637 Mon Sep 17 00:00:00 2001 From: ton Date: Sat, 26 Aug 2023 18:26:38 +0700 Subject: [PATCH] fix neuroplasticity error --- src/learn.jl | 6 +++--- src/snnUtil.jl | 15 +-------------- src/type.jl | 4 ++-- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/learn.jl b/src/learn.jl index 0873d32..4e3a985 100644 --- a/src/learn.jl +++ b/src/learn.jl @@ -323,7 +323,7 @@ function lifLearn(wRec, zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col) # weak / negative synaptic connection will get randomed in neuroplasticity() - wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.1, -1.0) # mark with -1.0 + 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, -10_000) @@ -375,7 +375,7 @@ function alifLearn(wRec, zitCumulative_cpu = zitCumulative_cpu[:,:,1] # (row, col) # weak / negative synaptic connection will get randomed in neuroplasticity() - wRec_cpu = GeneralUtils.replaceBetween.(wRec_cpu, 0.0, 0.1, -1.0) # mark with -1.0 + 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, -10_000) @@ -437,7 +437,7 @@ 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, $totalNewConn are replaced") + println("neuroplasticity, from $synapticConnectionNumber, $totalNewConn are replaced") # clear -1.0 marker GeneralUtils.replace_elements!(wRec, -1.0, synapticInactivityCounter, -0.99) diff --git a/src/snnUtil.jl b/src/snnUtil.jl index 39f997d..c95cee3 100644 --- a/src/snnUtil.jl +++ b/src/snnUtil.jl @@ -74,22 +74,11 @@ function addNewSynapticConn!(mask::AbstractArray{<:Any}, x::Number, wRec::Abstra selected = indices[1:n] # replace the elements in wRec at the selected positions with a for i in selected - wRec[i] = 0.1 #rand(0.1:0.01:0.3) + wRec[i] = rand(0.01:0.01:0.1) if counter !== nothing counter[i] = 0 # reset end end - # println("==================") - # println("mask ", mask, size(mask)) - # println("") - # println("x ", x, size(x)) - # println("") - # println("wRec ", wRec, size(wRec)) - # println("") - # println("counter ", counter, size(counter)) - # println("") - # println("n ", n, size(n)) - # println("") # error("DEBUG addNewSynapticConn!") return remaining end @@ -125,8 +114,6 @@ end - - diff --git a/src/type.jl b/src/type.jl index 7d95da3..a293d35 100644 --- a/src/type.jl +++ b/src/type.jl @@ -370,14 +370,14 @@ function wRec(row, col, n, synapticConnectionNumber) for slice in eachslice(w, dims=3) pool = shuffle!([1:row*col...])[1:synapticConnectionNumber] for i in pool - slice[i] = rand() # assign weight to synaptic connection. /10 to start small, + 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 (-) end end # 10% of neuron connection should be enough to start to make neuron fires avgWeight = sum(w)/length(w) - w = w .* (0.1 / avgWeight) # adjust overall weight + w = w .* (0.01 / avgWeight) # adjust overall weight return w #(row, col, n) end