-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from pybop-team/116-add-pints-optimisers
Adds Pints' optimisers
- Loading branch information
Showing
15 changed files
with
507 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# [Unreleased](https://github.com/pybop-team/PyBOP) | ||
|
||
- [#116](https://github.com/pybop-team/PyBOP/issues/116) - Adds PSO, SNES, XNES, ADAM, and IPropMin optimisers to PintsOptimisers() class | ||
|
||
# [v23.11](https://github.com/pybop-team/PyBOP/releases/tag/v23.11) | ||
- Initial release | ||
- Adds Pints, NLOpt, and SciPy optimisers | ||
- Adds SumofSquareError and RootMeanSquareError cost functions | ||
- Adds Parameter and dataset classes | ||
- Initial release | ||
- Adds Pints, NLOpt, and SciPy optimisers | ||
- Adds SumofSquareError and RootMeanSquareError cost functions | ||
- Adds Parameter and dataset classes |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pybop | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
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.7, 0.05), | ||
bounds=[0.6, 0.9], | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
bounds=[0.5, 0.8], | ||
), | ||
] | ||
|
||
sigma = 0.001 | ||
t_eval = np.arange(0, 900, 2) | ||
values = model.predict(t_eval=t_eval) | ||
CorruptValues = 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]", CorruptValues), | ||
] | ||
|
||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.Problem(model, parameters, dataset) | ||
cost = pybop.SumSquaredError(problem) | ||
optim = pybop.Optimisation(cost, optimiser=pybop.IRPropMin) | ||
optim.set_max_iterations(100) | ||
|
||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Show the generated data | ||
simulated_values = problem.evaluate(x) | ||
|
||
plt.figure(dpi=100) | ||
plt.xlabel("Time", fontsize=12) | ||
plt.ylabel("Values", fontsize=12) | ||
plt.plot(t_eval, CorruptValues, label="Measured") | ||
plt.fill_between(t_eval, simulated_values - sigma, simulated_values + sigma, alpha=0.2) | ||
plt.plot(t_eval, simulated_values, label="Simulated") | ||
plt.legend(bbox_to_anchor=(0.6, 1), loc="upper left", fontsize=12) | ||
plt.tick_params(axis="both", labelsize=12) | ||
plt.show() |
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,55 @@ | ||
import pybop | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
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.7, 0.05), | ||
bounds=[0.6, 0.9], | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
bounds=[0.5, 0.8], | ||
), | ||
] | ||
|
||
sigma = 0.001 | ||
t_eval = np.arange(0, 900, 2) | ||
values = model.predict(t_eval=t_eval) | ||
CorruptValues = 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]", CorruptValues), | ||
] | ||
|
||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.Problem(model, parameters, dataset) | ||
cost = pybop.SumSquaredError(problem) | ||
optim = pybop.Optimisation(cost, optimiser=pybop.SNES) | ||
optim.set_max_iterations(100) | ||
|
||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Show the generated data | ||
simulated_values = problem.evaluate(x) | ||
|
||
plt.figure(dpi=100) | ||
plt.xlabel("Time", fontsize=12) | ||
plt.ylabel("Values", fontsize=12) | ||
plt.plot(t_eval, CorruptValues, label="Measured") | ||
plt.fill_between(t_eval, simulated_values - sigma, simulated_values + sigma, alpha=0.2) | ||
plt.plot(t_eval, simulated_values, label="Simulated") | ||
plt.legend(bbox_to_anchor=(0.6, 1), loc="upper left", fontsize=12) | ||
plt.tick_params(axis="both", labelsize=12) | ||
plt.show() |
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,55 @@ | ||
import pybop | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
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.7, 0.05), | ||
bounds=[0.6, 0.9], | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
bounds=[0.5, 0.8], | ||
), | ||
] | ||
|
||
sigma = 0.001 | ||
t_eval = np.arange(0, 900, 2) | ||
values = model.predict(t_eval=t_eval) | ||
CorruptValues = 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]", CorruptValues), | ||
] | ||
|
||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.Problem(model, parameters, dataset) | ||
cost = pybop.SumSquaredError(problem) | ||
optim = pybop.Optimisation(cost, optimiser=pybop.XNES) | ||
optim.set_max_iterations(100) | ||
|
||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Show the generated data | ||
simulated_values = problem.evaluate(x) | ||
|
||
plt.figure(dpi=100) | ||
plt.xlabel("Time", fontsize=12) | ||
plt.ylabel("Values", fontsize=12) | ||
plt.plot(t_eval, CorruptValues, label="Measured") | ||
plt.fill_between(t_eval, simulated_values - sigma, simulated_values + sigma, alpha=0.2) | ||
plt.plot(t_eval, simulated_values, label="Simulated") | ||
plt.legend(bbox_to_anchor=(0.6, 1), loc="upper left", fontsize=12) | ||
plt.tick_params(axis="both", labelsize=12) | ||
plt.show() |
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,59 @@ | ||
import pybop | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
# Parameter set and model definition | ||
parameter_set = pybop.ParameterSet("pybamm", "Chen2020") | ||
model = pybop.lithium_ion.SPMe(parameter_set=parameter_set) | ||
|
||
# Fitting parameters | ||
parameters = [ | ||
pybop.Parameter( | ||
"Negative electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.7, 0.05), | ||
bounds=[0.6, 0.9], | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
bounds=[0.5, 0.8], | ||
), | ||
] | ||
|
||
# Generate data | ||
sigma = 0.001 | ||
t_eval = np.arange(0, 900, 2) | ||
values = model.predict(t_eval=t_eval) | ||
corrupt_values = values["Terminal voltage [V]"].data + np.random.normal( | ||
0, sigma, len(t_eval) | ||
) | ||
|
||
# Dataset definition | ||
dataset = [ | ||
pybop.Dataset("Time [s]", t_eval), | ||
pybop.Dataset("Current function [A]", values["Current [A]"].data), | ||
pybop.Dataset("Terminal voltage [V]", corrupt_values), | ||
] | ||
|
||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.Problem(model, parameters, dataset) | ||
cost = pybop.SumSquaredError(problem) | ||
optim = pybop.Optimisation(cost, optimiser=pybop.Adam) | ||
optim.set_max_iterations(100) | ||
|
||
# Run optimisation | ||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Show the generated data | ||
simulated_values = problem.evaluate(x) | ||
|
||
plt.figure(dpi=100) | ||
plt.xlabel("Time", fontsize=12) | ||
plt.ylabel("Values", fontsize=12) | ||
plt.plot(t_eval, corrupt_values, label="Measured") | ||
plt.fill_between(t_eval, simulated_values - sigma, simulated_values + sigma, alpha=0.2) | ||
plt.plot(t_eval, simulated_values, label="Simulated") | ||
plt.legend(bbox_to_anchor=(0.6, 1), loc="upper left", fontsize=12) | ||
plt.tick_params(axis="both", labelsize=12) | ||
plt.show() |
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,55 @@ | ||
import pybop | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
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.7, 0.05), | ||
bounds=[0.6, 0.9], | ||
), | ||
pybop.Parameter( | ||
"Positive electrode active material volume fraction", | ||
prior=pybop.Gaussian(0.58, 0.05), | ||
bounds=[0.5, 0.8], | ||
), | ||
] | ||
|
||
sigma = 0.001 | ||
t_eval = np.arange(0, 900, 2) | ||
values = model.predict(t_eval=t_eval) | ||
CorruptValues = 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]", CorruptValues), | ||
] | ||
|
||
# Generate problem, cost function, and optimisation class | ||
problem = pybop.Problem(model, parameters, dataset) | ||
cost = pybop.SumSquaredError(problem) | ||
optim = pybop.Optimisation(cost, optimiser=pybop.PSO) | ||
optim.set_max_iterations(100) | ||
|
||
x, final_cost = optim.run() | ||
print("Estimated parameters:", x) | ||
|
||
# Show the generated data | ||
simulated_values = problem.evaluate(x) | ||
|
||
plt.figure(dpi=100) | ||
plt.xlabel("Time", fontsize=12) | ||
plt.ylabel("Values", fontsize=12) | ||
plt.plot(t_eval, CorruptValues, label="Measured") | ||
plt.fill_between(t_eval, simulated_values - sigma, simulated_values + sigma, alpha=0.2) | ||
plt.plot(t_eval, simulated_values, label="Simulated") | ||
plt.legend(bbox_to_anchor=(0.6, 1), loc="upper left", fontsize=12) | ||
plt.tick_params(axis="both", labelsize=12) | ||
plt.show() |
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
Oops, something went wrong.