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

[Bug]: GaussianLogLikelihood returns an error in the case of multiple signals #257

Closed
NicolaCourtier opened this issue Mar 25, 2024 · 0 comments · Fixed by #338
Closed
Labels
bug Something isn't working

Comments

@NicolaCourtier
Copy link
Member

Python Version

3.10.12

Describe the bug

The evaluate and evaluateS1 functions need to be updated for GaussianLogLikelihood to allow with multiple signals. Note that GaussianLogLikelihoodKnownSigma runs without error and produces the expected output.

Steps to reproduce the behaviour

Replace lines 46-47 in the spm_MLE.py example:

problem = pybop.FittingProblem(model, parameters, dataset, signal=["Voltage [V]", "Time [s]"])
likelihood = pybop.GaussianLogLikelihoodKnownSigma(problem, sigma=[0.03, 0.03])

with:

problem = pybop.FittingProblem(model, parameters, dataset, signal=["Voltage [V]", "Time [s]"])
likelihood = pybop.GaussianLogLikelihood(problem)

Running this updated example produces the error message copied below.

Relevant log output

----------------------------------------
Unexpected termination.
Current score: (-inf, -inf)
Current position:
 6.14848282459801054e-01
 4.47667093256804038e-01
----------------------------------------
Traceback (most recent call last):
  File "/home/nicola/GitHub/PyBOP/pybop/costs/base_cost.py", line 88, in evaluate
    return -self._evaluate(x, grad)
  File "/home/nicola/GitHub/PyBOP/pybop/costs/_likelihoods.py", line 148, in _evaluate
    y = self.problem.evaluate(x[: -self.n_outputs])
  File "/home/nicola/GitHub/PyBOP/pybop/_problem.py", line 244, in evaluate
    if np.any(x != self.x) and self._model.matched_parameters:
ValueError: operands could not be broadcast together with shapes (0,) (2,) 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nicola/GitHub/PyBOP/examples/scripts/spm_MLE.py", line 54, in <module>
    x, final_cost = optim.run()
  File "/home/nicola/GitHub/PyBOP/pybop/_optimisation.py", line 158, in run
    x, final_cost = self._run_pints()
  File "/home/nicola/GitHub/PyBOP/pybop/_optimisation.py", line 260, in _run_pints
    fs = evaluator.evaluate(xs)
  File "/home/nicola/GitHub/pybop-env/lib/python3.10/site-packages/pints/_evaluation.py", line 119, in evaluate
    return self._evaluate(positions)
  File "/home/nicola/GitHub/pybop-env/lib/python3.10/site-packages/pints/_evaluation.py", line 481, in _evaluate
    scores[k] = self._function(x, *self._args)
  File "/home/nicola/GitHub/PyBOP/pybop/costs/base_cost.py", line 60, in __call__
    return self.evaluate(x, grad)
  File "/home/nicola/GitHub/PyBOP/pybop/costs/base_cost.py", line 94, in evaluate
    raise ValueError(f"Error in cost calculation: {e}")
ValueError: Error in cost calculation: operands could not be broadcast together with shapes (0,) (2,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant