示例#1
0
 def test_neuron_count(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     pool = NetworkPool()
     pool.add_network(builder.build())
     pool.add_network(builder.build(topology_params={"multiplicity": 3}))
     self.assertEqual(20, pool.neuron_count())
示例#2
0
    def test_calculate_latencies(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50
        }
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)

        pool = NetworkPool(net1.build())
        pool.add_network(net2.build())

        output = (stub_simulation(net1.mat_out, data_params=dp1, latency=20.0) +
                stub_simulation(net2.mat_out, data_params=dp2, latency=30.0))

        analysis_instances = pool.build_analysis(output)
        np.testing.assert_almost_equal(
                [20.0] * dp1["n_samples"],
                analysis_instances[0].calculate_latencies())
        np.testing.assert_almost_equal(
                [30.0] * dp2["n_samples"],
                analysis_instances[1].calculate_latencies())
示例#3
0
    def test_preserve_data_params(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40,
            "n_bits": -1,
            "algorithm": "unique"
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50,
            "n_bits": -1,
            "algorithm": "random"
        }
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)

        pool = NetworkPool(net1.build())
        pool.add_network(net2.build())

        output = (stub_simulation(net1.mat_out, data_params=dp1) +
                stub_simulation(net2.mat_out, data_params=dp2))

        analysis_instances = pool.build_analysis(output)
        self.assertEqual(len(analysis_instances), 2)
        self.assertEqual(dp1, analysis_instances[0]["data_params"])
        self.assertEqual(dp2, analysis_instances[1]["data_params"])
示例#4
0
    def test_build_input(self):
        mat_in, mat_out = test_data()
        net = NetworkBuilder(mat_in, mat_out)
        times, indices, split = net.build_input()
        self.assertEqual([[100.0], [100.0], [0.0, 200.0], [200.0], [0.0]],
                         times)
        self.assertEqual([[1], [1], [0, 2], [2], [0]], indices)
        self.assertEqual([3], split)

        times, indices, split = net.build_input(
            topology_params={"multiplicity": 2})
        self.assertEqual([[100.0], [100.0], [100.0], [100.0], [0.0, 200.0],
                          [0.0, 200.0], [200.0], [200.0], [0.0], [0.0]], times)
        self.assertEqual(
            [[1], [1], [1], [1], [0, 2], [0, 2], [2], [2], [0], [0]], indices)
        self.assertEqual([3], split)

        times, indices, split = net.build_input(
            topology_params={"multiplicity": 2},
            input_params={"burst_size": 3})
        self.assertEqual(
            [[100.0, 101.0, 102.0], [100.0, 101.0, 102.0], [
                100.0, 101.0, 102.0
            ], [100.0, 101.0, 102.0], [0.0, 1.0, 2.0, 200.0, 201.0, 202.0],
             [0.0, 1.0, 2.0, 200.0, 201.0, 202.0], [200.0, 201.0, 202.0],
             [200.0, 201.0, 202.0], [0.0, 1.0, 2.0], [0.0, 1.0, 2.0]], times)
        self.assertEqual(
            [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [0, 0, 0, 2, 2, 2],
             [0, 0, 0, 2, 2, 2], [2, 2, 2], [2, 2, 2], [0, 0, 0], [0, 0, 0]],
            indices)
        self.assertEqual([3], split)
示例#5
0
 def test_neuron_count(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     pool = NetworkPool()
     pool.add_network(builder.build())
     pool.add_network(builder.build(topology_params={"multiplicity": 3}))
     self.assertEqual(20, pool.neuron_count())
示例#6
0
 def test_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{"multiplicity": 1},
         {"multiplicity": 2}])
     analysis_instances = net.build_analysis(time_mux_output_data)
     test_time_mux_res(self, analysis_instances)
示例#7
0
    def test_build_multi_input(self):
        mat_in, mat_out = test_data2()

        net = NetworkBuilder(mat_in, mat_out)
        times, indices, split = net.build_input(
            topology_params={"multiplicity": 2},
            input_params=[{
                "burst_size": 3
            }, {
                "burst_size": 2,
                "isi": 4.0
            }])

        self.assertEqual([[
            100.0, 101.0, 102.0, 1300.0, 1304.0
        ], [
            100.0, 101.0, 102.0, 1300.0, 1304.0
        ], [
            0.0, 1.0, 2.0, 100.0, 101.0, 102.0, 1200.0, 1204.0, 1300.0, 1304.0
        ], [
            0.0, 1.0, 2.0, 100.0, 101.0, 102.0, 1200.0, 1204.0, 1300.0, 1304.0
        ], [], [], [0.0, 1.0, 2.0, 1200.0, 1204.0],
                          [0.0, 1.0, 2.0, 1200.0, 1204.0]], times)
        self.assertEqual(
            [[1, 1, 1, 3, 3], [1, 1, 1, 3, 3], [0, 0, 0, 1, 1, 1, 2, 2, 3, 3],
             [0, 0, 0, 1, 1, 1, 2, 2, 3, 3], [], [], [0, 0, 0, 2, 2],
             [0, 0, 0, 2, 2]], indices)
        self.assertEqual([2, 4], split)
