add: fitness best values
This commit is contained in:
+7
-1
@@ -22,6 +22,9 @@ class GeneticAlgorithm:
|
||||
self.percentageBest = percentageBest
|
||||
self.percentageNew = percentageNew
|
||||
self.inputSize = inputSize
|
||||
|
||||
self.fitnessBest = []
|
||||
|
||||
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
||||
print(self.device)
|
||||
self.initialize_population()
|
||||
@@ -53,7 +56,10 @@ class GeneticAlgorithm:
|
||||
return model
|
||||
|
||||
def learn(self, fitness: list):
|
||||
self.population = [self.population[x] for x in np.argsort(fitness)[::-1]]
|
||||
sortedFitnessArg = np.argsort(fitness)[::-1]
|
||||
self.fitnessBest.append(fitness[sortedFitnessArg[0]])
|
||||
print(self.fitnessBest[-1])
|
||||
self.population = [self.population[x] for x in sortedFitnessArg]
|
||||
numBest = int(self.populationSize * self.percentageBest)
|
||||
self.population = self.population[:numBest]
|
||||
while len(self.population) < self.populationSize - self.populationSize * self.percentageNew:
|
||||
|
||||
Reference in New Issue
Block a user