Skip to content

Commit

Permalink
Add catch-all for evaluation function
Browse files Browse the repository at this point in the history
Do not allow one pipeline that crashes to cause TPOT to crash. Instead,
assign the crashing pipeline a poor fitness.

Reference: #84 and #85
  • Loading branch information
rhiever committed Feb 20, 2016
1 parent 0bb34c6 commit 72a3c66
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions tpot/tpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,27 +992,32 @@ def _evaluate_individual(self, individual, training_testing_data):
try:
# Transform the tree expression in a callable function
func = self.toolbox.compile(expr=individual)
except MemoryError:
# Throw out GP expressions that are too large to be compiled in Python
return 5000., 0.

# Count the number of pipeline operators as a measure of pipeline complexity
operator_count = 0
for i in range(len(individual)):
node = individual[i]
if type(node) is deap.gp.Terminal:
continue
if type(node) is deap.gp.Primitive and node.name in ['add', 'sub', 'mul', '_div', '_combine_dfs']:
continue
# Count the number of pipeline operators as a measure of pipeline complexity
operator_count = 0
for i in range(len(individual)):
node = individual[i]
if type(node) is deap.gp.Terminal:
continue
if type(node) is deap.gp.Primitive and node.name in ['add', 'sub', 'mul', '_div', '_combine_dfs']:
continue

operator_count += 1
operator_count += 1

result = func(training_testing_data)
result = result[result['group'] == 'testing']
res = self.scoring_function(result)
result = func(training_testing_data)
result = result[result['group'] == 'testing']
resulting_score = self.scoring_function(result)

except MemoryError:
# Throw out GP expressions that are too large to be compiled in Python
return 5000., 0.
except:
# Catch-all: Do not allow one pipeline that crashes to cause TPOT to crash
# Instead, assign the crashing pipeline a poor fitness
return 5000., 0.

if isinstance(res, float) or isinstance(res, np.float64) or isinstance(res, np.float32):
return max(1, operator_count), res
if isinstance(resulting_score, float) or isinstance(resulting_score, np.float64) or isinstance(resulting_score, np.float32):
return max(1, operator_count), resulting_score
else:
raise ValueError('Scoring function does not return a float')

Expand Down

0 comments on commit 72a3c66

Please sign in to comment.