示例#8
0
    def test_build_multi_input(self):
        mat_in, mat_out = test_data2()

        net = NetworkBuilder(mat_in, mat_out)
        times, indices, split = net.build_input(
                topology_params={"multiplicity": 2},
                input_params=[{"burst_size": 3}, {"burst_size": 2, "isi": 4.0}])

        self.assertEqual([
            [100.0, 101.0, 102.0, 1300.0, 1304.0],
            [100.0, 101.0, 102.0, 1300.0, 1304.0],
            [0.0, 1.0, 2.0, 100.0, 101.0, 102.0, 1200.0, 1204.0, 1300.0, 1304.0],
            [0.0, 1.0, 2.0, 100.0, 101.0, 102.0, 1200.0, 1204.0, 1300.0, 1304.0],
            [], [],
            [0.0, 1.0, 2.0, 1200.0, 1204.0],
            [0.0, 1.0, 2.0, 1200.0, 1204.0]], times)
        self.assertEqual([
            [1, 1, 1, 3, 3],
            [1, 1, 1, 3, 3],
            [0, 0, 0, 1, 1, 1, 2, 2, 3, 3],
            [0, 0, 0, 1, 1, 1, 2, 2, 3, 3],
            [], [],
            [0, 0, 0, 2, 2],
            [0, 0, 0, 2, 2]], indices)
        self.assertEqual([2, 4], split)
示例#9
0
    def test_build_input(self):
        mat_in, mat_out = test_data()
        net = NetworkBuilder(mat_in, mat_out)
        times, indices, split = net.build_input()
        self.assertEqual([[100.0], [100.0], [0.0, 200.0], [200.0], [0.0]], times)
        self.assertEqual([[1], [1], [0, 2], [2], [0]], indices)
        self.assertEqual([3], split)

        times, indices, split = net.build_input(
                topology_params={"multiplicity": 2})
        self.assertEqual([[100.0], [100.0], [100.0], [100.0], [0.0, 200.0],
                [0.0, 200.0], [200.0], [200.0], [0.0], [0.0]], times)
        self.assertEqual([[1], [1], [1], [1], [0, 2], [0, 2],
                [2], [2], [0], [0]], indices)
        self.assertEqual([3], split)

        times, indices, split = net.build_input(
                topology_params={"multiplicity": 2},
                input_params={"burst_size": 3})
        self.assertEqual([[100.0, 101.0, 102.0], [100.0, 101.0, 102.0],
                [100.0, 101.0, 102.0], [100.0, 101.0, 102.0],
                [0.0, 1.0, 2.0, 200.0, 201.0, 202.0],
                [0.0, 1.0, 2.0, 200.0, 201.0, 202.0],
                [200.0, 201.0, 202.0], [200.0, 201.0, 202.0],
                [0.0, 1.0, 2.0], [0.0, 1.0, 2.0]], times)
        self.assertEqual([[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1],
                [0, 0, 0, 2, 2, 2], [0, 0, 0, 2, 2, 2], [2, 2, 2], [2, 2, 2],
                [0, 0, 0], [0, 0, 0]], indices)
        self.assertEqual([3], split)
示例#10
0
 def test_add_net_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{}, {}])
     pool = NetworkPool()
     pool.add_network(net)
     analysis_instances = pool.build_analysis(time_mux_output_data)
     test_time_mux_res(self, analysis_instances)
示例#11
0
 def test_add_net_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{}, {}])
     pool = NetworkPool()
     pool.add_network(net)
     analysis_instances = pool.build_analysis(time_mux_output_data)
     test_time_mux_res(self, analysis_instances)
示例#12
0
 def test_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{
         "multiplicity": 1
     }, {
         "multiplicity": 2
     }])
     analysis_instances = net.build_analysis(time_mux_output_data)
     test_time_mux_res(self, analysis_instances)
示例#13
0
    def test_neuron_count(self):
        mat_in, mat_out = test_data()
        builder = NetworkBuilder(mat_in, mat_out)

        net = builder.build()
        self.assertEqual(5, net.neuron_count())
        self.assertEqual(10, net.neuron_count(count_sources=True))

        net = builder.build(topology_params={"multiplicity": 3})
        self.assertEqual(15, net.neuron_count())
        self.assertEqual(30, net.neuron_count(count_sources=True))
示例#14
0
 def test_match(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build()
     output = [
         {}, {"spikes": [[0.0, 100.0], [101.0], [300.0, 301.0], [200.0], [201.0, 101.0]]},
     ]
     output_spikes, output_indices = net.match(output)
     self.assertEqual([[0.0, 100.0], [101.0], [300.0, 301.0], [200.0],
         [201.0, 101.0]], output_spikes)
     self.assertEqual([[0, 0], [1], [2, 2], [1], [2, 1]], output_indices)
示例#15
0
    def test_neuron_count(self):
        mat_in, mat_out = test_data()
        builder = NetworkBuilder(mat_in, mat_out)

        net = builder.build()
        self.assertEqual(5, net.neuron_count())
        self.assertEqual(10, net.neuron_count(count_sources=True))

        net = builder.build(topology_params={"multiplicity": 3})
        self.assertEqual(15, net.neuron_count())
        self.assertEqual(30, net.neuron_count(count_sources=True))
示例#16
0
 def test_add_nets_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{"multiplicity": 1},
         {"multiplicity": 2}])
     pool = NetworkPool()
     pool.add_networks([net, net, net])
     analysis_instances = pool.build_analysis(time_mux_output_data * 3)
     self.assertEqual(6, len(analysis_instances))
     test_time_mux_res(self, analysis_instances[0:2])
     test_time_mux_res(self, analysis_instances[2:4])
     test_time_mux_res(self, analysis_instances[4:6])
示例#17
0
    def test_preserve_meta_data(self):
        ud1 = {"foo": "bar"}
        ud2 = {"foo2": "bar2"}
        net1 = NetworkBuilder(data_params={})
        net2 = NetworkBuilder(data_params={})
        pool = NetworkPool(net1.build(meta_data=ud1))
        pool.add_network(net2.build(meta_data=ud2))

        output = (stub_simulation(net1.mat_out) + stub_simulation(net2.mat_out))

        analysis_instances = pool.build_analysis(output)
        self.assertEqual(len(analysis_instances), 2)
        self.assertEqual(ud1, analysis_instances[0]["meta_data"])
        self.assertEqual(ud2, analysis_instances[1]["meta_data"])
