Skip to content

Refactor cost._evaluate methods to accept precomputed signals #436

Description

@BradyPlanden

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, with self.y & self.dy being the objects to operate on:

def _evaluate(self, inputs: Inputs):

This issue is to update these methods as follows:

  • Rename to cost.compute and cost.computeS1
  • Change the method args to be an object of signals that the cost is calculated on
  • Add object checks to the precomputed signal values

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.

for i in range(10):
    eval = problem.evaluate([val1, val2])
    for i in range(100):
        eval += np.random.normal(0, sigma, len(t_eval))
        cost.compute(eval)

Possible implementation

The MAP method may need a large refactor.

Additional context

Initial discussion on #435

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions