Esempio n. 1
0
def main():
    """ Main function. """
    pool = Pool.spawn(Genome.open(NN_STRUCTURE_FILE), 20, std=1)

    # Set evolutionary parameters
    eonn.samplesize = 5  # Sample size used for tournament selection
    eonn.keep = 5  # Nr. of organisms copied to the next generation (elitism)
    eonn.mutate_prob = 0.75  # Probability that offspring is being mutated
    eonn.mutate_frac = 0.2  # Fraction of genes that get mutated
    eonn.mutate_std = 0.1  # Std. dev. of mutation distribution (gaussian)
    eonn.mutate_repl = 0.25  # Probability that a gene gets replaced

    directory = "pics/" + ''.join(rand.sample(letters + digits, 5))
    os.makedirs(directory)
    # Evolve population
    for j in xrange(1, ROUNDS + 1):
        pool = eonn.optimize(pool, cliff, epochs=EPOCHS, evals=EVALS)
        print "AFTER EPOCH", j * EPOCHS
        print "average fitness %.1f" % pool.fitness
        champion = max(pool)
        print "champion fitness %.1f" % champion.fitness
        for i in xrange(10):
            cliff(champion.policy, verbose=True)
        plt.savefig(directory + "/" + str(j * EPOCHS) + ".png")
        plt.clf()
    with open(directory + '/best.net', 'w') as f:
        f.write('%s' % champion.genome)
    print "Done, everything saved in ", directory
Esempio n. 2
0
def evolve(heli, genome, popsize=50, epochs=100, keep=49, mutate_prob=.75, mutate_frac=.1, mutate_std=.8, mutate_repl=.25, verbose=False):
  """ Evolve a specialized policy for the given helicopter environment. """
  # Set evolutionary parameters
  eonn.keep = keep
  eonn.mutate_prob = mutate_prob
  eonn.mutate_frac = mutate_frac
  eonn.mutate_std = mutate_std
  eonn.mutate_repl = mutate_repl
  # Evolve population and return champion
  feval = Evaluator(heli)
  pool = spawn(genome, popsize)
  return max(eonn.optimize(pool, feval.call, epochs, 1, verbose))
Esempio n. 3
0
def main():
	""" Main function. """
	pool = Pool.spawn(Genome.open('mc.net'), 20, std=5.0)
	# Set evolutionary parameters
	eonn.KEEP = 5
	eonn.MUTATE_PROB = 0.9
	eonn.MUTATE_FRAC = 0.2
	eonn.MUTATE_STD = 8.0
	eonn.MUTATE_REPL = 0.1
	# Evolve population
	pool = eonn.optimize(pool, mc)
	champion = max(pool)
	# Print results
	print '\ntrace:'
	mc(champion.policy, verbose=True)
	print '\ngenome:\n%s' % champion.genome
Esempio n. 4
0
def main():
  """ Main function. """
  pool = Pool.spawn(Genome.open('mc.net'), 20, std=5.0)
  # Set evolutionary parameters
  eonn.keep = 5
  eonn.mutate_prob = 0.9
  eonn.mutate_frac = 0.2
  eonn.mutate_std = 8.0
  eonn.mutate_repl = 0.1
  # Evolve population
  pool = eonn.optimize(pool, mc)
  champion = max(pool)
  # Print results
  print '\ntrace:'
  mc(champion.policy, verbose=True)
  print '\ngenome:\n%s' % champion.genome
Esempio n. 5
0
def evolve(heli,
           genome,
           popsize=50,
           epochs=100,
           keep=49,
           mutate_prob=.75,
           mutate_frac=.1,
           mutate_std=.8,
           mutate_repl=.25,
           verbose=False):
    """ Evolve a specialized policy for the given helicopter environment. """
    # Set evolutionary parameters
    eonn.keep = keep
    eonn.mutate_prob = mutate_prob
    eonn.mutate_frac = mutate_frac
    eonn.mutate_std = mutate_std
    eonn.mutate_repl = mutate_repl
    # Evolve population and return champion
    feval = Evaluator(heli)
    pool = spawn(genome, popsize)
    return max(eonn.optimize(pool, feval.call, epochs, 1, verbose))
