module snnUtil export refractoryStatus!, addNewSynapticConn! using Random #------------------------------------------------------------------------------------------------100 function refractoryStatus!(refractoryCounter, refractoryActive, refractoryInactive) d1, d2, d3, d4 = size(refractoryCounter) for j in 1:d4 for i in 1:d3 if refractoryCounter[1, 1, i, j] > 0 # inactive view(refractoryActive, 1, 1, i, j) .= 0 view(refractoryInactive, 1, 1, i, j) .= 1 else # active view(refractoryActive, 1, 1, i, j) .= 1 view(refractoryInactive, 1, 1, i, j) .= 0 end end 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") # 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("") # 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 remaining = 0 if n == 0 || n > length(indices) remaining = n - length(indices) n = length(indices) end # shuffle the indices using the rng function shuffle!(rng, indices) # select the first n indices n > length(indices) ? println(">>> ", total_x_tobeReplced) : nothing selected = indices[1:n] # 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 end # error("DEBUG addNewSynapticConn!") return remaining end end # module