Skip to content

Commit

Permalink
Fix division by zero in IBEA
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Feb 21, 2017
1 parent b262a1c commit 6862eb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bluepyopt/deapext/tools/selIBEA.py
Expand Up @@ -72,21 +72,25 @@ def _calc_fitness_components(population, kappa):
box_ranges = (numpy.max(population_matrix, axis=0) -
numpy.min(population_matrix, axis=0))

# Replace all possible zeros to avoid division by zero
# Basically 0/0 is replaced by 0/1
box_ranges[box_ranges == 0] = 1.0

components_matrix = numpy.zeros((pop_len, pop_len))
for i in xrange(0, pop_len):
diff = population_matrix - population_matrix[i, :]
components_matrix[i, :] = numpy.max(
numpy.divide(
diff,
box_ranges),
numpy.divide(diff, box_ranges),
axis=1)

# Calculate max of absolute value of all elements in matrix
max_absolute_indicator = numpy.max(numpy.abs(components_matrix))

# Normalisation
components_matrix = numpy.exp((-1.0 / (kappa * max_absolute_indicator)) *
components_matrix.T)
if max_absolute_indicator != 0:
components_matrix = numpy.exp(
(-1.0 / (kappa * max_absolute_indicator)) * components_matrix.T)

return components_matrix


Expand Down
2 changes: 2 additions & 0 deletions bluepyopt/tests/test_l5pc.py
Expand Up @@ -170,6 +170,8 @@ def stdout_redirector(stream):
@attr('slow')
def test_exec():
"""L5PC Notebook: test execution"""
import numpy
numpy.seterr(all='raise')
old_cwd = os.getcwd()
output = StringIO()
try:
Expand Down

0 comments on commit 6862eb4

Please sign in to comment.