From b5c372d5707f93abf67ac676e68ff4d047c3d788 Mon Sep 17 00:00:00 2001 From: tonaerospace Date: Wed, 17 May 2023 07:36:14 +0700 Subject: [PATCH] refractoring --- src/snn_utils.jl | 74 +++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/src/snn_utils.jl b/src/snn_utils.jl index 98e179e..5ac5c41 100644 --- a/src/snn_utils.jl +++ b/src/snn_utils.jl @@ -244,31 +244,6 @@ end firing_rate!(n::compute_neuron) = n.firingRate = (n.firingCounter / n.timeStep) * 1000 firing_diff!(n::compute_neuron) = n.firingDiff = n.firingRate - n.firingRateTarget -function neuroplasticity!(n::compute_neuron, firedNeurons::Vector) - # if there is 0-weight then replace it with new connection - zero_weight_index = findall(iszero.(n.wRec)) - if length(zero_weight_index) != 0 - """ sampling new connection from list of neurons that fires instead of ramdom choose from - all compute neuron because there is no point to connect to neuron that not fires i.e. - not fire = no information - """ - - subscribe_options = filter(x -> x ∉ [n.id], firedNeurons) # exclude this neuron id from the list - filter!(x -> x ∉ n.subscriptionList, subscribe_options) # exclude this neuron's subscriptionList from the list - shuffle!(subscribe_options) - end - - new_connection_percent = 10 - ((n.optimiser.eta / 0.0001) / 10) # percent is in range 0.1 to 10 - percentage = [new_connection_percent, 100.0 - new_connection_percent] / 100.0 - for i in zero_weight_index - if Utils.random_choices([true, false], percentage) - n.subscriptionList[i] = pop!(subscribe_options) - n.wRec[i] = 0.01 # new connection should not send large signal otherwise it would throw - # RSNN off path. Let weight grow by an optimiser - end - end -end - function adjust_internal_learning_rate!(n::compute_neuron) n.internal_learning_rate = n.error_diff[end] < 0.0 ? n.internal_learning_rate * 0.99 : n.internal_learning_rate * 1.005 @@ -298,9 +273,11 @@ function synapticConnStrength(currentStrength::AbstractFloat, updown::String, bi return updatedStrength end +""" Compute all synaptic connection strength of a neuron. Also mark n.wRec to 0 if wRec goes + below lowerlimit. +""" function synapticConnStrength!(n::Union{compute_neuron, output_neuron}) for (i, connStrength) in enumerate(n.synapticStrength) - #WORKING # check whether connStrength increase or decrease based on usage from n.epsilonRec updown = n.epsilonRec[i] == 0.0 ? "down" : "up" updatedConnStrength = synapticConnStrength(connStrength, updown) @@ -312,8 +289,53 @@ function synapticConnStrength!(n::Union{compute_neuron, output_neuron}) end end end + function synapticConnStrength!(n::input_neuron) end +function neuroplasticity!(n::compute_neuron, firedNeurons::Vector) + # if there is 0-weight then replace it with new connection + zero_weight_index = findall(iszero.(n.wRec)) + if length(zero_weight_index) != 0 + """ sampling new connection from list of neurons that fires instead of ramdom choose from + all compute neuron because there is no point to connect to neuron that not fires i.e. + not fire = no information + """ + + subscribe_options = filter(x -> x ∉ [n.id], firedNeurons) # exclude this neuron id from the list + filter!(x -> x ∉ n.subscriptionList, subscribe_options) # exclude this neuron's subscriptionList from the list + shuffle!(subscribe_options) + end + + new_connection_percent = 10 - ((n.optimiser.eta / 0.0001) / 10) # percent is in range 0.1 to 10 + percentage = [new_connection_percent, 100.0 - new_connection_percent] / 100.0 + for i in zero_weight_index + if Utils.random_choices([true, false], percentage) + n.subscriptionList[i] = pop!(subscribe_options) + n.wRec[i] = 0.01 # new connection should not send large signal otherwise it would throw + # RSNN off path. Let weight grow by an optimiser + end + end +end + + + + + + + + + + + + + + + + + + + +