clear marker
This commit is contained in:
136
src/snnUtil.jl
136
src/snnUtil.jl
@@ -1,8 +1,8 @@
|
||||
module snnUtil
|
||||
|
||||
export refractoryStatus!
|
||||
export refractoryStatus!, addNewSynapticConn!
|
||||
|
||||
# using
|
||||
using Random
|
||||
|
||||
#------------------------------------------------------------------------------------------------100
|
||||
|
||||
@@ -21,28 +21,132 @@ function refractoryStatus!(refractoryCounter, refractoryActive, refractoryInacti
|
||||
end
|
||||
end
|
||||
|
||||
function frobenius_distance(A, B)
|
||||
# Check if the matrices have the same size
|
||||
if size(A) != size(B)
|
||||
error("The matrices must have the same size")
|
||||
# function frobenius_distance(A, B)
|
||||
# # Check if the matrices have the same size
|
||||
# if size(A) != size(B)
|
||||
# error("The matrices must have the same size")
|
||||
# end
|
||||
# # Initialize the distance to zero
|
||||
# distance = 0.0
|
||||
# # Loop over the elements of the matrices and add the squared differences
|
||||
# for i in 1:size(A, 1)
|
||||
# for j in 1:size(A, 2)
|
||||
# distance += (A[i, j] - B[i, j])^2
|
||||
# end
|
||||
# end
|
||||
# # Return the square root of the distance
|
||||
# return sqrt(distance)
|
||||
# end
|
||||
|
||||
function addNewSynapticConn!(mask::AbstractArray{<:Any}, x::Number, wRec::AbstractArray{<:Any},
|
||||
counter::AbstractArray{<:Any}, n=0;
|
||||
rng::AbstractRNG=MersenneTwister(1234))
|
||||
# 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("")
|
||||
|
||||
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
|
||||
# Initialize the distance to zero
|
||||
distance = 0.0
|
||||
# Loop over the elements of the matrices and add the squared differences
|
||||
for i in 1:size(A, 1)
|
||||
for j in 1:size(A, 2)
|
||||
distance += (A[i, j] - B[i, j])^2
|
||||
|
||||
# check if mask and wRec have the same size
|
||||
if size(mask) != size(wRec)
|
||||
error("mask and wRec must have the same size")
|
||||
end
|
||||
# get the indices of elements in mask that equal x
|
||||
indices = findall(x -> x == x, mask)
|
||||
alreadySub = findall(x -> x != 0, wRec) # get already subscribe
|
||||
setdiff!(indices, alreadySub) # remove already sub conn from pool
|
||||
|
||||
# shuffle the indices using the rng function
|
||||
shuffle!(rng, indices)
|
||||
# select the first n indices
|
||||
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)
|
||||
if counter !== nothing
|
||||
counter[i] = 0 # reset
|
||||
end
|
||||
end
|
||||
# Return the square root of the distance
|
||||
return sqrt(distance)
|
||||
# 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
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user