Example #1
0
    def __init__(this, gene=None):
        super(onemax_ptype, this).__init__(gene)
        if this.gene == None:
            this.generate_gene(problem_size)


problem = raw_input("Input problem to solve (matching/onemax): ")
if problem == "matching":
    target = [int(c) for c in raw_input("Input a bit string: ")]
    problem_size = len(target)
else:
    problem_size = int(input("Input problem size: "))
    target = [1 for i in xrange(problem_size)]

population_list = evoalg.main(onemax_ptype)

best = [pop.max_fitness() for pop in population_list]
average = [pop.average_fitness() for pop in population_list]
average_plus_stddev = [
    pop.average_fitness() + pop.fitness_standard_deviation()
    for pop in population_list
]
average_minus_stddev = [
    pop.average_fitness() - pop.fitness_standard_deviation()
    for pop in population_list
]
std_dev = [pop.fitness_standard_deviation() for pop in population_list]

print "Plotting..."
fill_between(range(len(best)),
Example #2
0
    def __init__(this, gene=None):
        super(onemax_ptype, this).__init__(gene)
        if this.gene == None:
            this.generate_gene(problem_size)


problem = raw_input("Input problem to solve (matching/onemax): ")
if problem == "matching":
    target = [int(c) for c in raw_input("Input a bit string: ")]
    problem_size = len(target)
else:
    problem_size = int(input("Input problem size: "))
    target = [1 for i in xrange(problem_size)]

population_list = evoalg.main(onemax_ptype)

best = [pop.max_fitness() for pop in population_list]
average = [pop.average_fitness() for pop in population_list]
average_plus_stddev = [pop.average_fitness() + pop.fitness_standard_deviation() for pop in population_list]
average_minus_stddev = [pop.average_fitness() - pop.fitness_standard_deviation() for pop in population_list]
std_dev = [pop.fitness_standard_deviation() for pop in population_list]

print "Plotting..."
fill_between(
    range(len(best)), average_plus_stddev, average_minus_stddev, alpha=0.2, color="b", label="Standard deviation"
)
plot(range(len(best)), best, color="r", label="Best")
plot(range(len(best)), average, color="b", label="Average with std. dev.")
title("Fitness plot - Onemax")
xlabel("Generation")
Example #3
0
	def __init__(this, gene=None):
		super(blotto_ptype, this).__init__(gene)
		if this.gene == None:
			this.generate_gene(problem_size*4)
		
		this.generate_phenotype()
		
	def calc_entropy(this):
		return -sum((battle*log(battle, 2) if battle != 0 else 0) for battle in this.phenotype)
		

problem_size = int(input("Input number of battles: "))
rf = float(input("Input reployment fraction: "))
lf = float(input("Input \"morale reduction from loss\"-fraction: "))
population_list = evoalg.main(blotto_ptype)

for pop in population_list:
	pop.sort()

average_entropy = [sum(strategy.calc_entropy() for strategy in pop.get_individuals())/problem_size for pop in population_list]
best_entropy = [pop.get_individuals()[0].calc_entropy() for pop in population_list]
best = [pop.max_fitness() for pop in population_list]
average = [pop.average_fitness() for pop in population_list]
std_dev = [pop.fitness_standard_deviation() for pop in population_list]
worst = [pop.min_fitness() for pop in population_list]

topline = [average[i] + std_dev[i] for i in xrange(len(population_list))]
bottomline = [average[i] - std_dev[i] for i in xrange(len(population_list))]

figure(1)
Example #4
0
    def __init__(this, gene=None):
        super(blotto_ptype, this).__init__(gene)
        if this.gene == None:
            this.generate_gene(problem_size * 4)

        this.generate_phenotype()

    def calc_entropy(this):
        return -sum((battle * log(battle, 2) if battle != 0 else 0)
                    for battle in this.phenotype)


problem_size = int(input("Input number of battles: "))
rf = float(input("Input reployment fraction: "))
lf = float(input("Input \"morale reduction from loss\"-fraction: "))
population_list = evoalg.main(blotto_ptype)

for pop in population_list:
    pop.sort()

average_entropy = [
    sum(strategy.calc_entropy()
        for strategy in pop.get_individuals()) / problem_size
    for pop in population_list
]
best_entropy = [
    pop.get_individuals()[0].calc_entropy() for pop in population_list
]
best = [pop.max_fitness() for pop in population_list]
average = [pop.average_fitness() for pop in population_list]
std_dev = [pop.fitness_standard_deviation() for pop in population_list]