-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optimiser.name() to optimisers, updt. plotting across examples, c…
…hange plot_convergence() to plot mininum cost trace, merge develop
- Loading branch information
Showing
21 changed files
with
547 additions
and
144 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
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,54 @@ | ||
import pybop | ||
import numpy as np | ||
|
||
# Define model | ||
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) | ||
|
||
# Plot the timeseries output | ||
pybop.quick_plot(x, cost, title="Optimised Comparison") | ||
|
||
# Plot convergence | ||
pybop.plot_convergence(optim) | ||
|
||
# Plot the cost landscape | ||
pybop.plot_cost2d(cost, steps=15) | ||
|
||
# Plot the cost landscape with optimisation path | ||
pybop.plot_cost2d(cost, optim=optim, 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pybop | ||
import numpy as np | ||
|
||
# Define model | ||
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) | ||
|
||
# Plot the timeseries output | ||
pybop.quick_plot(x, cost, title="Optimised Comparison") | ||
|
||
# Plot convergence | ||
pybop.plot_convergence(optim) | ||
|
||
# Plot the cost landscape | ||
pybop.plot_cost2d(cost, steps=15) | ||
|
||
# Plot the cost landscape with optimisation path | ||
pybop.plot_cost2d(cost, optim=optim, 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pybop | ||
import numpy as np | ||
|
||
# Define model | ||
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) | ||
|
||
# Plot the timeseries output | ||
pybop.quick_plot(x, cost, title="Optimised Comparison") | ||
|
||
# Plot convergence | ||
pybop.plot_convergence(optim) | ||
|
||
# Plot the cost landscape | ||
pybop.plot_cost2d(cost, steps=15) | ||
|
||
# Plot the cost landscape with optimisation path | ||
pybop.plot_cost2d(cost, optim=optim, 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pybop | ||
import numpy as np | ||
|
||
# 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) | ||
|
||
# Plot the timeseries output | ||
pybop.quick_plot(x, cost, title="Optimised Comparison") | ||
|
||
# Plot convergence | ||
pybop.plot_convergence(optim) | ||
|
||
# Plot the cost landscape | ||
pybop.plot_cost2d(cost, steps=15) | ||
|
||
# Plot the cost landscape with optimisation path | ||
pybop.plot_cost2d(cost, optim=optim, 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
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.