EvoTorch是一个直接构建在PyTorch之上的高级进化算法库,由NNAISENSE创建。EvoTorch旨在加速进化算法的研究和应用,并专门支持NeuroEvolutio。
pipistallevotorch使用EvoTorch,可以解决各种优化问题,而不必担心手头的这些问题是否可微。EvoTorch可解决的问题类型包括:Black-box优化问题(连续或离散)强化学习任务监督学习任务等等EvoTorch中提供了各种进化计算算法:基于分布的搜索算法:PGPE:基于参数探索的策略梯度。XNES:指数自然进化策略。SNES:可分离的自然进化策略。CEM:交叉熵方法。基于群体的搜索算法:SteadyStateGA:一个完全精英化的遗传算法实现。还支持多个目标,在这种情况下,其行为类似于 NSGA-II。CoSyNE:协同突触神经进化。上面提到的所有这些算法都是在PyTorch中实现的,因此可以从PyTorch的矢量化和GPU功能中受益。此外,在Ray库的帮助下,EvoTorch可以通过将工作负载分散到以下方面来进一步扩展这些算法:多个CPU多个GPURay集群上的多台计算机black-box优化示例fromevotorchimportProblemfromevotorch.algorithmsimportSNESfromevotorch.loggigimportStdOutLogger,PadasLoggerimportmathimportmatplotlib.pyplotaspltimporttorch#Declaretheobjectivefuctiodefrastrigi(x:torch.Tesor)->torch.Tesor:A=10(_,)=x.shapereturA*+torch.sum((x**2)-A*torch.cos(2*math.pi*x),1)#Declaretheproblemproblem=Problem("mi",rastrigi,iitial_bouds=(-5.12,5.12),solutio_legth=100,vectorized=True,#device="cuda:0"#eablethislieifyouwishtouseGPU)#IitializetheSNESalgorithmtosolvetheproblemsearcher=SNES(problem,popsize=1000,stdev_iit=10.0)#Iitializeastadardoutputlogger,adapadaslogger_=StdOutLogger(searcher,iterval=10)padas_logger=PadasLogger(searcher)#RuSNESforthespecifiedamoutofgeeratiossearcher.ru(2000)#GettheprogressoftheevolutioitoaDataFramewiththe#helpofthePadasLogger,adtheplottheprogress.padas_frame=padas_logger.to_dataframe()padas_frame["best_eval"].plot()plt.show()强化学习示例fromevotorch.algorithmsimportPGPEfromevotorch.loggigimportStdOutLoggerfromevotorch.euroevolutioimportGymNE#Declaretheproblemtosolveproblem=GymNE(ev_ame="Humaoid-v4",#SolvetheHumaoid-v4tasketwork="Liear(obs_legth,act_legth)",#Liearpolicyobservatio_ormalizatio=True,#Normalizethepolicyiputsdecrease_rewards_by=5.0,#Decreaseeachrewardby5.0um_actors="max",#UseallavailableCPUs#um_actors=4,#Explicitsettig.Use4actors.)#IstatiateaPGPEalgorithmtosolvetheproblemsearcher=PGPE(problem,#Basepopulatiosizepopsize=200,#Foreachgeeratio,samplemoresolutiosutilthe#umberofsimulatoriteractiosreachesthisthresholdum_iteractios=it(200*1000*0.75),#Stopre-sampligsolutiosifthecurretpopulatiosize#reachesorexceedsthisumber.popsize_max=3200,#Learigratesceter_learig_rate=0.0075,stdev_learig_rate=0.1,#Radiusoftheiitialsearchdistributioradius_iit=0.27,#UsetheClipUpoptimizerwiththespecifiedmaximumspeedoptimizer="clipup",optimizer_cofig={"max_speed":0.15},)#Istatiateastadardoutputlogger_=StdOutLogger(searcher)#Ruthealgorithmforthespecifiedamoutofgeeratiossearcher.ru(500)#Gettheceterpoitofthesearchdistributio,#obtaiapolicyoutofthatpoit,advisualizethe#agetusigthatpolicy.ceter_solutio=searcher.status["ceter"]traied_policy=problem.make_et(ceter_solutio)problem.visualize(traied_policy)
更多示例可以在这里找到。
评论