Esempio n. 1
0
 def plot(self):
     training_nr = 1
     spiketrain1 = self.ea.best_overall_individual.spiketrain
     spiketrain2 = read_training_files()
     
     title_string = "Pop size: %s. Generations: %s Fitness: %s Distance: %s \nC-rate: %s M-rate: %s Overproduction: %s R-Max: %s Dataset: %s \n%s"%(
                                                                   self.ea.population_size,
                                                                   self.ea.generation,
                                                                   self.ea.best_overall_individual.fitness, 
                                                                   self.ea.best_overall_individual.distance, 
                                                                   self.ea.crossover_rate,
                                                                   self.ea.mutation_probability,
                                                                   self.ea.overproduction_factor,
                                                                   self.ea.rank_max,
                                                                   training_nr, 
                                                                   self.ea.best_overall_individual)
     fig = plt.figure()
     plt.title(title_string, fontsize=10)
     plt.plot(xrange(0,1001), spiketrain1, xrange(0,1001), spiketrain2)
     plt.ylabel("Test spiketrain vs best evolved spiketrain")
     run_string = "%s-%spop-%sgen-%sfit-%sdist-%scross-%smut-%sop-%srmax-%sdata-%s.png"%("EA",
                                                                   self.ea.population_size,
                                                                   self.ea.generation,
                                                                   self.ea.best_overall_individual.fitness, 
                                                                   self.ea.best_overall_individual.distance, 
                                                                   self.ea.crossover_rate,
                                                                   self.ea.mutation_probability,
                                                                   self.ea.overproduction_factor,
                                                                   self.ea.rank_max,
                                                                   training_nr, 
                                                                   self.ea.best_overall_individual)
     fig.savefig("spiketrains/"+run_string+".png")
     print run_string +" fit:" +str(self.ea.best_overall_individual.fitness)+" dist:"+str(self.ea.best_overall_individual.distance) + str(self.ea.best_overall_individual)
     
     fig = plt.figure()
     plt.title(title_string)
     plt.subplot(211)
     plt.plot(self.generation, self.max_fitness, self.generation, self.avg_fitness)
     plt.ylabel("Max and average fitness")
     
     plt.subplot(212)
     plt.plot(self.generation, self.std_deviation)
     plt.ylabel("Standard deviation")
     fig.savefig("fitnessplots/"+run_string+".png")
Esempio n. 2
0
            #WAR done, increment fitness of winner based on points
            if points_commander>points_opponent:
                commander.increment_fitness(2)
            if points_commander<points_opponent:
                opposing_commander.increment_fitness(2)
            if points_commander==points_opponent:
                commander.increment_fitness(1)
                opposing_commander.increment_fitness(1)
            commander.reset()
            opposing_commander.reset()
            
#3 different fitness calculations: 
#Spike Time
#Spike Interval
#Waveform
trainingdata = read_training_files()
def izzy_spike_time(p, training_spikes):
    power = 4
    S_b = training_spikes
    S_a = p.spikes
        
    N = min(len(S_a),len(S_b))
    if N == 0:
        return 0.0
        
    sigma = 0
    for t_ai, t_bi in zip(S_a, S_b):
        sigma += abs(t_ai - t_bi)**power
        
    nv = sigma ** (power ** -1)
    dist = nv/N