Skip to content

Commit

Permalink
Merge pull request #27 from RenZhen95/master
Browse files Browse the repository at this point in the history
Method to correct for self.best_score
  • Loading branch information
jaswinder9051998 authored Feb 9, 2023
2 parents f2b5536 + 1c6ee7d commit 7c502b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions zoofs/baseoptimizationalgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def fit(self):
def sigmoid(self, x):
return 1 / (1 + np.exp(-x))

def _get_bestScore(self):
if self.minimize:
return self.best_score
else:
return -(self.best_score)

def _evaluate_fitness(
self, model, x_train, y_train, x_valid, y_valid, particle_swarm_flag=0, dragon_fly_flag=0
):
Expand Down
12 changes: 9 additions & 3 deletions zoofs/geneticoptimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def __init__(
self.elitism = elitism
self.mutation_rate = mutation_rate

def _get_bestScore(self):
if self.minimize:
return -(self.best_score)
else:
return self.best_score

def _evaluate_fitness(self, model, x_train, y_train, x_valid, y_valid):
scores = []
for individual in self.individuals:
Expand All @@ -83,11 +89,11 @@ def _evaluate_fitness(self, model, x_train, y_train, x_valid, y_valid):
if self.minimize:
score = -score
self.feature_score_hash[feature_hash] = score

if score > self.best_score:
self.best_score = score
self.best_dim = individual

scores.append(score)

self.fitness_scores = scores
Expand Down Expand Up @@ -151,7 +157,7 @@ def _produce_next_generation(self):
new_population[i + 1] = self._mutate(new_population[i + 1])
self.individuals = new_population

def _verbose_results(self, verbose, i):
def _verbose_results(self, verbose, i):
if (verbose):
if (i == 0) and (self.my_logger is None):
self.my_logger = self._setup_logger()
Expand Down

0 comments on commit 7c502b8

Please sign in to comment.