Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into simplify_source
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Aug 1, 2023
2 parents 459c93b + 58bf303 commit e1cf100
Show file tree
Hide file tree
Showing 19 changed files with 658 additions and 284 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 e1cf100

Please sign in to comment.