问题
I want to solve a constrained NLP in Pyomo. However, the objective function includes a normal distribution where the argument of the normal distribution contains the decision variable, e.g. an expression like - (norm.cdf(model.x[0]))
.
But I receive this error:
Cannot convert object of type 'ndarray' (value = 1) to a numeric value.
Is there a way of working with normal distributions in Pyomo?
回答1:
I think that you can't use the variable as parameter, because pyomo's variable isn't the python's variable. You could write the expression of the normal distribution, maybe this works.
回答2:
I have seen that pyomo isn't a fan of some of the typical math you might be used to wanting in pyton or black box functions (Optimizing Fortran function in pyomo and https://groups.google.com/forum/#!topic/pyomo-forum/dK71XrHlBIM).
I think in this case you probably will need to write out an approximation of the normal cdf in the object (gross, I know). Might I suggest:
1/(model.x[0]*2.50663)*(1-model.x[0]**-2+3*model.x[0]**-4+15*model.x[0]**-6-105*model.x[0]**-8)
which is based on this post: https://mathoverflow.net/questions/19404/approximation-of-a-normal-distribution-function
Here is a cool paper of other options: http://www.hrpub.org/download/20140305/MS7-13401470.pdf
来源:https://stackoverflow.com/questions/54037358/probability-distributions-in-pyomo