parameterspace.priors.uniform
Uniform (BasePrior)
Uninformed prior that puts equal weight on every value.
Source code in parameterspace/priors/uniform.py
class Uniform(BasePrior):
"""Uninformed prior that puts equal weight on every value."""
@store_init_arguments
def __init__(self):
super().__init__([0, 1])
def pdf(self, value):
"""Calculate probability density function value.
Return constant for values inside the bounds, zero if outside, and NaN for NaNs.
"""
value = np.atleast_1d(value)
active_idx = np.isfinite(value)
pdf = np.full(value.shape, np.nan)
inside = np.logical_and(
self.bounds[0] <= value[active_idx], value[active_idx] <= self.bounds[1]
)
pdf[active_idx] = 1.0 / (self.bounds[1] - self.bounds[0]) * (inside)
return pdf.squeeze()
def sample(self, num_samples=None, random_state=np.random):
return random_state.uniform(
low=self.bounds[0], high=self.bounds[1], size=num_samples
)
def __repr__(self):
"""Minimal information about the Prior."""
return f"Uniform prior in the interval [{self.bounds[0]}, {self.bounds[1]}]."
pdf(self, value)
Calculate probability density function value.
Return constant for values inside the bounds, zero if outside, and NaN for NaNs.
Source code in parameterspace/priors/uniform.py
def pdf(self, value):
"""Calculate probability density function value.
Return constant for values inside the bounds, zero if outside, and NaN for NaNs.
"""
value = np.atleast_1d(value)
active_idx = np.isfinite(value)
pdf = np.full(value.shape, np.nan)
inside = np.logical_and(
self.bounds[0] <= value[active_idx], value[active_idx] <= self.bounds[1]
)
pdf[active_idx] = 1.0 / (self.bounds[1] - self.bounds[0]) * (inside)
return pdf.squeeze()
sample(self, num_samples=None, random_state=<module 'numpy.random' from '/home/runner/.cache/pypoetry/virtualenvs/parameterspace-9AYrJA9h-py3.8/lib/python3.8/site-packages/numpy/random/__init__.py'>)
Draw random samples from the prior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_samples |
[description] |
None |
Returns:
Type | Description |
---|---|
[descriptions] |
Source code in parameterspace/priors/uniform.py
def sample(self, num_samples=None, random_state=np.random):
return random_state.uniform(
low=self.bounds[0], high=self.bounds[1], size=num_samples
)