Skip to content

Commit

Permalink
Merge pull request #338 from pybop-team/gauss-log-like-fixes
Browse files Browse the repository at this point in the history
Updates to likelihoods, bug fix `GaussianLogLikelihood` class
  • Loading branch information
BradyPlanden authored Jul 5, 2024
2 parents 4c4a31e + ee73c2b commit 7a85dd0
Show file tree
Hide file tree
Showing 25 changed files with 556 additions and 295 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

## Bug Fixes

- [#338](https://github.com/pybop-team/PyBOP/pull/338) - Fixes GaussianLogLikelihood class, adds integration tests, updates non-bounded parameter implementation by applying bounds from priors and `boundary_multiplier` argument. Bugfixes to CMAES construction.
- [#339](https://github.com/pybop-team/PyBOP/issues/339) - Updates the calculation of the cyclable lithium capacity in the spme_max_energy example.
- [#387](https://github.com/pybop-team/PyBOP/issues/387) - Adds keys to ParameterSet and updates ECM OCV check.
- [#380](https://github.com/pybop-team/PyBOP/pull/380) - Restore self._boundaries construction for `pybop.PSO`
Expand Down
24 changes: 14 additions & 10 deletions examples/scripts/spm_MAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import pybop

# Define model
# Construct and update initial parameter values
parameter_set = pybop.ParameterSet.pybamm("Chen2020")
parameter_set.update(
{
"Negative electrode active material volume fraction": 0.63,
"Positive electrode active material volume fraction": 0.51,
}
)

# Define model
model = pybop.lithium_ion.SPM(parameter_set=parameter_set)

# Fitting parameters
Expand All @@ -12,21 +20,16 @@
"Negative electrode active material volume fraction",
prior=pybop.Gaussian(0.6, 0.05),
bounds=[0.5, 0.8],
true_value=parameter_set["Negative electrode active material volume fraction"],
),
pybop.Parameter(
"Positive electrode active material volume fraction",
prior=pybop.Gaussian(0.48, 0.05),
bounds=[0.4, 0.7],
true_value=parameter_set["Positive electrode active material volume fraction"],
),
)

# Set initial parameter values
parameter_set.update(
{
"Negative electrode active material volume fraction": 0.63,
"Positive electrode active material volume fraction": 0.51,
}
)
# Generate data
sigma = 0.005
t_eval = np.arange(0, 900, 3)
Expand All @@ -44,8 +47,8 @@

# Generate problem, cost function, and optimisation class
problem = pybop.FittingProblem(model, parameters, dataset)
cost = pybop.MAP(problem, pybop.GaussianLogLikelihoodKnownSigma)
optim = pybop.CMAES(
cost = pybop.MAP(problem, pybop.GaussianLogLikelihoodKnownSigma, sigma0=sigma)
optim = pybop.AdamW(
cost,
max_unchanged_iterations=20,
min_iterations=20,
Expand All @@ -54,6 +57,7 @@

# Run the optimisation
x, final_cost = optim.run()
print("True parameters:", parameters.true_value())
print("Estimated parameters:", x)

# Plot the timeseries output
Expand Down
7 changes: 3 additions & 4 deletions examples/scripts/spm_MLE.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
pybop.Parameter(
"Positive electrode active material volume fraction",
prior=pybop.Gaussian(0.48, 0.05),
bounds=[0.4, 0.7],
),
)

Expand Down Expand Up @@ -44,8 +43,8 @@

# Generate problem, cost function, and optimisation class
problem = pybop.FittingProblem(model, parameters, dataset)
likelihood = pybop.GaussianLogLikelihoodKnownSigma(problem, sigma=[0.03, 0.03])
optim = pybop.CMAES(
likelihood = pybop.GaussianLogLikelihoodKnownSigma(problem, sigma0=sigma)
optim = pybop.IRPropMin(
likelihood,
max_unchanged_iterations=20,
min_iterations=20,
Expand All @@ -57,7 +56,7 @@
print("Estimated parameters:", x)

# Plot the timeseries output
pybop.quick_plot(problem, problem_inputs=x[0:2], title="Optimised Comparison")
pybop.quick_plot(problem, problem_inputs=x, title="Optimised Comparison")

# Plot convergence
pybop.plot_convergence(optim)
Expand Down
2 changes: 1 addition & 1 deletion pybop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
RootMeanSquaredError,
SumSquaredError,
ObserverCost,
MAP,
)
from .costs.design_costs import (
DesignCost,
Expand All @@ -97,6 +96,7 @@
BaseLikelihood,
GaussianLogLikelihood,
GaussianLogLikelihoodKnownSigma,
MAP,
)

#
Expand Down
Loading

0 comments on commit 7a85dd0

Please sign in to comment.