Re: [R] Optimization problem
Hi Greg, The problem is that I also have restrictions for each variable (they must be higher than -.07 and smaller than .2) and I'm dealing with a lot of them. I've already tried the second approach but, as far as it seems, the function doesn't satisfy my objective. That's what I'm doing: . faum = function(aum) { (...) ifelse(colMeans(prob) .65, totm - (sum(marg)), totm - -1e10) #prob is a transformation of 'aum' and sum(marg) (always positive) is what I want to maximize (...) return(-totm) } optim(rep(0,nrow), faum, method=L-BFGS-B, control=list(trace=12), lower=rep(-.07,nrow), upper=rep(.2,nrow) ) . The function gives me 1e10 if my initial values for the parameters doesn't satisfy mean.65 and doesn't improve my initial conditions if they satisfy mean=.65. I know that a solution with mean.65 exists, I can find it by hand. -- View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4630278p4630419.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Optimization problem
Hi, I'm dealing with an optimization problem. I'm using 'optim' to maximize the output of a function, given some restrictions on the input. I would like to know if there is a way to impose some restrictions on 'intermediate variables' of the function. An example.. fx = function (x) { s - 0 for (i in 1:3) { s - x[i]^3 + s } s } optim(rep(4,3), method=L-BFGS-B, lower=rep(-10,nlin), upper=rep(10,nlin)) It would return '-10' for all variables. I want, however, a solution satisfying mean(x)7. Please, don't analyse this specific example, but the logic of satisfying a criterium for the mean of the input (with thousands of variables). My real problem involves price elasticity and I want to find the price increase for each individual that would give me maximum total profit margin, but respecting a minimum retention of clients. Thank you very much, John Mayer -- View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4630278.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ensuring a matrix to be positive definite, case involving three matrices
Hi, I would like to know what should I garantee about P and GGt in order to have F = Z %*% P %*% t(Z) + GGt always as a positive definite matrix. Being more precise: I am trying to find minimum likelihood parameters by using the function 'optim' to find the lowest value generated by $LogLik from the function 'fkf' (http://127.0.0.1:27262/library/FKF/html/fkf.html). The variable Kt within the algorithm used to generate the Kalman Filter equations needs in each iteration the inverse of the variable Ft, (Kt[,, i] = Pt[,, i] %*% t(Zt[,, i]) %*% solve(Ft[,, i])) which is updated by Ft[,, i] = Zt[,, i] %*% Pt[,, i] %*% t(Zt[,, i]) + GGt[,, i]. Zt is a constant 2x4 matrix and can't be changed. Gt (2x2) and P0 (4x4) are inputs for 'fkf'. Pt is updated in each iteration, starting with P0. GGt is constant and one of the parameters tested by 'optim' to minimize the LogLik (by the way, GGt is always positive definite). Except for the first parameters that I give to 'optim', I can't control its tested parameters, which will be used as the inputs of 'fkf' (except, as I sad, for Gt, because I ask 'optim' to give GLt, the lower triangular matrix of Gt, giving as input to 'fkf' GLt %*% t(GLt) ). Since the process stops every time a non positive matrix Ft appears, I would like to know if are there any transformations that could be applied to GGt and P0, given by 'optim', to be sure that Ft will be always positive definite. -- View this message in context: http://r.789695.n4.nabble.com/Ensuring-a-matrix-to-be-positive-definite-case-involving-three-matrices-tp4083376p4083376.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.