nonlinear-optimization

“multiple inequality constraints” - Minimization with R nloptr package

北城余情 提交于 2020-01-14 03:54:07
问题 Is there a way to define multiple "inequality constraints" in nloptr package in R? The inequality function needs to have five inequality constraints; colsum of a matrix (stacked from a integer vector) <=1 . (5 out of 6 columns) This is how I implemented to achieve it: constraint.func <- function(my.data.var) { column = 2 constr <- c("numeric",ncol(my.data.matrix.inj) ) for(index in 1:ncol(my.data.matrix.inj)) #1 to 5 { constr[index] <- sum(my.data.var[column], my.data.var[column+6], my.data

R: Error in is.nloptr(ret) : objective in x0 returns NA

限于喜欢 提交于 2020-01-11 10:49:49
问题 I am trying to use the nloptr package to find the optimal x value that maximized the non-linear function F=b0+b1*x+b2*x^2+b3*x^3. I am using the following code with apply() function in order to loop it through each individual row of the Regression data frame and get the optimal value of the function for each individual row: F <- function(x,b0,b1,b2,b3){return(b0+b1*x+b2*x^2+b3*x^3)} Optimal <- apply(Regression,1,function(i){ nloptr( x0 <- c(0) ,eval_f <- F ,eval_g_ineq = NULL ,eval_g_eq =

Solve a pair of coupled nonlinear equations within certain limits

回眸只為那壹抹淺笑 提交于 2020-01-06 16:23:15
问题 This answer to this question works only for situations in which the desired solution to the coupled functions is not restricted to a certain range. But what if, for example, we wanted a solution such that 0 < x < 10 and 0 < y < 10 ? Another way of thinking about this is, what if the coupled functions are undefined when x or y is, e.g., less than zero? There are functions within scipy.optimize that find roots to a function within a given interval (e.g., brentq), but these work only for

solving the Chapman-Richards equation

社会主义新天地 提交于 2020-01-05 06:29:15
问题 I need to find a way to solve the Chapman-Richards with 3 parameters. The equation is F=a(1-EXP(-bt)) power c It is a nonlinear problem. The goal is to minimize the error and the constraints are that the 3 variables must be >= 0.0001. Our current implementation uses Excel and the Solver plugin (GRG nonlinear method). But now, we need to implement all this without making use of Excel. My questions are: 1. Is it possible to use MS Solver Foundation to solve this problem? I have read some docs

Automatic differentiation (AD) with respect to list of matrices in Haskell

我只是一个虾纸丫 提交于 2020-01-04 10:06:22
问题 I am trying to understand how can I use Numeric.AD (automatic differentiation) in Haskell. I defined a simple matrix type and a scalar function taking an array and two matrices as arguments. I want to use AD to get the gradient of the scoring function with respect to both matrices, but I'm running into compilation problems. Here is the code {-# LANGUAGE DeriveTraversable, DeriveFunctor, DeriveFoldable #-} import Numeric.AD.Mode.Reverse as R import Data.Traversable as T import Data.Foldable as

IPOPT options for reducing constraint violation after fewer iterations

扶醉桌前 提交于 2020-01-04 06:57:09
问题 I am using IPOPT implemented through OpenMDAO and am having some trouble understanding and controlling the stopping criteria. Here is what I'm experiencing specifically: Initially, IPOPT is able to find a solution that appears to be much better, although constraints are violated slightly (intuition tells me that adjusting a few parameters would likely bring it into the feasible region). From this discussion I understand that "linear or nonlinear equality or inequality constraint will not

Passing arguments in nonlinear optimization function `nloptr`

人走茶凉 提交于 2020-01-02 04:47:22
问题 My initial question can be found here:Optimization in R with arbitrary constraints It led to another question how to pass arguments into nloptr . I need to minimize a function F(x,y,A) where x and y are vectors and A is a matrix, while having constrains that sum(x * y) >= sum(y/3) and sum(x)=1 . I have tried to use nloptr : F <- function(x,y,A){ ... } Gc <- function(x,y){ return(sum(y/3) - sum(x*y)) } Hc <- function(x){ retunr(1-sum(x)) } nloptr(x0=rep(1/3,3), eval_f=F, lb = 0.05, ub = 1,

Scipy selects nan as inputs while minimizing

荒凉一梦 提交于 2020-01-01 19:53:13
问题 I have this objective function (in python) : actions= [...] # some array Na= len(actions) # maximize p0 * qr(s,a0,b0) + ... + pn * qr(s,an,bn) def objective(x): p = x[:Na] # p is a probability distribution b = x[Na:2 * Na] # b is an array of positive unbounded scalars q = np.array([qr(s, actions[a], b[a]) for a in range(0, Na)]) # s is an array rez = - np.dot(p, q) # np stands for numpy library return rez qr and qc are regression trees, these are functions mapping arrays to scalars. I have

Non Linear Integer Programming

╄→尐↘猪︶ㄣ 提交于 2020-01-01 10:49:10
问题 I would like to know if there is a package in R handling non linear integer optimization. "Basically", I would like to solve the following problem: max f(x) s.t x in (0,10) and x is integer . I know that some branching algorithms are able to handle the linear version of this problem, but here my function f() might be more complicated. (I can't even make sure it would be quadratic of the form f(x)=xQx ). I guess there is always the brute force solution to test all the possibilities as long as

Finding a curve to match data

橙三吉。 提交于 2019-12-29 03:30:47
问题 I'm looking for a non-linear curve fitting routine (probably most likely to be found in R or Python, but I'm open to other languages) which would take x,y data and fit a curve to it. I should be able to specify as a string the type of expression I want to fit. Examples: "A+B*x+C*x*x" "(A+B*x+C*x*x)/(D*x+E*x*x)" "sin(A+B*x)*exp(C+D*x)+E+F*x" What I would get out of this is at least the values for the constants (A, B, C, etc.) And hopefully stats about the fitness of the match. There are