-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Nelder-Mead optimiser from PINTS (#254)
* Add Nelder-Mead optimiser from PINTS * Create spm_NelderMead.py * Update CHANGELOG.md * Update pints_optimiser comments * Update NelderMead description Co-authored-by: Brady Planden <[email protected]> * Change model in NelderMead example Co-authored-by: Brady Planden <[email protected]>
- Loading branch information
1 parent
7b500e4
commit 0135d45
Showing
6 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import numpy as np | ||
|
||
import pybop | ||
|
||
# Parameter set and model definition | ||
parameter_set = pybop.ParameterSet.pybamm("Chen2020") | ||
model = pybop.lithium_ion.SPM(parameter_set=parameter_set) | ||
|
||
# Fitting parameters | ||
parameters = [ | ||
pybop.Parameter( | ||
"Negative electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.68, 0.05), | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
), | ||
] | ||
|
||
# Generate data | ||
init_soc = 0.5 | ||
sigma = 0.003 | ||
experiment = pybop.Experiment( | ||
[ | ||
( | ||
"Discharge at 0.5C for 3 minutes (1 second period)", | ||
"Charge at 0.5C for 3 minutes (1 second period)", | ||
), | ||
] | ||
* 2 | ||
) | ||
values = model.predict(init_soc=init_soc, experiment=experiment) | ||
|
||
|
||
def noise(sigma): | ||
return np.random.normal(0, sigma, len(values["Voltage [V]"].data)) | ||
|
||
|
||
# Form dataset | ||
dataset = pybop.Dataset( | ||
{ | ||
"Time [s]": values["Time [s]"].data, | ||
"Current function [A]": values["Current [A]"].data, | ||
"Voltage [V]": values["Voltage [V]"].data + noise(sigma), | ||
"Bulk open-circuit voltage [V]": values["Bulk open-circuit voltage [V]"].data | ||
+ noise(sigma), | ||
} | ||
) | ||
|
||
signal = ["Voltage [V]", "Bulk open-circuit voltage [V]"] | ||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.FittingProblem( | ||
model, parameters, dataset, signal=signal, init_soc=init_soc | ||
) | ||
cost = pybop.RootMeanSquaredError(problem) | ||
optim = pybop.Optimisation( | ||
cost, | ||
optimiser=pybop.NelderMead, | ||
verbose=True, | ||
allow_infeasible_solutions=True, | ||
sigma0=0.05, | ||
) | ||
optim.set_max_iterations(100) | ||
optim.set_max_unchanged_iterations(45) | ||
|
||
# Run optimisation | ||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Plot the timeseries output | ||
pybop.quick_plot(problem, parameter_values=x, title="Optimised Comparison") | ||
|
||
# Plot convergence | ||
pybop.plot_convergence(optim) | ||
|
||
# Plot the parameter traces | ||
pybop.plot_parameters(optim) | ||
|
||
# Plot the cost landscape with optimisation path | ||
bounds = np.array([[0.5, 0.8], [0.4, 0.7]]) | ||
pybop.plot2d(optim, bounds=bounds, steps=15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ | |
Adam, | ||
CMAES, | ||
IRPropMin, | ||
NelderMead, | ||
PSO, | ||
SNES, | ||
XNES, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters