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])
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])
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)
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)