-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathBPX_spm.py
59 lines (48 loc) · 1.59 KB
/
BPX_spm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
import pybop
# Define model
parameter_set = pybop.ParameterSet(json_path="examples/parameters/example_BPX.json")
model = pybop.lithium_ion.SPM(parameter_set=parameter_set)
# Fitting parameters
parameters = pybop.Parameters(
pybop.Parameter(
"Negative particle radius [m]",
prior=pybop.Gaussian(6e-06, 0.1e-6),
bounds=[1e-6, 9e-6],
true_value=parameter_set["Negative particle radius [m]"],
),
pybop.Parameter(
"Positive particle radius [m]",
prior=pybop.Gaussian(4.5e-07, 0.1e-6),
bounds=[1e-7, 9e-7],
true_value=parameter_set["Positive particle radius [m]"],
),
)
# Generate data
sigma = 0.001
t_eval = np.arange(0, 900, 5)
values = model.predict(t_eval=t_eval)
corrupt_values = values["Voltage [V]"].data + np.random.normal(0, sigma, len(t_eval))
# Form dataset
dataset = pybop.Dataset(
{
"Time [s]": t_eval,
"Current function [A]": values["Current [A]"].data,
"Voltage [V]": corrupt_values,
}
)
# Generate problem, cost function, and optimisation class
problem = pybop.FittingProblem(model, parameters, dataset)
cost = pybop.SumSquaredError(problem)
optim = pybop.CMAES(cost, max_iterations=40)
# Run the optimisation
results = optim.run()
print("True parameters:", parameters.true_value())
# Plot the timeseries output
pybop.plot.quick(problem, problem_inputs=results.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
pybop.plot.surface(optim)