示例#18
0
 def test_add_nets_build_analysis(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(input_params=[{
         "multiplicity": 1
     }, {
         "multiplicity": 2
     }])
     pool = NetworkPool()
     pool.add_networks([net, net, net])
     analysis_instances = pool.build_analysis(time_mux_output_data * 3)
     self.assertEqual(6, len(analysis_instances))
     test_time_mux_res(self, analysis_instances[0:2])
     test_time_mux_res(self, analysis_instances[2:4])
     test_time_mux_res(self, analysis_instances[4:6])
示例#19
0
 def test_match(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build()
     output = [
         {},
         {
             "spikes": [[0.0, 100.0], [101.0], [300.0, 301.0], [200.0],
                        [201.0, 101.0]]
         },
     ]
     output_spikes, output_indices = net.match(output)
     self.assertEqual(
         [[0.0, 100.0], [101.0], [300.0, 301.0], [200.0], [201.0, 101.0]],
         output_spikes)
     self.assertEqual([[0, 0], [1], [2, 2], [1], [2, 1]], output_indices)
示例#20
0
 def test_build(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(topology_params={"params": {"cm": 0.2}})
     topo = {
         "connections": net["connections"],
         "populations": net["populations"]
     }
     times = net["input_times"]
     indices = net["input_indices"]
     compare({'connections': [
         ((0, 0), (1, 1), 0.03, 0.0),
         ((0, 0), (1, 4), 0.03, 0.0),
         ((0, 1), (1, 1), 0.03, 0.0),
         ((0, 1), (1, 4), 0.03, 0.0),
         ((0, 2), (1, 0), 0.03, 0.0),
         ((0, 2), (1, 1), 0.03, 0.0),
         ((0, 2), (1, 2), 0.03, 0.0),
         ((0, 2), (1, 3), 0.03, 0.0),
         ((0, 3), (1, 0), 0.03, 0.0),
         ((0, 3), (1, 1), 0.03, 0.0),
         ((0, 4), (1, 2), 0.03, 0.0),
         ((0, 4), (1, 3), 0.03, 0.0)],
         'populations': [
             {'count': 5,
             'params': [
                 {'spike_times': [100.0]},
                 {'spike_times': [100.0]},
                 {'spike_times': [0.0, 200.0]},
                 {'spike_times': [200.0]},
                 {'spike_times': [0.0]}
             ],
             'record': [],
             'type': 'SpikeSourceArray'
             },
             {'count': 5,
             'params': [
                 {'tau_refrac': 0.1, 'tau_m': 20.0, 'e_rev_E': 0.0,
             'i_offset': 0.0, 'cm': 0.2, 'e_rev_I': -70.0,
             'v_thresh': -50.0, 'tau_syn_E': 5.0, 'v_rest': -65.0,
             'tau_syn_I': 5.0, 'v_reset': -65.0}] * 5,
             'type': 'IF_cond_exp',
             'record': ['spikes']}],
             }, topo)
     self.assertEqual([[100.0], [100.0], [0.0, 200.0], [200.0], [0.0]],
             times)
     self.assertEqual([[1], [1], [0, 2], [2], [0]], indices)
示例#21
0
    def test_init_data(self):
        net = NetworkBuilder(
            data_params={
                "n_bits_in": 8,
                "n_bits_out": 10,
                "n_ones_in": 3,
                "n_ones_out": 5,
                "n_samples": 20
            })

        net2 = NetworkBuilder(net.mat_in, net.mat_out)

        self.assertEqual(8, net2.data_params["n_bits_in"])
        self.assertEqual(10, net2.data_params["n_bits_out"])
        self.assertEqual(3, net2.data_params["n_ones_in"])
        self.assertEqual(5, net2.data_params["n_ones_out"])
        self.assertEqual(20, net2.data_params["n_samples"])
示例#22
0
    def test_init_mat(self):
        mat_in, mat_out = test_data2()
        net = NetworkBuilder(mat_in, mat_out)

        self.assertEqual(4, net.data_params["n_bits_in"])
        self.assertEqual(6, net.data_params["n_bits_out"])
        self.assertEqual(2, net.data_params["n_ones_in"])
        self.assertEqual(3, net.data_params["n_ones_out"])
        self.assertEqual(2, net.data_params["n_samples"])
示例#23
0
 def test_auto_sample_count(self):
     net = NetworkBuilder(data_params={
         "n_bits_in": 16,
         "n_bits_out": 16,
         "n_ones_in": 2,
         "n_ones_out": 2
     })
     self.assertEqual(52, net.data_params["n_samples"])
     self.assertEqual(52, net.mat_in.shape[0])
     self.assertEqual(52, net.mat_out.shape[0])
示例#24
0
    def test_init_data_seed(self):
        net1 = NetworkBuilder(data_params={
            "n_bits_in": 8,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 5,
            "n_samples": 20
        },
                              seed=15412)
        net2 = NetworkBuilder(data_params={
            "n_bits_in": 8,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 5,
            "n_samples": 40
        },
                              seed=15412)

        # The first twenty samples must be equal
        np.testing.assert_equal(net1.mat_in, net2.mat_in[0:20])
        np.testing.assert_equal(net1.mat_out, net2.mat_out[0:20])
示例#25
0
def stub_simulation(mat_out, data_params={}, input_params={},
        topology_params={}, latency=1.0):
    # Build the output spike trains
    trains, _, _ = NetworkBuilder.build_spike_trains(mat_out, time_offs=latency,
            input_params=input_params, topology_params=topology_params)

    # Encapsulate the perfect spike trains in the PyNNLess output format, add
    # empty elements for the input populations
    data_params = DataParameters(data_params)
    nin = (data_params["n_bits_in"]
            * TopologyParameters(topology_params)["multiplicity"])
    return ([{}, {"spikes": [train for train in trains]}])
示例#26
0
    def test_calculate_latencies(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50
        }
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)

        pool = NetworkPool(net1.build())
        pool.add_network(net2.build())

        output = (
            stub_simulation(net1.mat_out, data_params=dp1, latency=20.0) +
            stub_simulation(net2.mat_out, data_params=dp2, latency=30.0))

        analysis_instances = pool.build_analysis(output)
        np.testing.assert_almost_equal(
            [20.0] * dp1["n_samples"],
            analysis_instances[0].calculate_latencies())
        np.testing.assert_almost_equal(
            [30.0] * dp2["n_samples"],
            analysis_instances[1].calculate_latencies())
示例#27
0
    def test_preserve_data_params(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40,
            "n_bits": -1,
            "algorithm": "unique"
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50,
            "n_bits": -1,
            "algorithm": "random"
        }
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)

        pool = NetworkPool(net1.build())
        pool.add_network(net2.build())

        output = (stub_simulation(net1.mat_out, data_params=dp1) +
                  stub_simulation(net2.mat_out, data_params=dp2))

        analysis_instances = pool.build_analysis(output)
        self.assertEqual(len(analysis_instances), 2)
        self.assertEqual(dp1, analysis_instances[0]["data_params"])
        self.assertEqual(dp2, analysis_instances[1]["data_params"])
示例#28
0
def stub_simulation(mat_out,
                    data_params={},
                    input_params={},
                    topology_params={},
                    latency=1.0):
    # Build the output spike trains
    trains, _, _ = NetworkBuilder.build_spike_trains(
        mat_out,
        time_offs=latency,
        input_params=input_params,
        topology_params=topology_params)

    # Encapsulate the perfect spike trains in the PyNNLess output format, add
    # empty elements for the input populations
    data_params = DataParameters(data_params)
    nin = (data_params["n_bits_in"] *
           TopologyParameters(topology_params)["multiplicity"])
    return ([{}, {"spikes": [train for train in trains]}])
示例#29
0
    def test_preserve_meta_data(self):
        ud1 = {"foo": "bar"}
        ud2 = {"foo2": "bar2"}
        net1 = NetworkBuilder(data_params={})
        net2 = NetworkBuilder(data_params={})
        pool = NetworkPool(net1.build(meta_data=ud1))
        pool.add_network(net2.build(meta_data=ud2))

        output = (stub_simulation(net1.mat_out) +
                  stub_simulation(net2.mat_out))

        analysis_instances = pool.build_analysis(output)
        self.assertEqual(len(analysis_instances), 2)
        self.assertEqual(ud1, analysis_instances[0]["meta_data"])
        self.assertEqual(ud2, analysis_instances[1]["meta_data"])
示例#30
0
    def test_calculate_output_matrix_stub_sim(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50
        }
        dp3 = {
            "n_bits_in": 5,
            "n_bits_out": 8,
            "n_ones_in": 1,
            "n_ones_out": 3,
            "n_samples": 20
        }
        tp1 = {"multiplicity": 1}
        tp2 = {"multiplicity": 3}
        tp3 = {"multiplicity": 2}

        # Build three networks
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)
        net3 = NetworkBuilder(data_params=dp3)

        # Add them to a network pool
        pool = NetworkPool()
        pool.add_networks([
            net1.build(topology_params=tp1),
            net2.build(topology_params=tp2),
            net3.build(topology_params=tp3)
        ])

        # Simulate some expected output
        output = (stub_simulation(
            net1.mat_out, data_params=dp1, topology_params=tp1, latency=20.0) +
                  stub_simulation(net2.mat_out,
                                  data_params=dp2,
                                  topology_params=tp2,
                                  latency=30.0) +
                  stub_simulation(net3.mat_out,
                                  data_params=dp3,
                                  topology_params=tp3,
                                  latency=10.0))

        # Fetch the analysis instance for the output
        analysis_instances = pool.build_analysis(output)

        # Compare the output matrices
        m1 = analysis_instances[0].calculate_output_matrix()
        m2 = analysis_instances[1].calculate_output_matrix()
        m3 = analysis_instances[2].calculate_output_matrix()
        np.testing.assert_almost_equal(net1.mat_out, m1)
        np.testing.assert_almost_equal(net2.mat_out, m2)
        np.testing.assert_almost_equal(net3.mat_out, m3)
