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)
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) activenodes = {root}
'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, # 个体输出动作 'env.target': handle_set_target # 环境设定目标 }) #endregion #region 启动进化环境 evo = EvolutionTask(1, popParam, None) evo.execute(runParam) #endregion
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)