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

Transformations for varying scale parameters #92

Closed
BradyPlanden opened this issue Nov 13, 2023 · 1 comment · Fixed by #357
Closed

Transformations for varying scale parameters #92

BradyPlanden opened this issue Nov 13, 2023 · 1 comment · Fixed by #357
Assignees
Labels
bug Something isn't working

Comments

@BradyPlanden
Copy link
Member

Feature description

When optimising parameters of varying scale, we overshoot acceptable parameter ranges during fitting (for non-bounded methods). Transforming / normalising the parameter space on input to the optimiser should solve this issue. An example of this issue is:

import pybop
import numpy as np

parameter_set = pybop.ParameterSet("pybamm", "Chen2020")
model = pybop.lithium_ion.SPMe(parameter_set=parameter_set)

# Fitting parameters
parameters = [
    pybop.Parameter(
        "Positive electrode diffusivity [m2.s-1]",
        prior=pybop.Gaussian(3.43e-15, 1e-15),
        bounds=[1e-15, 5e-15],
    ),
]

sigma = 0.001
t_eval = np.arange(0, 900, 2)
values = model.predict(t_eval=t_eval)
corrupt_voltage = values["Terminal voltage [V]"].data + np.random.normal(
    0, sigma, len(t_eval)
)

dataset = [
    pybop.Dataset("Time [s]", t_eval),
    pybop.Dataset("Current function [A]", values["Current [A]"].data),
    pybop.Dataset("Terminal voltage [V]", corrupt_voltage),
]

# Generate problem, cost function, and optimisation class
problem = pybop.Problem(model, parameters, dataset)
cost = pybop.SumSquaredError(problem)
optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent)
optim.optimiser.set_learning_rate(0.025)

x, final_cost = optim.run()
print("Estimated parameters:", x)

Our implementation of Gradient Descent (#88) is unbounded and immediately select a candidate solution orders of magnitude higher than an acceptable range.

Motivation

No response

Possible implementation

No response

Additional context

No response

@BradyPlanden BradyPlanden added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Nov 13, 2023
@NicolaCourtier
Copy link
Member

This issue seems to have been resolved by PR #213.

In light of API changes, the example is now:

import pybop
import numpy as np

parameter_set = pybop.ParameterSet.pybamm("Chen2020")
model = pybop.lithium_ion.SPMe(parameter_set=parameter_set)

# Fitting parameters
parameters = [
    pybop.Parameter(
        "Positive electrode diffusivity [m2.s-1]",
        prior=pybop.Gaussian(3.43e-15, 1e-15),
        bounds=[1e-15, 5e-15],
    ),
]

sigma = 0.001
t_eval = np.arange(0, 900, 2)
values = model.predict(t_eval=t_eval)
corrupt_voltage = values["Terminal voltage [V]"].data + np.random.normal(
    0, sigma, len(t_eval)
)

dataset = pybop.Dataset(
    {
        "Time [s]": t_eval,
        "Current function [A]": values["Current [A]"].data,
        "Voltage [V]": corrupt_voltage,
    }
)

# Generate problem, cost function, and optimisation class
problem = pybop.FittingProblem(model, parameters, dataset)
cost = pybop.SumSquaredError(problem)
optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent)
# optim.optimiser.set_learning_rate(0.025)  # replaced by sigma

x, final_cost = optim.run()
print("Estimated parameters:", x)

@BradyPlanden BradyPlanden self-assigned this May 30, 2024
@BradyPlanden BradyPlanden linked a pull request Jun 12, 2024 that will close this issue
15 tasks
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
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants