def __init__(self, network: Network, max_velocity: float):
     self.network = network
     self.max_velocity = max_velocity
     self.state = np.random.uniform(low=LOWER_BOUND,
                                    high=UPPER_BOUND,
                                    size=network.get_num_weights())
     self.velocity = np.random.uniform(low=-1,
                                       high=1,
                                       size=network.get_num_weights())
     self.velocity = self.velocity * (max_velocity /
                                      np.linalg.norm(self.velocity))
     self.p_best = self.state
     self.best_fitness = self.get_fitness()
Exemple #2
0
 def __init__(self, network: Network, population_size: int, crossover_prob: float,
              creep_variance: float, mutation_prob: float, tournament_size: int, convergence_size: int):
     self.network = network
     self.population_size = population_size
     self.crossover_prob = crossover_prob
     self.creep_variance = creep_variance
     self.mutation_prob = mutation_prob
     self.tournament_size = tournament_size
     self.convergence_size = convergence_size
     self.population = [Individual(network, np.random.uniform(low=LOWER_BOUND, high=UPPER_BOUND,
                                                              size=network.get_num_weights()))
                        for i in range(population_size)]