Optimization in R with arbitrary constraints

霸气de小男生 提交于 2019-12-05 07:35:04

问题


I have done it in Excel but need to run a proper simulation in R.

I need to minimize function F(x) (x is a vector) while having constraints that sum(x)=1, all values in x are [0,1] and another function G(x) > G_0.

I have tried it with optim and constrOptim. None of them give you this option.


回答1:


The problem you are referring to is (presumably) a non-linear optimization with non-linear constraints. This is one of the most general optimization problems.

The package I have used for these purposes is called nloptr: see here. From my experience, it is both versatile and fast. You can specify both equality and inequality constaints by setting eval_g_eq and eval_g_ineq, correspondingly. If the jacobians are known explicitly (can be derived analytically), specify them for faster convergence; otherwise, a numerical approximation is used.

Use this list as a general reference to optimization problems.




回答2:


Write the set of equations using the Lagrange multiplier, then solve using the R command nlm.




回答3:


You can do this in the OpenMx Package (currently host at the site listed below. Aiming for 2.0 relase on cran this year)

It is a general purpose package mostly used for Structural Equation Modelling, but handling nonlinear constraints.

FOr your case, make an mxModel() with your algebras expressed in mxAlgebras() and the constraints in mxConstraints()

When you mxRun() the model, the algebras will be solved within the constraints, if possible.

http://openmx.psyc.virginia.edu/



来源:https://stackoverflow.com/questions/21611092/optimization-in-r-with-arbitrary-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!