From b0a8a5374e72b09a5ed822457d7b5f60955a038c Mon Sep 17 00:00:00 2001 From: Marco Lehmann Date: Wed, 28 Mar 2018 14:58:33 +0200 Subject: [PATCH] bugfix pattern_tools: size of vector with changed neurons was not correct --- neurodynex/hopfield_network/demo.py | 6 +++--- neurodynex/hopfield_network/pattern_tools.py | 2 +- neurodynex/tools/spike_tools.py | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/neurodynex/hopfield_network/demo.py b/neurodynex/hopfield_network/demo.py index db141fc..f4243ef 100644 --- a/neurodynex/hopfield_network/demo.py +++ b/neurodynex/hopfield_network/demo.py @@ -123,7 +123,7 @@ def run_demo(): """ # Demo2: more neurons, more patterns, more noise - run_hf_demo(pattern_size=6, nr_random_patterns=5, initially_flipped_pixels=11, nr_iterations=5) + # run_hf_demo(pattern_size=6, nr_random_patterns=5, initially_flipped_pixels=11, nr_iterations=5) # Demo3: more parameters # run_hf_demo(pattern_size=4, nr_random_patterns=5, @@ -180,5 +180,5 @@ def upd_random(state_s0, weights): if __name__ == '__main__': - # run_demo() - run_user_function_demo() + run_demo() + # run_user_function_demo() diff --git a/neurodynex/hopfield_network/pattern_tools.py b/neurodynex/hopfield_network/pattern_tools.py index 047fe51..95eedcb 100644 --- a/neurodynex/hopfield_network/pattern_tools.py +++ b/neurodynex/hopfield_network/pattern_tools.py @@ -232,7 +232,7 @@ def get_noisy_copy(template, noise_level): n = np.prod(template.shape) nr_mutations = int(round(n * noise_level)) idx_reassignment = np.random.choice(n, nr_mutations, replace=False) - rand_values = np.random.binomial(1, 0.5, n) + rand_values = np.random.binomial(1, 0.5, nr_mutations) rand_values = rand_values * 2 - 1 # map {0,1} to {-1, +1} linear_template[idx_reassignment] = rand_values return linear_template.reshape(template.shape) diff --git a/neurodynex/tools/spike_tools.py b/neurodynex/tools/spike_tools.py index 4fea04a..7447f82 100644 --- a/neurodynex/tools/spike_tools.py +++ b/neurodynex/tools/spike_tools.py @@ -31,9 +31,9 @@ def get_spike_time(voltage_monitor, spike_threshold): """ - Detects the spike times in the voltage. The spike time is the value in voltage_monitor.t for - which voltage_monitor.v[idx] is above threshold AND voltage_monitor.v[idx-1] is below threshold - (crossing from below). + Detects the spike times in the voltage. Here, the spike time is DEFINED as the value in + voltage_monitor.t for which voltage_monitor.v[idx] is above threshold AND + voltage_monitor.v[idx-1] is below threshold (crossing from below). Note: currently only the spike times of the first column in voltage_monitor are detected. Matrix-like monitors are not supported. Args: @@ -57,6 +57,9 @@ def get_spike_time(voltage_monitor, spike_threshold): def get_spike_stats(voltage_monitor, spike_threshold): """ Detects spike times and computes ISI, mean ISI and firing frequency. + Here, the spike time is DEFINED as the value in + voltage_monitor.t for which voltage_monitor.v[idx] is above threshold AND + voltage_monitor.v[idx-1] is below threshold (crossing from below). Note: meanISI and firing frequency are set to numpy.nan if less than two spikes are detected Note: currently only the spike times of the first column in voltage_monitor are detected. Matrix-like monitors are not supported.