Esempio n. 1
0
 def test_raises_error(self):
     MP = ModelParameters()
     MP.add_model_parameter('aa', 0, minimum=-10., maximum=10)
     MP.add_model_parameter('bb', 5, minimum=100., maximum=10)
     MP._openparameterstructure(nbatch=1)
     with self.assertRaises(SystemExit, msg='Min > Max'):
         MP._check_parameter_limits()
 def test_initial_parameter_outside(self):
     MP = ModelParameters()
     MP.add_model_parameter('aa', 0, minimum = -10., maximum = 10)
     MP.add_model_parameter('bb', 11, minimum = -10., maximum = 10)
     MP._openparameterstructure(nbatch=1)
     with self.assertRaises(SystemExit, msg = 'Initial value outside of bounds.'):
         MP._check_initial_values_wrt_parameter_limits()
Esempio n. 3
0
 def test_scan_for_local_variables_with_sample_false(self):
     MP = ModelParameters()
     MP.add_model_parameter(name='m', theta0=0.2, local=0, sample=False)
     MP.add_model_parameter(name='b', theta0=-0.5, local=1)
     local = MP.scan_for_local_variables(nbatch=2, parameters=MP.parameters)
     self.assertTrue(np.array_equal(local, np.array([1, 2])),
                     msg=str('Expect arrays to match: {} neq {}'.format(
                         local, np.array([1, 2]))))
Esempio n. 4
0
 def standard_check(self, theta0=1.0, name='$p_{0}$'):
     MP = ModelParameters()
     MP.add_model_parameter(name=name, theta0=theta0)
     self.assertEqual(MP.parameters[0]['theta0'], theta0)
     self.assertEqual(MP.parameters[0]['name'], name)
     self.assertEqual(MP.parameters[0]['minimum'], -np.inf)
     self.assertEqual(MP.parameters[0]['maximum'], np.inf)
     self.assertEqual(MP.parameters[0]['prior_mu'], np.zeros([1]))
     self.assertEqual(MP.parameters[0]['prior_sigma'], np.inf)
     self.assertEqual(MP.parameters[0]['sample'], 1)
     self.assertEqual(MP.parameters[0]['local'], 0)
Esempio n. 5
0
 def test_get_parameter_features(self):
     MP = ModelParameters()
     MP.add_model_parameter(name='a1', theta0=0.1, minimum=0, maximum=1)
     MP.add_model_parameter(name='a2', theta0=0.2, minimum=0, maximum=1)
     MP.add_model_parameter(name='a3', theta0=0.3, minimum=0, maximum=1)
     npar, low_lim, upp_lim = get_parameter_features(MP.parameters)
     self.assertEqual(npar, 3, msg='Expect to find 3 parameters')
     self.assertTrue(np.array_equal(low_lim, np.zeros([3])),
                     msg=str('Expect low_lim all zero: {} neq {}'.format(
                         low_lim, np.zeros([3]))))
     self.assertTrue(np.array_equal(upp_lim, np.ones([3])),
                     msg=str('Expect upp_lim all one: {} neq {}'.format(
                         upp_lim, np.ones([3]))))
 def test_results_to_params(self):
     MP = ModelParameters()
     MP.add_model_parameter('aa', 0)
     MP._openparameterstructure(nbatch=1)
      # define minimal results dictionary
     results = {'parind': MP._parind, 'names': MP._names, 'local': MP._local, 'theta': [1.2]}
     # initialize default options
     SO = SimulationOptions()
     SO.define_simulation_options(verbosity=0)
     MP.display_parameter_settings(verbosity = SO.verbosity, no_adapt = MP._no_adapt)
     MP._results_to_params(results, 1)
     MP._openparameterstructure(nbatch=1)
     MP.display_parameter_settings(verbosity = SO.verbosity, no_adapt = MP._no_adapt)
     self.assertEqual(MP.parameters[0]['theta0'], results['theta'][0])
 def test_parameter_display_set_2(self):
     MP = ModelParameters()
     MP.add_model_parameter(name = 'm', theta0 = 2., minimum = -10, maximum = np.inf, sample = True)
     MP.add_model_parameter(name = 'b', theta0 = -5., minimum = -10, maximum = 100, sample = False)
     MP.add_model_parameter(name = 'b2', theta0 = -5.3e6, minimum = -1e7, maximum = 1e6, sample = True)
     MP._openparameterstructure(nbatch = 1)
     
     MP.display_parameter_settings(verbosity = None, no_adapt = None)
Esempio n. 8
0
 def test_get_parameter_features_with_inf_bounds(self):
     MP = ModelParameters()
     MP.add_model_parameter(name='a1',
                            theta0=0.1,
                            minimum=-np.inf,
                            maximum=1)
     MP.add_model_parameter(name='a2', theta0=0.2, minimum=0, maximum=1)
     MP.add_model_parameter(name='a3',
                            theta0=0.3,
                            minimum=0,
                            maximum=np.inf)
     npar, low_lim, upp_lim = get_parameter_features(MP.parameters)
     expect_low_lim = np.array([0.1 - 100 * 0.1, 0, 0])
     expect_upp_lim = np.array([1, 1, 0.3 + 100 * 0.3])
     self.assertEqual(npar, 3, msg='Expect to find 3 parameters')
     self.assertTrue(np.array_equal(low_lim, expect_low_lim),
                     msg=str('Expect low_lim finite: {} neq {}'.format(
                         low_lim, expect_low_lim)))
     self.assertTrue(np.array_equal(upp_lim, expect_upp_lim),
                     msg=str('Expect upp_lim finite: {} neq {}'.format(
                         upp_lim, expect_upp_lim)))
Esempio n. 9
0
 def test_initial_parameter_okay(self):
     MP = ModelParameters()
     MP.add_model_parameter('aa', 0, minimum=-10., maximum=10)
     MP.add_model_parameter('bb', 9, minimum=-10., maximum=10)
     MP._openparameterstructure(nbatch=1)
     self.assertTrue(MP._check_initial_values_wrt_parameter_limits())