-
Notifications
You must be signed in to change notification settings - Fork 24
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
Refactor cost._evaluate
methods to accept precomputed signals
#436
Comments
I think this is a great direction to go in! 💯 Consider EDIT: After some more thought, I think using any synonym here (such as "compute" is confusing and I would instead vote for something like |
Thanks for the comment @NicolaCourtier! On further thought, I think we can make better use of the
To summarise, the API looks like this: phi = cost([0.5,0.5]) # stays the same
phi, grad = cost([0.5, 0.5], calculate_grad=True) # returns cost and gradient
phi = cost.compute(np.ones(100)*4.0) # compute the cost against the ground truth and the user supplied vector
phi, grad = cost.compute(np.ones(100)*4.0, calculate_grad=True) # compute the cost and gradient against the ground truth and the user supplied vector This is a large change to the internal cost API, as the |
This sounds good to me- the function names are not direct synonyms and the amount of duplicate code will be reduced! |
Feature description
At the moment, the private cost evaluate methods (cost._evaluate/evaluateS1) complete their computation via side-effects i.e.
inputs
is passed, but not used, withself.y
&self.dy
being the objects to operate on:PyBOP/pybop/costs/fitting_costs.py
Line 109 in 8b09214
This issue is to update these methods as follows:
cost.compute
andcost.computeS1
Motivation
Opens up an additional API for users to compute a cost directly without triggering and
problem.evaluate
creating an advanced workflow that can be used for custom cost methods. An example is shown below, although the logic is meaningless.Possible implementation
The MAP method may need a large refactor.
Additional context
Initial discussion on #435
The text was updated successfully, but these errors were encountered: