PDFO(Powell's Derivative-Free Optimizationsolvers,Powell无导数优化求解器)为 MichaelJ.D.Powell 的无导数优化求解器提供跨平台的调用接口。这些求解器包括 COBYLA,UOBYQA,NEWUOA,BOBYQA,LINCOA,最初由M.J.D.Powell采用 Fortran77 实现。它们可求解黑箱优化,用于机器学习超参数调节。Powell的求解器旨在仅使用函数值而不使用目标函数或非线性约束函数的导数来求解连续变量的一般非线性优化问题 。实际应用中,此类函数通常是基于仿真模拟的黑箱。因此,相应的优化问题通常被归类为黑盒优化或基于仿真模拟的优化。UOBYQA和NEWUOA可求解无约束问题,除了相当小的问题外,NEWUOA通常表现更好;BOBYQA可求解无约束和界约束问题;LINCOA可求解决无约束、界约束和线性约束问题;COBYLA可求解一般的非线性优化问题。由显式公式定义的问题往往可以用其他方法更有效地处理。PDFO当前的版本支持 MATLAB 和 Python 。它依赖MEX和F2PY来编译Powell的 Fortran 代码,并将其封装为用户友好的函数。MATLAB或Python用户可在直接调用Powell的求解器而无需了解其Fortran实现。HansD.Mittelmann 的优化软件决策树收录了PDFO,建议将其用于“只用函数值求解一般非线性问题”。这里,“一般非线性问题”包括无约、界约束,线性约束和非线性约束问题。更多信息请访问PDFO主页 (https://pdfo.net)。安装PDFO的Python版本可通过pip安装:pipinstallpdfoMATLAB版本可从码云 (https://gitee.com/pdfo/pdfo)或 PDFO主页 (https://pdfo.net)下载源代码,用其中提供的setup脚本安装。代码示例Pythonfrompdfoimportpdfo,Bounds,LinearConstraint,NonlinearConstraint#IfSciPy(version1.1orabove)isinstalled,thenBounds,LinearConstraint,#andNonlinearConstraintcanalternativelybeimportedfromscipy.optimize.importnumpyasnpdefchrosen(x):#thesubroutinedefiningtheobjectivefunctionreturnsum((1-x[:-1])**2+4*(x[1:]-x[:-1]**2)**2)defnlc_ineq(x):#thesubroutinedefiningthenonlinearinequalityconstraintsreturnx[:-1]**2-x[1:]defnlc_eq(x):#thesubroutinedefiningthenonlinearequalityconstraintsreturnsum(x**2)-1if__name__=='__main__':print('\nMinimizethechainedRosenbrockfunctionwiththreevariablessubjecttononlinearconstraints:\n')x0=[0,0,0]#startingpointlb=[0,0,0]ub=[np.inf,np.inf,np.inf]#ub=[None,None,None]orub=Noneworksequallywellbounds=Bounds(lb,ub)#boundconstraints:lb<=x<=ub#Boundconstraintscanalsobewrittenas:bounds=[(lb[0],ub[0]),(lb[1],ub[1]),(lb[2],ub[2])]A=[[0.5,-1,0],[0,0.5,-1]]lin_lb=[-np.inf,-np.inf]lin_ub=[0,0]lin_con=LinearConstraint(A,lin_lb,lin_ub)#inequalityconstraints:lin_lb<=A*x<=lin_ubnonlin_lb=[0,0]nonlin_ub=[np.inf,np.inf]nonlin_con_ineq=NonlinearConstraint(nlc_ineq,nonlin_lb,nonlin_ub)#inequalityconstraints:nonlin_lb<=nlc_ineq(x)<=nonlin_ubnonlin_con_eq=NonlinearConstraint(nlc_eq,0,0)#equalityconstraint:nlc_eq(x)=0#Nonlinearconstraintscanalsobedefinedasdictionaries:#nonlin_con_ineq={'type':'ineq','fun':nlc_ineq}#inequalityconstraint:nlc_ineq(x)>=0#nonlin_con_eq={'type':'eq','fun':nlc_eq}#inequalityconstraint:nlc_eq(x)=0res=pdfo(chrosen,x0,bounds=bounds,constraints=[lin_con,nonlin_con_ineq,nonlin_con_eq])print(res)MATLABfunctionrosenbrock_example()fprintf('\nMinimizethechainedRosenbrockfunctionwiththreevariablessubjecttononlinearconstraints:\n');x0=[0;0;0];%startingpoint%linearinequalityconstraintsA*x<=bA=[0.5,-1,0;0,0.5,-1];b=[0;0];%linearequalityconstraintsAeq*x=beqAeq=[];beq=[];%boundconstraintslb<=x<=ublb=[0;0;0];ub=[];%ub=[inf;inf;inf]worksequallywell%nonlinearconstraintsnonlcon=@nlc;%seefunctionnlcgivenbelow%Thefollowingsyntaxisidenticaltofmincon:[x,fx,exitflag,output]=pdfo(@chrosen,x0,A,b,Aeq,beq,lb,ub,nonlcon)%Alternatively,theproblemcanbepassedtopdfoasastructure:%p.objective=@chrosen;p.x0=x0;p.Aineq=A;p.bineq=b;p.lb=lb;p.nonlcon=@nlc;%[x,fx,exitflag,output]=pdfo(p)returnfunctionf=chrosen(x)%thesubroutinedefiningtheobjectivefunctionf=sum((x(1:end-1)-1).^2+4*(x(2:end)-x(1:end-1).^2).^2);returnfunction[cineq,ceq]=nlc(x)%thesubroutinedefiningthenonlinearconstraints%Thesameasfmincon,nonlinearconstraintscineq(x)<=0andceq(x)=0arespecified%byafunctionwithtworeturns,thefirstbeingcineqandthesecondbeingceq.cineq=x(2:end)-x(1:end-1).^2;ceq=x'*x-1;return
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态
评论