Skip to content

Commit

Permalink
converts parent selection weights via sofmax
Browse files Browse the repository at this point in the history
  • Loading branch information
lacava committed Jul 27, 2017
1 parent eb14dff commit 01b6f3c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions few/variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def variation(self,parents):
if hasattr(self.ml.named_steps['ml'],'coef_'):
# for l1 regularization, filter individuals with 0 coefficients
if self.weight_parents:
weights = abs(self.ml.named_steps['ml'].coef_)
weights = self.ml.named_steps['ml'].coef_
if len(weights.shape)>1: # handle multi-coefficient models
weights = [np.mean(abs(c)) for c in weights.transpose()]
weights = weights/sum(weights)
# softmax transformation of the weights
weights = np.exp(weights)/np.sum(np.exp(weights))
offspring = copy.deepcopy(
list(np.random.choice(self.valid(parents),
self.population_size, p=weights)))
Expand All @@ -41,7 +42,8 @@ def variation(self,parents):
# for tree methods, filter our individuals with 0 feature importance
if self.weight_parents:
weights = self.ml.named_steps['ml'].feature_importances_
weights = weights/sum(weights)
# softmax transformation of the weights
weights = np.exp(weights)/np.sum(np.exp(weights))
offspring = copy.deepcopy(list(
np.random.choice(self.valid(parents),
self.population_size, p=weights)))
Expand Down

0 comments on commit 01b6f3c

Please sign in to comment.