示例#31
0
    def test_calculate_output_matrix_stub_sim(self):
        dp1 = {
            "n_bits_in": 14,
            "n_bits_out": 10,
            "n_ones_in": 3,
            "n_ones_out": 3,
            "n_samples": 40
        }
        dp2 = {
            "n_bits_in": 8,
            "n_bits_out": 16,
            "n_ones_in": 2,
            "n_ones_out": 4,
            "n_samples": 50
        }
        dp3 = {
            "n_bits_in": 5,
            "n_bits_out": 8,
            "n_ones_in": 1,
            "n_ones_out": 3,
            "n_samples": 20
        }
        tp1 = {
            "multiplicity": 1
        }
        tp2 = {
            "multiplicity": 3
        }
        tp3 = {
            "multiplicity": 2
        }

        # Build three networks
        net1 = NetworkBuilder(data_params=dp1)
        net2 = NetworkBuilder(data_params=dp2)
        net3 = NetworkBuilder(data_params=dp3)

        # Add them to a network pool
        pool = NetworkPool()
        pool.add_networks([
                net1.build(topology_params=tp1),
                net2.build(topology_params=tp2),
                net3.build(topology_params=tp3)])

        # Simulate some expected output
        output = (
                stub_simulation(net1.mat_out, data_params=dp1,
                        topology_params=tp1, latency=20.0) +
                stub_simulation(net2.mat_out, data_params=dp2,
                        topology_params=tp2, latency=30.0) +
                stub_simulation(net3.mat_out, data_params=dp3,
                        topology_params=tp3, latency=10.0))

        # Fetch the analysis instance for the output
        analysis_instances = pool.build_analysis(output)

        # Compare the output matrices
        m1 = analysis_instances[0].calculate_output_matrix()
        m2 = analysis_instances[1].calculate_output_matrix()
        m3 = analysis_instances[2].calculate_output_matrix()
        np.testing.assert_almost_equal(net1.mat_out, m1)
        np.testing.assert_almost_equal(net2.mat_out, m2)
        np.testing.assert_almost_equal(net3.mat_out, m3)
