def run(): # ehnal网络初始化 senal.ehnal_init() netdef = brain.createNetDef(neuronCounts=[30, 6]) pop_param = evolution.createPopParam(size=50) run_param = evolution.createRunParam() session = Session() monitor = session.run()
from pybullet_envs.bullet import bullet_client from evolution.session import EvolutionTask import ne.neat as neat import ne.neat.config as config import evolution import domains.antbullet.env as env import domains.antbullet.measure as measure from brain.networks import NeuralNetworkTask if __name__ == '__main__': # NEAT 前馈网络 neat.neat_init() task = NeuralNetworkTask() netdef = config.createNetDef(task, neuronCounts=[30, 8]) popParam = evolution.createPopParam(indTypeName='network', size=100, elitistSize=0.01, genomeDefinition=netdef, evaluators=[ (env.fitness, 0.5, 'fitness'), (measure.novelty, 0.5, 'novelty') ], species=config.defaultSpeciesMethod()) runParam = evolution.createRunParam( debug=True, operations="NSGA2,neat_crossmate,neat_mutate") evolutionTask = EvolutionTask(1, popParam, env.callback) evolutionTask.execute(runParam)
elif oper == 1:v += 1 else: v -= 1 newg = g newg[index] = str(v) return newg def phenome_mutate(p): g,pt = phenome_spilt(p) newg = genome_mutate(g) postfix = np.random.uniform(low=0, high=99) if len(postfix) < 2: postfix = '0' + str(postfix) return newg + postfix #endregion #region init popParam = evolution.createPopParam(size=10000,evaluators=fitnessLandscape.fitness,genomeFactory=VEEGenomeFactory()) runParam = evolution.createRunParam(maxIterCount=1000,operations='') generation,max_generation = 0,10000 pop = Population.create(popParam) class Node: def __init__(self,genome,level,inds,childs,parent): self.genome = genome self.level = level self.inds = inds self.childs = childs self.parent = parent self.features = {} root = Node(init_genome,0,pop.inds,[],None)
'attributes': {} }] netdef.box = { 'activation_threadshold': 0.5, # 激活门限,小于该值相当于没有激活 'overflow_count': 20, # 溢出数量,超过该数量将导致节点分裂 'adjust_count': 10, # 调整数量,超出该数量将导致节点均值和协方差调整 'energy': [0., 1.], # 瞬时能量限制范围 'init_lambda': 1., # 初始协方差矩阵系数 'grid_size': 100, # 特征空间中每个维度的网格数,总网格数为维度个gird_size相乘 'benchmark_energy': 1.0 # 瞬时基准能耗 } #endregion #region 种群参数和运行参数 popParam = evolution.createPopParam(size=100, elitistSize=0.05, genomeDefinition=netdef) runParam = evolution.createRunParam( 1000, 1.0, mutate_propotion=0.2, activity={ 'stability_threshold': 0.8, 'stability_resdual': 0.2, 'stability_max_count': 3, 'stability_output_count': 3, 'autonomous_targe': 10 }, handlers={ 'ind.begin': handle_ind_begin, # 个体活动初始化 'ind.action': handle_ind_action, # 个体输出动作
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(os.path.dirname(currentdir)) os.sys.path.insert(0, parentdir) from pybullet_envs.bullet import bullet_client from evolution.session import EvolutionTask import ne.neat as neat import ne.neat.config as config import evolution import domains.antbullet.env as env from brain.networks import NeuralNetworkTask if __name__ == '__main__': # NEAT 前馈网络 neat.neat_init() task = NeuralNetworkTask() netdef = config.createNetDef(task,neuronCounts=[30,8]) popParam = evolution.createPopParam(indTypeName='network', size=100, elitistSize=0.01, genomeDefinition=netdef, evaluators=env.fitness, species=config.defaultSpeciesMethod() ) runParam = evolution.createRunParam() evolutionTask = EvolutionTask(1,popParam,env.callback) evolutionTask.execute(runParam)