GithubHelp home page GithubHelp logo

Comments (3)

NicolaCourtier avatar NicolaCourtier commented on August 10, 2024

I think this is a great direction to go in! 💯

Consider compute_for(y) to indicate that the computation is being applied to a given array and distinguish it from the synonym evaluate().

EDIT: After some more thought, I think using any synonym here (such as "compute" is confusing and I would instead vote for something like evaluate_on_prediction(y).

from pybop.

BradyPlanden avatar BradyPlanden commented on August 10, 2024

Thanks for the comment @NicolaCourtier!

On further thought, I think we can make better use of the __call__ method within the cost class to simplify these methods. Here's what I'm thinking:

  • The __call__ method is updated to implement the current evaluate and evaluateS1 functionality, with an optional arg added as calculate_grad with default as False. This aligns with PyBaMM's solver interface, which should simplify this change for users. I think this is a nice solution as it remains non-breaking for users, with added functionality for obtaining gradients. This results in evaluate and evaluateS1 being redundant and removed. For v24.9, these should be deprecated with full removal in 24.12.
  • _evaluate and _evaluateS1 are refactored into cost.compute with optional arg for returning gradients. This method computes the cost between two vectors without performing a problem.evaluate. The default would be for the ground truth and the user supplied vector, but an optional arg will be added to replace the ground truth in the computation.

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 S1 methods are removed and replaced with an optional arg in the non-gradient implementation. I think this is worth doing, as the current naming convention isn't clear to users, and would we would end up with less duplicate code. I'm be interested to hear others' thoughts on this!

from pybop.

NicolaCourtier avatar NicolaCourtier commented on August 10, 2024

This sounds good to me- the function names are not direct synonyms and the amount of duplicate code will be reduced!

from pybop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.