From bf78ca5086062c56c11da5c90541396caf7e972e Mon Sep 17 00:00:00 2001 From: ton Date: Sat, 26 Aug 2023 17:19:22 +0700 Subject: [PATCH] change how to random neuron's initial weight --- src/learn.jl | 1 + src/snnUtil.jl | 58 -------------------------------------------------- src/type.jl | 6 ++---- 3 files changed, 3 insertions(+), 62 deletions(-) diff --git a/src/learn.jl b/src/learn.jl index 4d9db2c..0873d32 100644 --- a/src/learn.jl +++ b/src/learn.jl @@ -437,6 +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") # clear -1.0 marker GeneralUtils.replace_elements!(wRec, -1.0, synapticInactivityCounter, -0.99) diff --git a/src/snnUtil.jl b/src/snnUtil.jl index ca7c024..39f997d 100644 --- a/src/snnUtil.jl +++ b/src/snnUtil.jl @@ -95,64 +95,6 @@ function addNewSynapticConn!(mask::AbstractArray{<:Any}, x::Number, wRec::Abstra end -# function addNewSynapticConn!(mask::AbstractArray{<:Any}, x::Number, A::AbstractArray{<:Any}, -# A2::AbstractArray{<:Any}, n=0; -# rng::AbstractRNG=MersenneTwister(1234)) -# # println("mask ", mask, size(mask)) -# # println("") -# # println("x ", x, size(x)) -# # println("") -# # println("A ", A, size(A)) -# # println("") -# # println("A2 ", A2, size(A2)) -# # println("") -# # println("n ", n, size(n)) -# # println("") - -# total_x_tobeReplced = sum(isequal.(mask, x)) -# remaining = 0 -# if n == 0 || n > total_x_tobeReplced -# remaining = n - total_x_tobeReplced -# n = total_x_tobeReplced -# end - -# # check if mask and A have the same size -# if size(mask) != size(A) -# error("mask and A must have the same size") -# end -# # get the indices of elements in mask that equal x -# indices = findall(x -> x == x, mask) -# # shuffle the indices using the rng function -# shuffle!(rng, indices) -# # select the first n indices -# selected = indices[1:n] -# # replace the elements in A at the selected positions with a -# for i in selected -# A[i] = rand(0.1:0.01:0.3) -# if A2 !== nothing -# A2[i] = 10000 -# end -# end -# # println("==================") -# # println("mask ", mask, size(mask)) -# # println("") -# # println("x ", x, size(x)) -# # println("") -# # println("A ", A, size(A)) -# # println("") -# # println("A2 ", A2, size(A2)) -# # println("") -# # println("n ", n, size(n)) -# # println("") -# # error("DEBUG addNewSynapticConn!") -# return remaining -# end - - - - - - diff --git a/src/type.jl b/src/type.jl index 84fb6ac..7d95da3 100644 --- a/src/type.jl +++ b/src/type.jl @@ -376,8 +376,8 @@ function wRec(row, col, n, synapticConnectionNumber) end # 10% of neuron connection should be enough to start to make neuron fires - should_be_avg_weight = 1 / (0.1 * synapticConnectionNumber) - w = w .* (should_be_avg_weight / maximum(w)) # adjust overall weight + avgWeight = sum(w)/length(w) + w = w .* (0.1 / avgWeight) # adjust overall weight return w #(row, col, n) end @@ -423,8 +423,6 @@ end - -