Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds cuckoo optimiser #319

Merged
merged 15 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: cuckoo boundaries==None clipping, add missing cuckoo to unit opt…
…imisation tests, updt. integration tests
  • Loading branch information
BradyPlanden committed Jul 5, 2024
commit aa94180c426e0a89a1761ac2e9f7226837e51ff2
2 changes: 1 addition & 1 deletion pybop/costs/_likelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class MAP(BaseLikelihood):

"""

def __init__(self, problem, likelihood, sigma0=None, gradient_step=1e-2):
def __init__(self, problem, likelihood, sigma0=None, gradient_step=1e-3):
super(MAP, self).__init__(problem)
self.sigma0 = sigma0
self.gradient_step = gradient_step
Expand Down
4 changes: 3 additions & 1 deletion pybop/optimisers/_cuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def __init__(self, x0, sigma0=0.01, boundaries=None, pa=0.25):
size=(self._n, self._dim),
)
else:
self._nests = np.random.normal(self._x0, self._sigma0)
self._nests = np.random.normal(
self._x0, self._sigma0, size=(self._n, self._dim)
)

self._fitness = np.full(self._n, np.inf)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_spm_parameterisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_spm_optimisers(self, optimiser, spm_costs):
)

# Set sigma0 and create optimiser
sigma0 = 0.01 if isinstance(spm_costs, pybop.GaussianLogLikelihood) else 0.05
sigma0 = 0.006 if isinstance(spm_costs, pybop.MAP) else None
optim = optimiser(sigma0=sigma0, **common_args)

# Set max unchanged iterations for BasePintsOptimisers
Expand Down
14 changes: 4 additions & 10 deletions tests/unit/test_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_no_optimisation_parameters(self, model, dataset):
pybop.PSO,
pybop.IRPropMin,
pybop.NelderMead,
pybop.CuckooSearch,
],
)
@pytest.mark.unit
Expand Down Expand Up @@ -265,17 +266,10 @@ def test_optimiser_kwargs(self, cost, optimiser):
assert optim.x0 != x0

@pytest.mark.unit
def test_cuckoo_no_bounds(self, dataset, model):
parameter = pybop.Parameter(
"Negative electrode active material volume fraction",
prior=pybop.Gaussian(0.6, 0.2),
)

cost_no_bounds = pybop.SumSquaredError(
pybop.FittingProblem(model, parameter, dataset)
)
optim = pybop.CuckooSearch(cost=cost_no_bounds, max_iterations=1)
def test_cuckoo_no_bounds(self, dataset, cost, model):
optim = pybop.CuckooSearch(cost=cost, bounds=None, max_iterations=1)
optim.run()
assert optim.pints_optimiser._boundaries is None

@pytest.mark.unit
def test_scipy_minimize_with_jac(self, cost):
Expand Down
Loading