Beispiel #1
0
def main():
    env = gym.make('SlimeVolley-v0')
    env.seed(123)

    POPULATION_SIZE = 20
    MAX_GENERATION = 100
    MUTATION_RATE = 0.4
    CROSSOVER_RATE = 0.7

    INPUT_SIZE = 12
    OUTPUT_SIZE = 3

    assert POPULATION_SIZE % 2 == 0
    p = Population(DeepMLPTorchIndividual(INPUT_SIZE, 0,
                                          OUTPUT_SIZE), POPULATION_SIZE,
                   MAX_GENERATION, MUTATION_RATE, CROSSOVER_RATE, 0.0)
    p.set_population([
        DeepMLPTorchIndividual(INPUT_SIZE, 0, OUTPUT_SIZE)
        for _ in range(POPULATION_SIZE)
    ])
    p.run(
        env,
        generation,
        verbose=True,
        log=True,
        output_folder=f'model-layers={INPUT_SIZE}-{HIDDEN_SIZE}-{OUTPUT_SIZE}',
        save_as_pytorch=False)
Beispiel #2
0
        if child1.fitness + child2.fitness > parent1.fitness + parent2.fitness:
            new_population[i] = child1
            new_population[i + 1] = child2
        else:
            new_population[i] = parent1
            new_population[i + 1] = parent2

if __name__ == '__main__':
    env = gym.make('CarRacing-v0')
    POPULATION_SIZE = 100
    MAX_GENERATION = 2
    MUTATION_RATE = 0.1
    CROSSOVER_RATE = 0.8

    p = Population(ConvNetTorchIndividal(None, None, None), POPULATION_SIZE, MAX_GENERATION, MUTATION_RATE, CROSSOVER_RATE, 0)
    p.run(env, generation, verbose=False, output_folder='')

    env.close()



'''
초기화
for in max_generation (총 세대수){

for old_population : 적합성 계산 ( 100 episode * population_size )

run_generation(env, old, new, mutation, crossover){
	for old population / 2
	parent1,parent2 = 적합성 기준 2개 select
	child1,child2 = (parent1,parent2,crossover){
Beispiel #3
0
            # 4.
            if np.random.rand() < p_inversion:
                child1.weights_biases = inversion(child1.weights_biases)
                child2.weights_biases = inversion(child2.weights_biases)

            new_population.append(child1)
            new_population.append(child2)


if __name__ == '__main__':
    env = gym.make('BipedalWalker-v2')
    env.seed(123)

    POPULATION_SIZE = 10
    MAX_GENERATION = 20
    MUTATION_RATE = 0.01
    CROSSOVER_RATE = 0.8
    INVERSION_RATE = 0.02

    INPUT_SIZE = 10
    HIDDEN_SIZE = 16
    OUTPUT_SIZE = 4

    p = Population(MLPTorchIndividual(INPUT_SIZE, HIDDEN_SIZE, OUTPUT_SIZE),
                   POPULATION_SIZE, MAX_GENERATION, MUTATION_RATE,
                   CROSSOVER_RATE, INVERSION_RATE)
    p.run(env, generation_new, verbose=True, log=True, output_folder='')

    env.close()
Beispiel #4
0

if __name__ == '__main__':
    env = gym.make('BipedalWalker-v2')
    env.seed(123)

    POPULATION_SIZE = 10
    MAX_GENERATION = 10
    MUTATION_RATE = 0.01
    CROSSOVER_RATE = 0.8

    INPUT_SIZE = 24
    OUTPUT_SIZE = 4

    assert POPULATION_SIZE % 2 == 0
    p = Population(DeepBipedalWalkerIndividual(INPUT_SIZE, 0,
                                               OUTPUT_SIZE), POPULATION_SIZE,
                   MAX_GENERATION, MUTATION_RATE, CROSSOVER_RATE, 0.0)
    p.set_population([
        DeepBipedalWalkerIndividual(INPUT_SIZE, 0, OUTPUT_SIZE)
        for _ in range(POPULATION_SIZE)
    ])
    p.run(
        env,
        generation,
        verbose=True,
        log=True,
        output_folder=f'model-layers={INPUT_SIZE}-{HIDDEN_SIZE}-{OUTPUT_SIZE}',
        save_as_pytorch=False)
    env.close()
            new_population[i + 1] = child2
        else:
            new_population[i] = parent1
            new_population[i + 1] = parent2


if __name__ == '__main__':
    env = gym.make('CartPole-v1')
    env.seed(123)

    POPULATION_SIZE = 100
    MAX_GENERATION = 20

    MUTATION_RATE = 0.4
    CROSSOVER_RATE = 0.9

    INPUT_SIZE = 4
    HIDDEN_SIZE = 2
    OUTPUT_SIZE = 1

    p = Population(MLPIndividual(INPUT_SIZE, HIDDEN_SIZE,
                                 OUTPUT_SIZE), POPULATION_SIZE, MAX_GENERATION,
                   MUTATION_RATE, CROSSOVER_RATE, 0)
    p.run(env,
          generation,
          verbose=True,
          output_folder='../../models/cartpole',
          log=True)

    env.close()