示例#32
0
    def test_build_topology(self):
        mat_in, mat_out = test_data()
        net = NetworkBuilder(mat_in, mat_out)
        topo = net.build_topology(topology_params={"params": {"cm": 0.2}})
        self.assertEqual(set(topo["connections"]), set([
            ((0, 0), (1, 1), 0.03, 0.0),
            ((0, 0), (1, 4), 0.03, 0.0),
            ((0, 1), (1, 1), 0.03, 0.0),
            ((0, 1), (1, 4), 0.03, 0.0),
            ((0, 2), (1, 0), 0.03, 0.0),
            ((0, 2), (1, 1), 0.03, 0.0),
            ((0, 2), (1, 2), 0.03, 0.0),
            ((0, 2), (1, 3), 0.03, 0.0),
            ((0, 3), (1, 0), 0.03, 0.0),
            ((0, 3), (1, 1), 0.03, 0.0),
            ((0, 4), (1, 2), 0.03, 0.0),
            ((0, 4), (1, 3), 0.03, 0.0)]))
        self.assertEqual(topo["populations"], [
                {'count': 5,
                 'params': [{}] * 5,
                 'type': 'SpikeSourceArray',
                 'record': []
                },
                {'count': 5,
                 'params': [{
                    'tau_refrac': 0.1,
                    'tau_m': 20.0,
                    'e_rev_E': 0.0,
                    'i_offset': 0.0,
                    'cm': 0.2,
                    'e_rev_I': -70.0,
                    'v_thresh': -50.0,
                    'tau_syn_E': 5.0,
                    'v_rest': -65.0,
                    'tau_syn_I': 5.0,
                    'v_reset': -65.0
                }] * 5,
                'record': ['spikes'],
                'type': 'IF_cond_exp'
                }
            ])

        net = NetworkBuilder(mat_in, mat_out)
        topo = net.build_topology(topology_params={"multiplicity": 2, "w": 0.1})
        self.assertEqual(set(topo["connections"]), set([
            ((0, 0), (1, 2), 0.1, 0.0),
            ((0, 0), (1, 3), 0.1, 0.0),
            ((0, 1), (1, 2), 0.1, 0.0),
            ((0, 1), (1, 3), 0.1, 0.0),
            ((0, 0), (1, 8), 0.1, 0.0),
            ((0, 0), (1, 9), 0.1, 0.0),
            ((0, 1), (1, 8), 0.1, 0.0),
            ((0, 1), (1, 9), 0.1, 0.0),
            ((0, 2), (1, 2), 0.1, 0.0),
            ((0, 2), (1, 3), 0.1, 0.0),
            ((0, 3), (1, 2), 0.1, 0.0),
            ((0, 3), (1, 3), 0.1, 0.0),
            ((0, 2), (1, 8), 0.1, 0.0),
            ((0, 2), (1, 9), 0.1, 0.0),
            ((0, 3), (1, 8), 0.1, 0.0),
            ((0, 3), (1, 9), 0.1, 0.0),
            ((0, 4), (1, 0), 0.1, 0.0),
            ((0, 4), (1, 1), 0.1, 0.0),
            ((0, 5), (1, 0), 0.1, 0.0),
            ((0, 5), (1, 1), 0.1, 0.0),
            ((0, 4), (1, 2), 0.1, 0.0),
            ((0, 4), (1, 3), 0.1, 0.0),
            ((0, 5), (1, 2), 0.1, 0.0),
            ((0, 5), (1, 3), 0.1, 0.0),
            ((0, 4), (1, 4), 0.1, 0.0),
            ((0, 4), (1, 5), 0.1, 0.0),
            ((0, 5), (1, 4), 0.1, 0.0),
            ((0, 5), (1, 5), 0.1, 0.0),
            ((0, 4), (1, 6), 0.1, 0.0),
            ((0, 4), (1, 7), 0.1, 0.0),
            ((0, 5), (1, 6), 0.1, 0.0),
            ((0, 5), (1, 7), 0.1, 0.0),
            ((0, 6), (1, 0), 0.1, 0.0),
            ((0, 6), (1, 1), 0.1, 0.0),
            ((0, 7), (1, 0), 0.1, 0.0),
            ((0, 7), (1, 1), 0.1, 0.0),
            ((0, 6), (1, 2), 0.1, 0.0),
            ((0, 6), (1, 3), 0.1, 0.0),
            ((0, 7), (1, 2), 0.1, 0.0),
            ((0, 7), (1, 3), 0.1, 0.0),
            ((0, 8), (1, 4), 0.1, 0.0),
            ((0, 8), (1, 5), 0.1, 0.0),
            ((0, 9), (1, 4), 0.1, 0.0),
            ((0, 9), (1, 5), 0.1, 0.0),
            ((0, 8), (1, 6), 0.1, 0.0),
            ((0, 8), (1, 7), 0.1, 0.0),
            ((0, 9), (1, 6), 0.1, 0.0),
            ((0, 9), (1, 7), 0.1, 0.0)]))