Esempio n. 6
0
File: heli.py Progetto: afcarl/ATAA
from eonn.genome import Genome
from eonn.organism import Pool
from helicopter.helicopter import Helicopter, XcellTempest


def hover(policy):
    """ Helicopter evaluation function. """
    state, sum_error = heli.reset()
    while not heli.terminal:
        action = policy.propagate(state, 1)
        state, error = heli.update(action)
        sum_error += error
    return 1 / math.log(sum_error)


if __name__ == '__main__':
    heli = Helicopter(XcellTempest.params, XcellTempest.noise_std)
    pool = Pool.spawn(Genome.open('baseline.net'), 20)
    # Set evolutionary parameters
    eonn.keep = 15
    eonn.mutate_prob = 0.9
    eonn.mutate_frac = 0.1
    eonn.mutate_std = 0.8
    eonn.mutate_repl = 0.15
    # Evolve population
    pool = eonn.optimize(pool, hover)
    champion = max(pool)
    # Print results
    print '\nerror:', math.exp(1 / hover(champion.policy))
    print '\ngenome:\n%s' % champion.genome
Esempio n. 7
0
from eonn.organism import Pool


def xor(policy, verbose=False):
	""" XOR evaluation function. """
	err = 0.0
	input = [(i, j) for i in range(2) for j in range(2)]
	for i in input:
		output = policy.propagate(i, 1);
		err += (output[0] - (i[0] ^ i[1]))**2
		if verbose:
			print i, '-> %.4f (%d)' % (output[0], round(output[0]))
	return 1.0 / err


if __name__ == '__main__':
	pool = Pool.spawn(Genome.open('xor.net'), 30)
	# Set evolutionary parameters
	eonn.KEEP = 1
	eonn.MUTATE_PROB = 0.9
	eonn.MUTATE_FRAC = 0.25
	eonn.MUTATE_STD = 0.8
	eonn.MUTATE_REPL = 0.2
	# Evolve population
	pool = eonn.optimize(pool, xor)
	champion = max(pool)
	# Print results
	print '\noutput:'
	xor(champion.policy, True)
	print '\ngenome:\n%s' % champion.genome
Esempio n. 8
0
from eonn.genome import Genome
from eonn.organism import Pool
from helicopter.helicopter import Helicopter, XcellTempest


def hover(policy):
  """ Helicopter evaluation function. """
  state, sum_error = heli.reset()
  while not heli.terminal:
    action = policy.propagate(state, 1)
    state, error = heli.update(action)
    sum_error += error
  return 1 / math.log(sum_error)


if __name__ == '__main__':
  heli = Helicopter(XcellTempest.params, XcellTempest.noise_std)
  pool = Pool.spawn(Genome.open('baseline.net'), 20)
  # Set evolutionary parameters
  eonn.keep = 15
  eonn.mutate_prob = 0.9
  eonn.mutate_frac = 0.1
  eonn.mutate_std = 0.8
  eonn.mutate_repl = 0.15
  # Evolve population
  pool = eonn.optimize(pool, hover)
  champion = max(pool)
  # Print results
  print '\nerror:', math.exp(1 / hover(champion.policy))
  print '\ngenome:\n%s' % champion.genome
Esempio n. 9
0
from eonn.organism import Pool


def xor(policy, verbose=False):
  """ XOR evaluation function. """
  err = 0.0
  input = [(i, j) for i in range(2) for j in range(2)]
  for i in input:
    output = policy.propagate(i, 1);
    err += (output[0] - (i[0] ^ i[1]))**2
    if verbose:
      print i, '-> %.4f' % output[0]
  return 1.0 / err


if __name__ == '__main__':
  pool = Pool.spawn(Genome.open('xor.net'), 30)
  # Set evolutionary parameters
  eonn.keep = 1
  eonn.mutate_prob = 0.9
  eonn.mutate_frac = 0.25
  eonn.mutate_std = 0.8
  eonn.mutate_repl = 0.2
  # Evolve population
  pool = eonn.optimize(pool, xor)
  champion = max(pool)
  # Print results
  print '\noutput:'
  xor(champion.policy, True)
  print '\ngenome:\n%s' % champion.genome