Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple gaussian model #12

Merged
merged 3 commits into from
Jun 19, 2023
Merged

Add simple gaussian model #12

merged 3 commits into from
Jun 19, 2023

Conversation

hammannr
Copy link
Collaborator

This adds the simplest model, which can serve as a very basic example and for unittests. This closes #5.

You can run the following code to check the functionality:

from alea.examples.gaussian_model import GaussianModel
import matplotlib.pyplot as plt
import numpy as np

# Initialize model
model = GaussianModel(mu=0, sigma=1)

# Generate and set toy
data = model.generate_data()
model.set_data(data)
print(model.get_data(), model.get_data().dtype)

# Fit the data
best_fit, ll_val = model.fit(verbose=True)

# Make a plot of the ll scan
x = np.linspace(-2, 2, 1000)
y = - model.ll(x, 1)
y -=  min(y)
plt.plot(x, y)
mle = best_fit["mu"]
plt.axvline(mle, label=f"MLE={mle:.2f}", color="red")
plt.axvline(model.get_data()["hat_mu"][0],
            label=f"hat_mu={model.get_data()['hat_mu'][0]:.2f}",
            ls=":",
            color="k")
plt.axhline(.5, c="k")
plt.ylim(0)
plt.legend()
plt.xlabel("mu")
plt.ylabel("Log Likelihood Ratio")

@hammannr hammannr added enhancement New feature or request inference Statistics code labels Jun 16, 2023
@hammannr hammannr requested review from kdund and dachengx June 16, 2023 14:50
@kdund kdund added the testing Works on testing code label Jun 16, 2023
change some return errors to raise errors (mea culpa)
made the dataset be an array of datasets to have the same format as the final nT likelihood (for storing and loading etc)
alea/examples/gaussian_model.py Outdated Show resolved Hide resolved
alea/examples/gaussian_model.py Outdated Show resolved Hide resolved
alea/statistical_model.py Show resolved Hide resolved
alea/statistical_model.py Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@hammannr
Copy link
Collaborator Author

@kdund I just fixed some import issues but apart from that I'd now leave it at that so we can continue working with this. We already discussed a few changes in the structure last Friday but I think they come more natural once we have the Parameter class.

@kdund
Copy link
Collaborator

kdund commented Jun 19, 2023

sounds good-- should we start making a list of all properties a parameter might have?

@hammannr
Copy link
Collaborator Author

Yes I'm now opening an issue for the Parameter and ParameterList class, maybe we can then discuss it there. But I think we can merge this PR, right?

@kdund
Copy link
Collaborator

kdund commented Jun 19, 2023

yes agreed

@hammannr hammannr merged commit a5f8270 into master Jun 19, 2023
@hammannr hammannr deleted the gaussian_model branch June 19, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request inference Statistics code testing Works on testing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minimal statistical likelihood implementation
3 participants