Ejemplo n.º 1
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())
Ejemplo n.º 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())
Ejemplo n.º 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"])
Ejemplo n.º 4
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"])
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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])
Ejemplo n.º 8
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"])
Ejemplo n.º 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"])
Ejemplo n.º 10
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])
Ejemplo n.º 11
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())
Ejemplo n.º 12
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())
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)