Skip to content

Commit

Permalink
Update odcstring of utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Jul 31, 2023
1 parent 6772eca commit d4e0f20
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
14 changes: 7 additions & 7 deletions alea/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class StatisticalModel:
- a likelihood function
ll(self, parameter_1, parameter_2... parameter_n):
A function of a set of named parameters which
returns a float expressing the loglikelihood for observed data given these parameters.
Return a float expressing the loglikelihood for observed data given these parameters.
- a data generation function
generate_data(self, parameter_1, parameter_2... parameter_n)
A function of the same set of named parameters returns a full data set.
A function of the same set of named parameters Return a full data set.
- Methods that you must implement:
- _ll
- _generate_data
Expand Down Expand Up @@ -104,7 +104,7 @@ def _check_ll_and_generate_data_signature(self):
"ll and generate_data must have the same signature (parameters)")

def _ll(self, **kwargs) -> float:
"""Likelihood function, returns the loglikelihood for the given parameters."""
"""Likelihood function, Return the loglikelihood for the given parameters."""
raise NotImplementedError(
"You must write a likelihood function (_ll) for your statistical model"
" or use a subclass where it is written for you")
Expand All @@ -118,7 +118,7 @@ def _generate_data(self, **kwargs):
@_needs_data
def ll(self, **kwargs) -> float:
"""
Likelihod function, returns the loglikelihood for the given parameters.
Likelihod function, Return the loglikelihood for the given parameters.
The parameters are passed as keyword arguments, positional arguments are not possible.
If a parameter is not given, the default value is used.
Expand Down Expand Up @@ -209,7 +209,7 @@ def nominal_expectation_values(self):

def get_likelihood_term_from_name(self, likelihood_name: str):
"""
Returns the index of a likelihood term if the likelihood has several names
Return the index of a likelihood term if the likelihood has several names
:param likelihood_name: name of the likelihood term
:type likelihood_name: str
Expand All @@ -223,7 +223,7 @@ def get_likelihood_term_from_name(self, likelihood_name: str):
raise NotImplementedError("The attribute likelihood_names is not defined.")

def get_parameter_list(self):
"""Returns a set of all parameters that the generate_data and likelihood accepts"""
"""Return a set of all parameters that the generate_data and likelihood accepts"""
return self.parameters.names

def make_objective(self, minus=True, **kwargs):
Expand Down Expand Up @@ -296,7 +296,7 @@ def _confidence_interval_checks(
confidence_interval_kind: str,
**kwargs):
"""
Helper function for confidence_interval that does the input checks and returns bounds
Helper function for confidence_interval that does the input checks and Return bounds
:param poi_name: name of the parameter of interest
:type poi_name: str
Expand Down
2 changes: 1 addition & 1 deletion alea/models/blueice_extended_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def from_config(cls, config_file_path: str) -> "BlueiceExtendedModel":

@property
def data(self) -> dict:
"""Returns the data of the statistical model."""
"""Return the data of the statistical model."""
return super().data

@data.setter
Expand Down
16 changes: 8 additions & 8 deletions alea/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __repr__(self) -> str:
@property
def uncertainty(self) -> float or Any:
"""
Returns the uncertainty of the parameter.
Return the uncertainty of the parameter.
If the uncertainty is a string, it can be evaluated as a numpy or scipy function.
"""
if isinstance(self._uncertainty, str):
Expand All @@ -89,7 +89,7 @@ def uncertainty(self, value: float or str) -> None:

@property
def fit_guess(self) -> float:
"""Returns the initial guess for fitting the parameter."""
"""Return the initial guess for fitting the parameter."""
# make sure to only return fit_guess if fittable
if self._fit_guess is not None and not self.fittable:
raise ValueError(
Expand All @@ -102,14 +102,14 @@ def fit_guess(self, value: float) -> None:
self._fit_guess = value

def __eq__(self, other: object) -> bool:
"""Returns True if all attributes are equal"""
"""Return True if all attributes are equal"""
if isinstance(other, Parameter):
return all(getattr(self, k) == getattr(other, k) for k in self.__dict__)
else:
return False

def value_in_fit_limits(self, value: float) -> bool:
"""Returns True if value is within fit_limits"""
"""Return True if value is within fit_limits"""
if self.fit_limits is None:
return True
elif self.fit_limits[0] is None:
Expand All @@ -132,7 +132,7 @@ def __init__(self):
self.parameters: Dict[str, Parameter] = {}

def __iter__(self) -> iter:
"""Returns an iterator over the parameters. Each iteration returns a Parameter object."""
"""Return an iterator over the parameters. Each iteration Return a Parameter object."""
return iter(self.parameters.values())

@classmethod
Expand Down Expand Up @@ -274,7 +274,7 @@ def __call__(
self, return_fittable: Optional[bool] = False,
**kwargs: Any) -> Dict[str, float]:
"""
Returns a dictionary of parameter values, optionally filtered
Return a dictionary of parameter values, optionally filtered
to return only fittable parameters.
:param return_fittable: Indicates if only fittable parameters should be returned.
Expand Down Expand Up @@ -332,7 +332,7 @@ def __getitem__(self, name: str) -> Parameter:
raise KeyError(f"Key '{name}' not found.")

