def test_seed(self): np.random.seed(123412845) a1 = np.random.randint(1000000) res1 = generate(128, 3, 100, abort_on_restart=True, seed=1423452) a2 = np.random.randint(1000000) res2 = generate(128, 3, 100, abort_on_restart=True, seed=1423452) a3 = np.random.randint(1000000) res3 = generate(128, 3, 100, abort_on_restart=True) a4 = np.random.randint(1000000) self.assertTrue(np.all(res1 == res2)) self.assertFalse(np.all(res1 == res3)) self.assertFalse(a1 == a2 or a2 == a3 or a3 == a4)
def __init__(self, data_params, params, delay, optimise_params, simulator, terminating_neurons=1, flag=False): ''' Calculation of the BiNAM and set up of the simulator :param data_params: BiNAM data parameters :param params: neuron params :param delay: delay in the synapses :param optimise_params: needs wCH_min, wCH_max, wCTInh = -0.001 :param simulator: nest, nmmmc1, ... :param terminating_neurons: Number of terminating neurons :param flag: change between SCM (False) and a single neuron in the CS(igma) population ''' # Generate BiNAM self.mat_in = data.generate(data_params["n_bits_in"], data_params["n_ones_in"], data_params["n_samples"]) self.mat_out = data.generate(data_params["n_bits_out"], data_params["n_ones_out"], data_params["n_samples"]) print "Data generated!" # set up simulator self.scm = pyscm.SpikeCounterModel(self.mat_in, self.mat_out) self.sim = pynl.PyNNLessIsolated(simulator) # Initial values self.weights = { "wCH": 0.00, "wCA": 0.00, "wCSigma": -0.00, "wCTExt": 0, # 0.02, "wCTInh": optimise_params["wCTInh"], "wAbort": 0 # -1.0 } self.wCH_min, self.wCH_max = optimise_params["wCH_min"], \ optimise_params[ "wCH_max"] self.params = params self.data_params = data_params self.n_ones_out = data_params["n_ones_out"] self.delay = delay self.terminating_neurons = terminating_neurons self.flag = flag self.simulator = simulator print "Optimisation set up done!"
def test_generate_all(self): res = generate(6, 3, 20) res = res[np.lexsort(res.T)] expected = np.array([ [1, 1, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0], [1, 0, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0], [1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 1], [1, 0, 0, 0, 1, 1], [0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1]], dtype=np.uint8) numpy.testing.assert_equal(res, expected)
def test_generate_all_multiple_abort_on_restart(self): res = generate(6, 3, 40, abort_on_restart=True) res = res[np.lexsort(res.T)] expected = np.array([ [1, 1, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0], [1, 0, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0], [1, 0, 0, 1, 1, 0], [0, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1], [1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 1], [1, 0, 0, 0, 1, 1], [0, 1, 0, 0, 1, 1], [0, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1]], dtype=np.uint8) numpy.testing.assert_equal(res, expected)
def test_generate_distribution(self): res = generate(6, 3, 20) for i in xrange(2, 22, 2): s = np.sum(res[0:i], 0) min_val = np.min(s) max_val = np.max(s) self.assertEqual(min_val, i // 2) self.assertEqual(max_val, i // 2)
# Read in neuron data with open("data/neuron_data.json", 'r') as outfile: dict = json.load(outfile) data_params = dict["data_params"] params = dict["neuron_params"] delay = dict["delay"] terminating_neurons = dict["terminating_neurons"] flag = dict["Simple_Network"] # Read in neuron weights, some still have to be set manually with open("data/optimised_weights.json", 'r') as outfile: weights = json.load(outfile) # Generate BiNAM mat_in = data.generate(data_params["n_bits_in"], data_params["n_ones_in"], data_params["n_samples"]) mat_out = data.generate(data_params["n_bits_out"], data_params["n_ones_out"], data_params["n_samples"]) print "Data generated!" # set up simulator scm = pyscm.SpikeCounterModel(mat_in, mat_out) sim = pynl.PyNNLess(sys.argv[1]) net, input_indices, _, input_times = scm.build(params=params, weights=weights, delay=delay, terminating_neurons=terminating_neurons, flag=flag) print "Preparations done" # Simulation
# Read in neuron data with open("data/neuron_data.json", 'r') as outfile: dict = json.load(outfile) data_params = dict["data_params"] params = dict["neuron_params"] delay = dict["delay"] terminating_neurons = dict["terminating_neurons"] flag = dict["Simple_Network"] # Read in neuron weights, some still have to be set manually with open("data/optimised_weights.json", 'r') as outfile: weights = json.load(outfile) # Generate BiNAM mat_in = data.generate(data_params["n_bits_in"], data_params["n_ones_in"], data_params["n_samples"]) mat_out = data.generate(data_params["n_bits_out"], data_params["n_ones_out"], data_params["n_samples"]) print "Data generated!" # set up simulator scm = pyscm.SpikeCounterModel(mat_in, mat_out) sim = pynl.PyNNLessIsolated(sys.argv[1]) [I, I_norm, fp, fn, I_start, I_norm_start, fp_start, fn_start] = np.zeros( (8, n)) values = np.linspace(0.1, 30, n) # Workaround for negative weights if (stri == "wCSigma"): values = np.linspace(-1, 0.001, n)