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

Make likelihoods a type of cost #230

Merged
merged 7 commits into from
Mar 8, 2024

Conversation

NicolaCourtier
Copy link
Member

Description

Suggestion to make the new likelihood classes a type of cost.

Issue reference

Regarding #210

Type of change

  • Refactoring: Non-functional changes that improve the codebase.

Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 84.37500% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 94.22%. Comparing base (8d58731) to head (a9683f7).
Report is 11 commits behind head on 210-add-likelihood-classes.

Files Patch % Lines
pybop/costs/base_cost.py 84.61% 2 Missing ⚠️
pybop/costs/fitting_costs.py 0.00% 2 Missing ⚠️
pybop/_optimisation.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           210-add-likelihood-classes     #230      +/-   ##
==============================================================
- Coverage                       94.37%   94.22%   -0.15%     
==============================================================
  Files                              33       33              
  Lines                            1760     1750      -10     
==============================================================
- Hits                             1661     1649      -12     
- Misses                             99      101       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@BradyPlanden BradyPlanden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the additions @NicolaCourtier! I've added a few comments, I'm happy to update these in #210 though :) Let me know if any thoughts on them!

the log-likelihood
"""
raise NotImplementedError
self.log_likelihood = problem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as it was only required for the ProbabilityCost() wrapper.

Suggested change
self.log_likelihood = problem

@@ -75,12 +75,6 @@ def test_base_likelihood_init(self, problem):
assert likelihood._n_parameters == 1
assert np.array_equal(likelihood._target, problem._target)

@pytest.mark.unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want this test? Looking at the above class, BaseLikelihood still returns NotImplemented from call(). It would be good to keep a test on that.

optimiser=None,
sigma0=None,
verbose=False,
physical_viability=True,
allow_infeasible_solutions=True,
):
self.cost = cost
self.x0 = x0
self.x0 = cost.x0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above. This keeps it open :)

Suggested change
self.x0 = cost.x0
self.x0 = x0 or cost.x0

@@ -40,27 +40,24 @@ class Optimisation:
def __init__(
self,
cost,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want users to overwrite the initial conditions, right? This modification should keep that open.

Suggested change
cost,
cost,
x0=None,

@NicolaCourtier NicolaCourtier merged commit 0b53048 into 210-add-likelihood-classes Mar 8, 2024
29 of 31 checks passed
@NicolaCourtier NicolaCourtier deleted the 210b-add-likelihood branch March 8, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants