Skip to content

Commit

Permalink
e-lexicase will ignore cases where all models got np.inf as error
Browse files Browse the repository at this point in the history
  • Loading branch information
gAldeia committed Dec 26, 2023
1 parent e7de8a5 commit b1094c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/brush/deap_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def e_lexicase(individuals, k):

while len(cases) > 0 and len(candidates) > 1:
errors_on_case = np.array([x.errors[cases[0]] for x in candidates])

MAD = np.median(np.abs(errors_on_case - np.median(errors_on_case)))

best_on_case = np.min(errors_on_case)

# Skip if this case is np.inf for all individuals
if not np.isfinite(best_on_case+MAD):
continue

candidates = [x for x in candidates
if x.errors[cases[0]] <= best_on_case + MAD]

Expand Down
9 changes: 6 additions & 3 deletions src/brush/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,18 @@ def _fitness_validation(self, ind, data: _brush.Dataset):
"complexity": ind.prg.complexity()
}

# Setting individual errors for lexicase
ind.errors = np.power( data.y - ind.prg.predict(data), 2 )

return [ ind_objectives[obj] for obj in self.objectives ]


def _fitness_function(self, ind, data: _brush.Dataset):
# fit the expression, then evaluate.

ind.prg.fit(data)

# Setting individual errors for lexicase
ind.errors = np.nan_to_num(
np.abs( data.y - ind.prg.predict(data) ), nan=np.inf)

return self._fitness_validation(ind, data)


Expand Down

0 comments on commit b1094c2

Please sign in to comment.