def __init__(self, scatterers, warn=True): scatterers = ensure_listlike(scatterers) self.warn = warn for s in ensure_listlike(scatterers): if not isinstance(s, Sphere): raise InvalidScatterer( self, "Spheres expects all component " + "scatterers to be Spheres.\n" + repr(s) + " is not a Sphere") super().__init__(scatterers) if self.overlaps and self.warn: warnings.warn(OverlapWarning(self, self.overlaps))
def __init__(self, scatterer, calc_func, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', alpha=None, use_random_fraction=None, constraints=[]): super().__init__(scatterer, medium_index, illum_wavelen, illum_polarization, theory) self.calc_func = calc_func self.use_random_fraction = use_random_fraction self._use_parameter(alpha, 'alpha') if len(self.parameters) == 0: raise ParameterSpecificationError("You must specify at least one parameter to vary in a fit") self.constraints = ensure_listlike(constraints)
def __init__(self, scatterer, noise_sd=None, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', constraints=[]): self.scatterer = scatterer self.constraints = ensure_listlike(constraints) self._parameters = [] self._use_parameters(scatterer.parameters, False) if not (np.isscalar(noise_sd) or isinstance(noise_sd, (Prior, dict))): noise_sd = ensure_array(noise_sd) parameters_to_use = { 'medium_index': medium_index, 'illum_wavelen': illum_wavelen, 'illum_polarization': illum_polarization, 'theory': theory, 'noise_sd': noise_sd, } self._check_parameters_are_not_xarray(parameters_to_use) self._use_parameters(parameters_to_use)
def __new__(self, guess=None, limit=None, name=None, **kwargs): fit_warning('hp.inference.prior', 'Parameter') if len(ensure_listlike(limit)) == 2: if limit[0] == limit[1]: return Parameter(guess, limit[0]) out = Uniform(limit[0], limit[1], guess, name) elif guess is None and limit is not None: return limit elif guess == limit and limit is not None: return guess elif limit is None and guess is not None: out = Uniform(-np.inf, np.inf, guess, name) else: raise ParameterSpecificationError( "Can't interpret Parameter with limit {} and guess {}".format( limit, guess)) setattr(out, 'limit', limit) setattr(out, 'kwargs', kwargs) return out
def __init__(self, transformation, base_prior, name=None): """Composite prior composed of one or more base priors transformed by a function. Note there are no `prob` and `lnprob` methods since those just depend on the probabilities of the underlying base priors. Parameters ---------- transformation : func Function to apply to base prior to get transformed value base_prior : Prior object or listlike containing Priors Values to be passed into transformation function name : string or None, optional The name of the parameter. """ self.base_prior = tuple(ensure_listlike(base_prior)) if callable(transformation): self.transformation = transformation else: msg = 'transformation must be function of one or more base priors' raise TypeError(msg) self.name = name
def __init__(self, scatterer, noise_sd=None, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', constraints=[]): dummy_parameters = {key: [0, 0, 0] for key in scatterer.parameters} self._dummy_scatterer = scatterer.from_parameters(dummy_parameters) self.theory = theory self.constraints = ensure_listlike(constraints) if not (np.isscalar(noise_sd) or isinstance(noise_sd, (Prior, dict))): noise_sd = ensure_array(noise_sd) optics = [medium_index, illum_wavelen, illum_polarization, noise_sd] optics_parameters = {key: val for key, val in zip(OPTICS_KEYS, optics)} self._parameters = [] self._parameter_names = [] self._maps = { 'scatterer': self._convert_to_map(scatterer.parameters), 'optics': self._convert_to_map(optics_parameters) }
def __init__(self, scatterer, calc_func, medium_index=None, illum_wavelen=None, illum_polarization=None, theory='auto', alpha=None, use_random_fraction=None, constraints=[]): super().__init__(scatterer, medium_index, illum_wavelen, illum_polarization, theory) self.calc_func = calc_func self.use_random_fraction = use_random_fraction self._use_parameter(alpha, 'alpha') if len(self.parameters) == 0: raise ParameterSpecificationError( "You must specify at least one parameter to vary in a fit") self.constraints = ensure_listlike(constraints)
def test_ensure_listlike(self): self.assertEqual(ensure_listlike(None), []) self.assertEqual(ensure_listlike(1), [1]) self.assertEqual(ensure_listlike([1]), [1])