From 4ea5f863a8d7fa1a34b5a1b56000a07a64309c08 Mon Sep 17 00:00:00 2001 From: Jinqi Huang Date: Mon, 28 Feb 2022 13:45:14 +0000 Subject: [PATCH] Update surrogate derivative --- NeuroCores/core_Izhikevich.py | 2 +- NeuroCores/core_LIF_supervisedlearning.py | 4 ++-- NeuroCores/core_LIF_supervisedlearning_wta.py | 2 +- NeuroCores/core_LIF_supervisedlearning_wta_debugver.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NeuroCores/core_Izhikevich.py b/NeuroCores/core_Izhikevich.py index 1d84bde..e661977 100644 --- a/NeuroCores/core_Izhikevich.py +++ b/NeuroCores/core_Izhikevich.py @@ -227,7 +227,7 @@ def plast(net, time): if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): error[neuron] = 0 else: - error[neuron] = delta * 0.5 * net.state.NeurAccum[time][neuron - net.inputNum] / net.params.get('FIRETH', 0.001) + error[neuron] = delta * 0.5 / net.params.get('FIRETH', 0.001) print("neuron %d has delta %f and error %f" % (neuron, delta, error[neuron])) elif neuron < fullNum - net.outputNum and neuron >= net.inputNum: # hidden neurons if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): diff --git a/NeuroCores/core_LIF_supervisedlearning.py b/NeuroCores/core_LIF_supervisedlearning.py index cd8eb69..af2e13a 100644 --- a/NeuroCores/core_LIF_supervisedlearning.py +++ b/NeuroCores/core_LIF_supervisedlearning.py @@ -199,13 +199,13 @@ def plast(net, time): if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): error[neuron] = 0 else: - error[neuron] = delta * 0.5 * net.state.NeurAccum[time][neuron - net.inputNum]) / net.params.get('FIRETH', 0.001) + error[neuron] = delta * 0.5 / net.params.get('FIRETH', 0.001) print("neuron %d has expected output %d and real output %d, delta %f and error %f" % (neuron, outputLabel[neuron], rawin[neuron], delta, error[neuron])) elif neuron < fullNum - net.outputNum and neuron >= net.inputNum: # hidden neurons if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): sur_deriv = 0 else: - sur_deriv = 0.5 * net.state.NeurAccum[time][neuron - net.inputNum] / net.params.get('FIRETH', 0.001) + sur_deriv = 0.5 / net.params.get('FIRETH', 0.001) for postidx in np.where(net.ConnMat[neuron,:, 0] != 0)[0]: # add up all error back propagated from the next layer delta_error = error[postidx] * net.state.weights[neuron, postidx - net.inputNum, time] * sur_deriv error[neuron] += delta_error diff --git a/NeuroCores/core_LIF_supervisedlearning_wta.py b/NeuroCores/core_LIF_supervisedlearning_wta.py index def8b13..bf08df9 100644 --- a/NeuroCores/core_LIF_supervisedlearning_wta.py +++ b/NeuroCores/core_LIF_supervisedlearning_wta.py @@ -242,7 +242,7 @@ def plast(net, time): if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): sur_deriv = 0 else: - sur_deriv = 0.5 * net.state.NeurAccum[time][neuron - net.inputNum] / net.params.get('FIRETH', 0.001) + sur_deriv = 0.5 / net.params.get('FIRETH', 0.001) for postidx in np.where(net.ConnMat[neuron,:, 0] != 0)[0]: # add up all error back propagated from the next layer delta_error = error[postidx] * net.state.weights[neuron, postidx - net.inputNum, time] * sur_deriv error[neuron] += delta_error diff --git a/NeuroCores/core_LIF_supervisedlearning_wta_debugver.py b/NeuroCores/core_LIF_supervisedlearning_wta_debugver.py index 3b72e9f..9feb969 100644 --- a/NeuroCores/core_LIF_supervisedlearning_wta_debugver.py +++ b/NeuroCores/core_LIF_supervisedlearning_wta_debugver.py @@ -231,7 +231,7 @@ def plast(net, time): if abs(net.state.NeurAccum[time][neuron - net.inputNum] - net.params.get('FIRETH', 0.001)) > net.params.get('FIRETH', 0.001): sur_deriv = 0 else: - sur_deriv = 0.5 * net.state.NeurAccum[time][neuron - net.inputNum] / net.params.get('FIRETH', 0.001) + sur_deriv = 0.5 / net.params.get('FIRETH', 0.001) for postidx in np.where(net.ConnMat[neuron,:, 0] != 0)[0]: # add up all error back propagated from the next layer delta_error = error[postidx] * net.state.weights[neuron, postidx - net.inputNum, time] * sur_deriv error[neuron] += delta_error