def test_BaseModel_lnprior(self): scat = Sphere(r=prior.Gaussian(1, 1), n=prior.Gaussian(1, 1), center=[10, 10, 10]) mod = Model(scat, noise_sd=0.1) # Desired: log(sqrt(0.5/pi))-1/2 desired_sigma = -1.4189385332 assert_obj_close(mod.lnprior({'n': 0, 'r': 0}), desired_sigma * 2)
def test_yaml_round_trip_with_dict(self): sphere = make_sphere() for key in self.model_keywords: value = {'red': 1, 'green': 0} kwargs = {key: value} model = Model(sphere, **kwargs) with self.subTest(key=key): reloaded = take_yaml_round_trip(model) self.assertEqual(reloaded, model)
def test_yaml_round_trip_with_xarray(self): sphere = make_sphere() for key in self.model_keywords: value = xr.DataArray([1, 0.], dims=['illumination'], coords={'illumination': ['red', 'green']}) kwargs = {key: value} model = Model(sphere, **kwargs) with self.subTest(key=key): reloaded = take_yaml_round_trip(model) self.assertEqual(reloaded, model)
def test_default_fit_strategy_is_nmpfit(self): model = Model(Sphere()) default_strategy = model.validate_strategy(None, 'fit') self.assertEqual(NmpfitStrategy(), default_strategy)
def test_initializable(self): scatterer = make_sphere() model = Model(scatterer) self.assertTrue(model is not None)
def test_parallel_tempering_not_implemented(self): model = Model(Sphere()) self.assertRaises(ValueError, model.validate_strategy, 'parallel tempering', 'sample')
def test_sample_strategy_names(self): model = Model(Sphere()) for name, strategy in available_sampling_strategies.items(): if strategy is not NotImplemented: strategy_by_name = model.validate_strategy(name, 'sample') self.assertEqual(strategy(), strategy_by_name)
def test_fit_strategy_names(self): model = Model(Sphere()) for name, strategy in available_fit_strategies.items(): strategy_by_name = model.validate_strategy(name, 'fit') self.assertEqual(strategy(), strategy_by_name)
def test_default_sampling_strategy_is_emcee(self): model = Model(Sphere()) default_strategy = model.validate_strategy(None, 'sample') self.assertTrue(isinstance(default_strategy, EmceeStrategy))