示例#33
0
    def test_build_topology(self):
        mat_in, mat_out = test_data()
        net = NetworkBuilder(mat_in, mat_out)
        topo = net.build_topology(topology_params={"params": {"cm": 0.2}})
        self.assertEqual(
            set(topo["connections"]),
            set([((0, 0), (1, 1), 0.03, 0.0), ((0, 0), (1, 4), 0.03, 0.0),
                 ((0, 1), (1, 1), 0.03, 0.0), ((0, 1), (1, 4), 0.03, 0.0),
                 ((0, 2), (1, 0), 0.03, 0.0), ((0, 2), (1, 1), 0.03, 0.0),
                 ((0, 2), (1, 2), 0.03, 0.0), ((0, 2), (1, 3), 0.03, 0.0),
                 ((0, 3), (1, 0), 0.03, 0.0), ((0, 3), (1, 1), 0.03, 0.0),
                 ((0, 4), (1, 2), 0.03, 0.0), ((0, 4), (1, 3), 0.03, 0.0)]))
        self.assertEqual(topo["populations"], [{
            'count': 5,
            'params': [{}] * 5,
            'type': 'SpikeSourceArray',
            'record': []
        }, {
            'count':
            5,
            'params': [{
                'tau_refrac': 0.1,
                'tau_m': 20.0,
                'e_rev_E': 0.0,
                'i_offset': 0.0,
                'cm': 0.2,
                'e_rev_I': -70.0,
                'v_thresh': -50.0,
                'tau_syn_E': 5.0,
                'v_rest': -65.0,
                'tau_syn_I': 5.0,
                'v_reset': -65.0
            }] * 5,
            'record': ['spikes'],
            'type':
            'IF_cond_exp'
        }])

        net = NetworkBuilder(mat_in, mat_out)
        topo = net.build_topology(topology_params={
            "multiplicity": 2,
            "w": 0.1
        })
        self.assertEqual(
            set(topo["connections"]),
            set([((0, 0), (1, 2), 0.1, 0.0), ((0, 0), (1, 3), 0.1, 0.0),
                 ((0, 1), (1, 2), 0.1, 0.0), ((0, 1), (1, 3), 0.1, 0.0),
                 ((0, 0), (1, 8), 0.1, 0.0), ((0, 0), (1, 9), 0.1, 0.0),
                 ((0, 1), (1, 8), 0.1, 0.0), ((0, 1), (1, 9), 0.1, 0.0),
                 ((0, 2), (1, 2), 0.1, 0.0), ((0, 2), (1, 3), 0.1, 0.0),
                 ((0, 3), (1, 2), 0.1, 0.0), ((0, 3), (1, 3), 0.1, 0.0),
                 ((0, 2), (1, 8), 0.1, 0.0), ((0, 2), (1, 9), 0.1, 0.0),
                 ((0, 3), (1, 8), 0.1, 0.0), ((0, 3), (1, 9), 0.1, 0.0),
                 ((0, 4), (1, 0), 0.1, 0.0), ((0, 4), (1, 1), 0.1, 0.0),
                 ((0, 5), (1, 0), 0.1, 0.0), ((0, 5), (1, 1), 0.1, 0.0),
                 ((0, 4), (1, 2), 0.1, 0.0), ((0, 4), (1, 3), 0.1, 0.0),
                 ((0, 5), (1, 2), 0.1, 0.0), ((0, 5), (1, 3), 0.1, 0.0),
                 ((0, 4), (1, 4), 0.1, 0.0), ((0, 4), (1, 5), 0.1, 0.0),
                 ((0, 5), (1, 4), 0.1, 0.0), ((0, 5), (1, 5), 0.1, 0.0),
                 ((0, 4), (1, 6), 0.1, 0.0), ((0, 4), (1, 7), 0.1, 0.0),
                 ((0, 5), (1, 6), 0.1, 0.0), ((0, 5), (1, 7), 0.1, 0.0),
                 ((0, 6), (1, 0), 0.1, 0.0), ((0, 6), (1, 1), 0.1, 0.0),
                 ((0, 7), (1, 0), 0.1, 0.0), ((0, 7), (1, 1), 0.1, 0.0),
                 ((0, 6), (1, 2), 0.1, 0.0), ((0, 6), (1, 3), 0.1, 0.0),
                 ((0, 7), (1, 2), 0.1, 0.0), ((0, 7), (1, 3), 0.1, 0.0),
                 ((0, 8), (1, 4), 0.1, 0.0), ((0, 8), (1, 5), 0.1, 0.0),
                 ((0, 9), (1, 4), 0.1, 0.0), ((0, 9), (1, 5), 0.1, 0.0),
                 ((0, 8), (1, 6), 0.1, 0.0), ((0, 8), (1, 7), 0.1, 0.0),
                 ((0, 9), (1, 6), 0.1, 0.0), ((0, 9), (1, 7), 0.1, 0.0)]))
