思想:进化理论,优胜劣汰
过程:初始化一种群,生宝宝,淘汰差的,保留优的且让它繁殖。
算法框架:
def F(x): return np.sin(10*x)*x + np.cos(2*x)*x # to find the maximum of this function
def get_fitness(pred): # find non-zero fitness for selection
def translateDNA(pop): # convert binary DNA to decimal
def select(pop, fitness): # nature selection wrt pop's fitness
def crossover(parent, pop): # mating process 1 (genes crossover)
- def mutate(child): # mating process 2