Пример #1
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"])
Пример #2
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())
Пример #3
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())
Пример #4
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())
Пример #5
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"])
Пример #6
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())
Пример #7
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))
Пример #8
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))
Пример #9
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"])
Пример #10
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"])
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #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_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])
Пример #18
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)
Пример #19
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)
Пример #20
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)
Пример #21
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)
Пример #22
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)