Skip to content

Commit

Permalink
Merge pull request #68 from XENONnT/code_docstring_style
Browse files Browse the repository at this point in the history
Unify and clean code style and docstring
  • Loading branch information
dachengx authored Aug 1, 2023
2 parents 6e7efd4 + 2682d9f commit 58bf303
Show file tree
Hide file tree
Showing 21 changed files with 673 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: Python style
on:
pull_request:
# types: [opened]
types: [opened]
jobs:
qa:
name: Quality check
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ __pycache__
build
docs/build
docs/source/_build
docs/source/build
debug.py
docs/source/reference/*
docs/source/reference/release_notes.rst
48 changes: 39 additions & 9 deletions alea/examples/gaussian_model.py
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
Loading

0 comments on commit 58bf303

Please sign in to comment.