Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

$ hexo new "My New Post"

the information is here

class GA:
def __init__(self, name, gender, age):
self.name = name
self.gender = gender
self.age = age
def __str__(self):
return f"name:{name},gender:{gender},age:{age}"

from deap import base,tools,algorithms,creator
import numpy as np
# import random

IND_NUM = 30 # 30位编码,[-5,5],精度是8位
POP_NUM = 100 # 种群总个体数量
OFS_MAX = 50 # 后代最大值

def decode(individual):
num = int(''.join([str(i) for i in individual]),2)
return (-5 + (10 * num)/(2**30 - 1))

def eval(individual):
x = decode(individual)
return ((np.square(x) + x) * np.cos(2 * x) + np.square(x) + x)


creator.create("FitnessMin",base.Fitness,weights=(-1.0,))
creator.create("Individual",list,fitness = creator.FitnessMin)

toolbox = base.Toolbox()
toolbox.register("attribute",np.random.randint,0,2)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attribute, n=IND_NUM)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
pop = toolbox.population(n=100)

toolbox.register("evaluate", eval)
toolbox.register("select", tools.selTournament, 3)
toolbox.register("mate", tools.cxUniform, indpb=0.5)
toolbox.register("mutate", tools.mutFlipBit, indpb=0.5)
# tools.mutFlipBit()


stats = tools.Statistics(key=lambda x: x.fitness.values)
stats.register("avg", np.mean)
stats.register("std", np.std)
stats.register("min", np.min)
stats.register("max", np.max)

resultPop, logbook = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=POP_NUM, stats=stats, verbose=False)
logbook.header = 'gen','nevals','avg','std','min','max'

print(logbook)

More info: Writing

Run server

  • 我有一个好点子

    tab名字为第一个Tab

    只有图标 没有Tab名字

    名字+icon

作者: Jerry
連結: https://butterfly.js.org/posts/4aa8abbe/
來源: Butterfly
著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment