importnumpyasnpimportcmaimportmultiprocessingasmpimportfunctoolsimportmyFuncsimporthdf5storagedefmyFuncOptimization():temp=hdf5storage.loadmat('/home/joe/Desktop/optimization_folder/matlab_workspace_for_optimization')input_A_Opt=temp["input_A"]input_B_Opt=temp["input_B"]deltempnumCores=20# Inputs#________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________P0=np.array([4.66666667,2.5,2.66666667,4.16666667,0.96969697,1.95959596,0.44088176,0.04040404,6.05210421,0.58585859,0.46464646,8.75751503,0.16161616,1.24248497,1.61616162,1.56312625,5.85858586,0.01400841,1.0,2.4137931,0.38076152,2.5,1.99679872])LBOpt=np.array([0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,])UBOpt=np.array([10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,])initialStdsOpt=np.array([2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,])minStdsOpt=np.array([0.030,0.40,0.030,0.40,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.020,0.050,0.050,0.020,0.40,0.020,])options={'bounds':[LBOpt,UBOpt],'CMA_stds':initialStdsOpt,'minstd':minStdsOpt,'popsize':numCores}es=cma.CMAEvolutionStrategy(P0,1,options)pool=mp.Pool(numCores)partial_function_to_optmize=functools.partial(myFuncs.func1,input_A=input_A_Opt,input_B=input_B_Opt)whilenotes.stop():solutions=es.ask(es.popsize)f_values=pool.map_async(partial_function_to_optmize,solutions).get()es.tell(solutions,f_values)es.disp(1)es.logger.add()returnes.result_pretty()
python设置内存上限_使用多处理时克服内存限制
最新推荐文章于 2023-06-02 07:38:56 发布