def __eq__(self, other: object) -> bool:
"""Returns True if all parameters are equal"""
"""Return True if all parameters are equal"""
if isinstance(other, Parameters):
names = set(self.names + other.names)
return all(getattr(self, n) == getattr(other, n) for n in names)
Expand All @@ -341,7 +341,7 @@ def __eq__(self, other: object) -> bool:

def values_in_fit_limits(self, **kwargs: Any) -> bool:
"""
Returns True if all values are within the fit limits.
Return True if all values are within the fit limits.
:param kwargs: The parameter values to check.
:return: True if all values are within the fit limits.
Expand Down
28 changes: 18 additions & 10 deletions alea/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


def get_analysis_space(analysis_space: dict) -> list:
"""Convert analysis_space to a list of tuples with evaluated values."""
eval_analysis_space = []

for element in analysis_space:
Expand All @@ -22,9 +23,7 @@ def get_analysis_space(analysis_space: dict) -> list:
elif isinstance(value, str):
eval_element = (
key,
np.fromstring(value,
dtype=float,
sep=" "))
np.fromstring(value, dtype=float, sep=" "))
elif isinstance(value, list):
eval_element = (key, np.array(value))
else:
Expand All @@ -40,13 +39,12 @@ def adapt_likelihood_config_for_blueice(
"""
Adapt likelihood config to be compatible with blueice.
Args:
likelihood_config (dict): likelihood config dict
template_folder_list (list): list of possible base folders.
Ordered by priority.
Returns:
dict: adapted likelihood config
:param likelihood_config: likelihood config dict
:type likelihood_config: dict
:param template_folder_list: list of possible base folders. Ordered by priority.
:type template_folder_list: list
:return: adapted likelihood config
:rtype: dict
"""

likelihood_config_copy = deepcopy(likelihood_config)
Expand Down Expand Up @@ -89,6 +87,11 @@ def formatted_to_asterisked(formatted):
Convert formatted string to asterisk
Sometimes a parameter(usually shape parameter) is not specified in formatted string,
this function replace the parameter with asterisk.
:param formatted: formatted string
:type formatted: str
:return: asterisked string
:rtype: str
"""
asterisked = formatted
for found in re.findall("\{(.*?)\}", formatted):
Expand All @@ -105,6 +108,11 @@ def get_file_path(fname, folder_list=None):
#. can get file from _get_abspath, return alea internal file path
#. can be found in local installed ntauxfiles, return ntauxfiles absolute path
#. can be downloaded from MongoDB, download and return cached path
:param fname: file name
:type fname: str
:param folder_list: list of possible base folders. Ordered by priority.
:type folder_list: list
"""
if folder_list is None:
folder_list = []
Expand Down

0 comments on commit d4e0f20

Please sign in to comment.