Skip to content

Make likelihoods a type of cost#230

Merged
NicolaCourtier merged 7 commits into
210-add-likelihood-classesfrom
210b-add-likelihood
Mar 8, 2024
Merged

Make likelihoods a type of cost#230
NicolaCourtier merged 7 commits into
210-add-likelihood-classesfrom
210b-add-likelihood

Conversation

@NicolaCourtier

Copy link
Copy Markdown
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.

@codecov

codecov Bot commented Mar 8, 2024

Copy link
Copy Markdown

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.

@BradyPlanden BradyPlanden left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

assert likelihood._n_parameters == 1
assert np.array_equal(likelihood._target, problem._target)

@pytest.mark.unit

Copy link
Copy Markdown
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.

Comment thread pybop/_optimisation.py
):
self.cost = cost
self.x0 = x0
self.x0 = cost.x0

Copy link
Copy Markdown
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

Comment thread pybop/_optimisation.py
@@ -40,27 +40,24 @@ class Optimisation:
def __init__(
self,
cost,

Copy link
Copy Markdown
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
@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