for i in range(0,self.population_sz,2): print(self.population[i]['nb_layers'], self.population[i]['layers'][0]['nb_units']) self.evaluate() children = [] print('\nPopulation mean:{} max:{}'.format( np.mean(self.evaluations), np.max(self.evaluations))) n_elite = 2 sorted_pop = np.argsort(self.evaluations)[::-1] elite = sorted_pop[:n_elite] # print top@n_elite scores # elites always included in the next population self.elite = [] print('\nTop performers:') for i,e in enumerate(elite): self.elite.append((self.evaluations[e], self.population[e])) print("{}-score:{}".format( str(i), self.evaluations[e])) children.append(self.population[e]) # tournament probabilities: # first p # second p*(1-p) # third p*((1-p)^2) # etc... p = 0.85 # winner probability tournament_size = 3 probs = [p*((1-p)**i) for i in range(tournament_size-1)] # a little trick to certify that probs is adding up to 1.0 probs.append(1-np.sum(probs)) while len(children) < self.population_sz: pop = range(len(self.population)) sel_k = random.sample(pop, k=tournament_size) fitness_k = list(np.array(self.evaluations)[sel_k]) selected = zip(sel_k, fitness_k) rank = sorted(selected, key=itemgetter(1), reverse=True) pick = np.random.choice(tournament_size, size=1, p=probs)[0] best = rank[pick][0] model = self.mutate_fn(self.population[best]) children.append(model) self.population = children # if we want to do a completely completely random search per epoch # self.population = [randomize_network(bounded=False) for i in range(self.population_sz) ]
推荐阅读
百度前首席科学家吴恩达:AI短期内不会超越人类
吴恩达认为,根本收入筹划的目标不该该是让人们持续给打车公司开车,他欲望根本收入筹划可以或许资世人们进修更多的器械,赞助他们找到有意义的工作。
腾讯科技讯 据外媒报道,固然比来有很>>>详细阅读
本文标题:如何用自动机器学习实现神经网络进化
地址:http://www.17bianji.com/lsqh/36435.html
1/2 1