Skip to content

Commit

Permalink
add jitter to krillsingularities
Browse files Browse the repository at this point in the history
  • Loading branch information
MDCHAMP committed Feb 24, 2022
1 parent 05ddcfd commit 9afcf9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/freelunch/optimisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def local_motion(self,herd,gen):
winner, loser = self.winners_and_losers(herd)
spread = loser[0] - winner[0]
if spread == 0:
warnings.warn(util.KrillSingularityWarning) #TODO add jitter?
warnings.warn(util.KrillSingularityWarning)
spread = 1e-8
# Alpha stores local [0] and target [1] for each krill
alpha = [np.zeros_like(herd[1]), np.zeros_like(herd[1])]
# Alpha local, the effect of the neighbours
Expand All @@ -429,6 +430,8 @@ def local_motion(self,herd,gen):
def foraging(self,herd,gen,pop):
winner, loser = self.winners_and_losers(herd)
spread = loser[0] - winner[0]
if spread == 0:
spread = 1e-8
# Tasty food at the centre of mass but how good is it
#Xfood = (np.sum(herd[1]/herd[0][:,None], axis=0) / np.sum(1/herd[0]))[:,None].T
Xfood = np.average(herd[1],weights=1/herd[0],axis=0)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_optimisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import numpy as np
import json
np.random.seed(100)
np.random.seed(200)


optimiser_classes = [SA, DE, PSO, QPSO, SADE, KrillHerd]
Expand Down Expand Up @@ -62,6 +62,7 @@ def test_multiproc_optimisers(opt):
@pytest.mark.parametrize('n', [1, 3])
@pytest.mark.parametrize('d', [1, 3, 5])
def test_run(opt, n, d):
np.random.seed(200)
o = exponential(d)
hypers = set_testing_hypers(opt)
out = opt(obj=o, bounds=o.bounds, hypers=hypers)(n_runs=n, full_output=True)
Expand Down

0 comments on commit 9afcf9a

Please sign in to comment.