Example #1
0
def run():
    pop = population.Population('xor2_config')
    pop.epoch(eval_fitness, 300)

    winner = pop.most_fit_genomes[-1]
    print('Number of evaluations: %d' % winner.ID)

    # Verify network output against training data.
    print('\nBest network output:')
    net = nn.create_feed_forward_phenotype(winner)
    for inputs, expected in zip(INPUTS, OUTPUTS):
        output = net.serial_activate(inputs)
        print("expected %1.5f got %1.5f" % (expected, output[0]))

    print(nn.create_feed_forward_function(winner))

    # Visualize the winner network and plot statistics.
    visualize.plot_stats(pop.most_fit_genomes, pop.avg_fitness_scores)
    visualize.plot_species(pop.species_log)
    visualize.draw_net(winner, view=True)
Example #2
0
from neat import nn
from neat.config import Config
from cart_pole import CartPole, run_simulation, num_steps, discrete_actuator_force
from movie import make_movie


# load the winner
with open('nn_winner_genome', 'rb') as f:
    c = pickle.load(f)

print('Loaded genome:')
print(c)
print()
print('Python implementation of network:')
print(nn.create_feed_forward_function(c))

local_dir = os.path.dirname(__file__)
config = Config(os.path.join(local_dir, 'nn_config'))
net = nn.create_feed_forward_phenotype(c)

sim = CartPole()

print()
print("Initial conditions:")
print("        x = %.4f" % sim.x)
print("    x_dot = %.4f" % sim.dx)
print("    theta = %.4f" % sim.theta)
print("theta_dot = %.4f" % sim.dtheta)
print()
n = run_simulation(sim, net, discrete_actuator_force)