-
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 #12 from XENONnT/gaussian_model
Add simple gaussian model
- Loading branch information
Showing
3 changed files
with
119 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from alea.statistical_model import StatisticalModel | ||
import scipy.stats as stats | ||
import numpy as np | ||
|
||
|
||
class GaussianModel(StatisticalModel): | ||
def __init__(self, nominal_mu, nominal_sigma): | ||
""" | ||
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. | ||
""" | ||
self.nominal_values = {"mu": nominal_mu, | ||
"sigma": nominal_sigma} | ||
super().__init__(fixed_parameters={"sigma": nominal_sigma}, | ||
) | ||
|
||
def ll(self, mu=None, sigma=None): | ||
if mu is None: | ||
mu = self.nominal_values.get("mu", None) | ||
if sigma is None: | ||
sigma = self.nominal_values.get("sigma", None) | ||
|
||
hat_mu = self.get_data()[0]['hat_mu'][0] | ||
return stats.norm.logpdf(x=hat_mu, loc=mu, scale=sigma) | ||
|
||
def generate_data(self, mu=None, sigma=None): | ||
if mu is None: | ||
mu = self.nominal_values.get("mu", None) | ||
if sigma is None: | ||
sigma = self.nominal_values.get("sigma", None) | ||
|
||
hat_mu = stats.norm(loc=mu, scale=sigma).rvs() | ||
data = [np.array([(hat_mu,)], dtype=[('hat_mu', float)])] | ||
return data | ||
|
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