def test_build_parameters(self): experiment = Experiment() input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "input.sigma_t": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 3) self.assertEqual(len(topology_params), 1) self.assertEqual(input_params[0]["sigma_t"], 0.0) self.assertEqual(input_params[1]["sigma_t"], 1.0) self.assertEqual(input_params[2]["sigma_t"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor( sweeps={"input.sigma_t": { "min": 0.0, "max": 2.0, "count": 3 }})) self.assertEqual(len(input_params), 3) self.assertEqual(len(topology_params), 1) self.assertEqual(input_params[0]["sigma_t"], 0.0) self.assertEqual(input_params[1]["sigma_t"], 1.0) self.assertEqual(input_params[2]["sigma_t"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "topology.params.tau_m": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 3) self.assertEqual(topology_params[0]["topology"]["params"]["tau_m"], 0.0) self.assertEqual(topology_params[1]["topology"]["params"]["tau_m"], 1.0) self.assertEqual(topology_params[2]["topology"]["params"]["tau_m"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "topology.param_noise.tau_m": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 3) self.assertEqual( topology_params[0]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual( topology_params[1]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual( topology_params[2]["topology"]["param_noise"]["tau_m"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps=collections.OrderedDict([( "topology.param_noise.tau_m", [0.0, 1.0, 2.0]), ("data.n_ones_in", [1, 2])]))) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 6) self.assertEqual( topology_params[0]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual( topology_params[1]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual( topology_params[2]["topology"]["param_noise"]["tau_m"], 2.0) self.assertEqual( topology_params[3]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual( topology_params[4]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual( topology_params[5]["topology"]["param_noise"]["tau_m"], 2.0) self.assertEqual(topology_params[0]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[1]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[2]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[3]["data"]["n_ones_in"], 2) self.assertEqual(topology_params[4]["data"]["n_ones_in"], 2) self.assertEqual(topology_params[5]["data"]["n_ones_in"], 2)
def test_build_parameters(self): experiment = Experiment() input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "input.sigma_t": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 3) self.assertEqual(len(topology_params), 1) self.assertEqual(input_params[0]["sigma_t"], 0.0) self.assertEqual(input_params[1]["sigma_t"], 1.0) self.assertEqual(input_params[2]["sigma_t"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "input.sigma_t": {"min": 0.0, "max": 2.0, "count": 3} })) self.assertEqual(len(input_params), 3) self.assertEqual(len(topology_params), 1) self.assertEqual(input_params[0]["sigma_t"], 0.0) self.assertEqual(input_params[1]["sigma_t"], 1.0) self.assertEqual(input_params[2]["sigma_t"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "topology.params.tau_m": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 3) self.assertEqual(topology_params[0]["topology"]["params"]["tau_m"], 0.0) self.assertEqual(topology_params[1]["topology"]["params"]["tau_m"], 1.0) self.assertEqual(topology_params[2]["topology"]["params"]["tau_m"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps={ "topology.param_noise.tau_m": [0.0, 1.0, 2.0], })) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 3) self.assertEqual(topology_params[0]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual(topology_params[1]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual(topology_params[2]["topology"]["param_noise"]["tau_m"], 2.0) input_params, topology_params = experiment.build_parameters( ExperimentDescriptor(sweeps=collections.OrderedDict([ ("topology.param_noise.tau_m", [0.0, 1.0, 2.0]), ("data.n_ones_in", [1, 2]) ]))) self.assertEqual(len(input_params), 1) self.assertEqual(len(topology_params), 6) self.assertEqual(topology_params[0]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual(topology_params[1]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual(topology_params[2]["topology"]["param_noise"]["tau_m"], 2.0) self.assertEqual(topology_params[3]["topology"]["param_noise"]["tau_m"], 0.0) self.assertEqual(topology_params[4]["topology"]["param_noise"]["tau_m"], 1.0) self.assertEqual(topology_params[5]["topology"]["param_noise"]["tau_m"], 2.0) self.assertEqual(topology_params[0]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[1]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[2]["data"]["n_ones_in"], 1) self.assertEqual(topology_params[3]["data"]["n_ones_in"], 2) self.assertEqual(topology_params[4]["data"]["n_ones_in"], 2) self.assertEqual(topology_params[5]["data"]["n_ones_in"], 2)
def test_validate_keys(self): Experiment.validate_keys(["input.sigma_t", "input.p0"]) Experiment.validate_keys(["topology.w"]) Experiment.validate_keys(["topology.params.tau_m"]) Experiment.validate_keys(["topology.param_noise.tau_m"]) Experiment.validate_keys(["data.n_ones_in"]) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys([""])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["bla"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["bla.blub"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["input"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["input.blub"])) self.assertRaises( ExperimentException, lambda: Experiment.validate_keys(["input.sigma_t.test"])) self.assertRaises( ExperimentException, lambda: Experiment.validate_keys(["topology.params.w"]))
def test_validate_keys(self): Experiment.validate_keys(["input.sigma_t", "input.p0"]) Experiment.validate_keys(["topology.w"]) Experiment.validate_keys(["topology.params.tau_m"]) Experiment.validate_keys(["topology.param_noise.tau_m"]) Experiment.validate_keys(["data.n_ones_in"]) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys([""])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["bla"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["bla.blub"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["input"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["input.blub"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["input.sigma_t.test"])) self.assertRaises(ExperimentException, lambda: Experiment.validate_keys(["topology.params.w"]))