示例#34
0
 def test_build(self):
     mat_in, mat_out = test_data()
     builder = NetworkBuilder(mat_in, mat_out)
     net = builder.build(topology_params={"params": {"cm": 0.2}})
     topo = {
         "connections": net["connections"],
         "populations": net["populations"]
     }
     times = net["input_times"]
     indices = net["input_indices"]
     compare(
         {
             'connections': [((0, 0), (1, 1), 0.03, 0.0),
                             ((0, 0), (1, 4), 0.03, 0.0),
                             ((0, 1), (1, 1), 0.03, 0.0),
                             ((0, 1), (1, 4), 0.03, 0.0),
                             ((0, 2), (1, 0), 0.03, 0.0),
                             ((0, 2), (1, 1), 0.03, 0.0),
                             ((0, 2), (1, 2), 0.03, 0.0),
                             ((0, 2), (1, 3), 0.03, 0.0),
                             ((0, 3), (1, 0), 0.03, 0.0),
                             ((0, 3), (1, 1), 0.03, 0.0),
                             ((0, 4), (1, 2), 0.03, 0.0),
                             ((0, 4), (1, 3), 0.03, 0.0)],
             'populations': [{
                 'count':
                 5,
                 'params': [{
                     'spike_times': [100.0]
                 }, {
                     'spike_times': [100.0]
                 }, {
                     'spike_times': [0.0, 200.0]
                 }, {
                     'spike_times': [200.0]
                 }, {
                     'spike_times': [0.0]
                 }],
                 'record': [],
                 'type':
                 'SpikeSourceArray'
             }, {
                 'count':
                 5,
                 'params': [{
                     'tau_refrac': 0.1,
                     'tau_m': 20.0,
                     'e_rev_E': 0.0,
                     'i_offset': 0.0,
                     'cm': 0.2,
                     'e_rev_I': -70.0,
                     'v_thresh': -50.0,
                     'tau_syn_E': 5.0,
                     'v_rest': -65.0,
                     'tau_syn_I': 5.0,
                     'v_reset': -65.0
                 }] * 5,
                 'type':
                 'IF_cond_exp',
                 'record': ['spikes']
             }],
         }, topo)
     self.assertEqual([[100.0], [100.0], [0.0, 200.0], [200.0], [0.0]],
                      times)
     self.assertEqual([[1], [1], [0, 2], [2], [0]], indices)