fix neuroplasticity error

This commit is contained in:
ton
2023-08-26 18:26:38 +07:00
parent bf78ca5086
commit 9b67a69612
3 changed files with 6 additions and 19 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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