-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from XENONnT/code_docstring_style
Unify and clean code style and docstring
- Loading branch information
Showing
21 changed files
with
673 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
name: Python style | ||
on: | ||
pull_request: | ||
# types: [opened] | ||
types: [opened] | ||
jobs: | ||
qa: | ||
name: Quality check | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,62 @@ | ||
from typing import Optional | ||
from typing import Dict, List, Optional | ||
|
||
from scipy import stats | ||
import numpy as np | ||
from scipy import stats | ||
|
||
from alea.model import StatisticalModel | ||
|
||
|
||
class GaussianModel(StatisticalModel): | ||
""" | ||
A model of a gaussian measurement, where the model has parameters mu and sigma. | ||
For illustration, we show how required nominal parameters can be added | ||
to the init sigma is fixed in this example. | ||
Args: | ||
parameter_definition (dict or list, optional (default=None)): | ||
definition of the parameters of the model | ||
Caution: | ||
You must define the nominal values of the parameters (mu, sigma) | ||
in the parameters definition. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
parameter_definition: Optional[dict or list] = None, | ||
parameter_definition: Optional[Dict or List] = None, | ||
**kwargs, | ||
): | ||
""" | ||
Initialise a model of a gaussian measurement (hatmu), | ||
where the model has parameters mu and sigma | ||
For illustration, we show how required nominal parameters can be added to the init | ||
sigma is fixed in this example. | ||
""" | ||
"""Initialise a gaussian model.""" | ||
if parameter_definition is None: | ||
parameter_definition = ["mu", "sigma"] | ||
super().__init__(parameter_definition=parameter_definition, **kwargs) | ||
|
||
def _ll(self, mu=None, sigma=None): | ||
""" | ||
Log-likelihood of the model. | ||
Args: | ||
mu (float, optional (default=None)): mean of the gaussian, | ||
if None, the nominal value is used | ||
sigma (float, optional (default=None)): standard deviation of the gaussian, | ||
if None, the nominal value is used | ||
""" | ||
hat_mu = self.data[0]['hat_mu'][0] | ||
return stats.norm.logpdf(x=hat_mu, loc=mu, scale=sigma) | ||
|
||
def _generate_data(self, mu=None, sigma=None): | ||
""" | ||
Generate data from the model. | ||
Args: | ||
mu (float, optional (default=None)): mean of the gaussian, | ||
if None, the nominal value is used | ||
sigma (float, optional (default=None)): standard deviation of the gaussian, | ||
if None, the nominal value is used | ||
Returns: | ||
list: data generated from the model | ||
""" | ||
hat_mu = stats.norm(loc=mu, scale=sigma).rvs() | ||
data = [np.array([(hat_mu,)], dtype=[('hat_mu', float)])] | ||
return data |
Oops, something went wrong.