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

Fix RMSE gradient #355

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pybop/costs/fitting_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def _evaluateS1(self, x):

r = np.array([y[signal] - self._target[signal] for signal in self.signal])
e = np.sqrt(np.mean(r**2, axis=1))
de = np.mean((r * dy.T), axis=2) / (
np.sqrt(np.mean((r * dy.T) ** 2, axis=2)) + np.finfo(float).eps
)
de = np.mean((r * dy.T), axis=2) / (e + np.finfo(float).eps)

if self.n_outputs == 1:
return e.item(), de.flatten()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_standalone_problem(self):
rmse_grad_x = rmse_cost.evaluateS1([1, 2])

np.testing.assert_allclose(rmse_x, 3.05615, atol=1e-2)
np.testing.assert_allclose(rmse_grad_x[1], [-0.81758337, 0.0], atol=1e-2)
np.testing.assert_allclose(rmse_grad_x[1], [-0.54645, 0.0], atol=1e-2)

# Test the sensitivities
sums_cost = pybop.SumSquaredError(problem)
Expand Down
Loading