Re: [R] optimizing with non-linear constraints
Ravi Varadhanwrites: > Hi Rainer, > It is very simple to specify the constraints (linear or nonlinear) in > "alabama" . They are specified in a function called `hin', where the > constraints are written such that they are positive. OK - I somehow missed the part that, when the values x are valid, i.e. in the range as defined by the conditions, the result of hin(x) that they are all positive. > Your two nonlinear constraints would be written as follows: > > hin <- function(x, LAI) { > h <- rep(NA, 2) > h[1] <- LAI^x[2] / x[3] + x[1] > h[2] <- 1 - x[1] - LAI^x[2] / x[3] > h > } Makes perfect sense. > > Please take a look at the help page. If it is still not clear, you can > contact me offline. Yup - I did. But I somehow missed the fact stated above. I am using constrOptim() and constrOptim.nl() for a paper and am compiling a separate document which explains how to get the constraints for the two functions step by step - I will make it available as a blog post and a pdf. I might have further questions concerning the different fitting functions and which ones are the most appropriate in my case. Thanks a lot, Rainer > Best, > Ravi > > Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) > Associate Professor, Department of Oncology > Division of Biostatistics & Bionformatics > Sidney Kimmel Comprehensive Cancer Center > Johns Hopkins University > 550 N. Broadway, Suite -E > Baltimore, MD 21205 > 410-502-2619 > > > [[alternative HTML version deleted]] > -- Rainer M. Krug email: Rainerkrugsde PGP: 0x0F52F982 signature.asc Description: PGP signature __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] optimizing with non-linear constraints
I would recommend that you use auglag() rather than constrOptim.nl() in the package "alabama." It is a better algorithm, and it does not require feasible starting values. Best, Ravi -Original Message- From: Rainer M Krug [mailto:rai...@krugs.de] Sent: Thursday, October 01, 2015 3:37 AM To: Ravi VaradhanCc: 'r-help@r-project.org' Subject: Re: optimizing with non-linear constraints Ravi Varadhan writes: > Hi Rainer, > It is very simple to specify the constraints (linear or nonlinear) in > "alabama" . They are specified in a function called `hin', where the > constraints are written such that they are positive. OK - I somehow missed the part that, when the values x are valid, i.e. in the range as defined by the conditions, the result of hin(x) that they are all positive. > Your two nonlinear constraints would be written as follows: > > hin <- function(x, LAI) { > h <- rep(NA, 2) > h[1] <- LAI^x[2] / x[3] + x[1] > h[2] <- 1 - x[1] - LAI^x[2] / x[3] > h > } Makes perfect sense. > > Please take a look at the help page. If it is still not clear, you can > contact me offline. Yup - I did. But I somehow missed the fact stated above. I am using constrOptim() and constrOptim.nl() for a paper and am compiling a separate document which explains how to get the constraints for the two functions step by step - I will make it available as a blog post and a pdf. I might have further questions concerning the different fitting functions and which ones are the most appropriate in my case. Thanks a lot, Rainer > Best, > Ravi > > Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) > Associate Professor, Department of Oncology Division of Biostatistics > & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns > Hopkins University > 550 N. Broadway, Suite -E > Baltimore, MD 21205 > 410-502-2619 > > > [[alternative HTML version deleted]] > -- Rainer M. Krug email: Rainerkrugsde PGP: 0x0F52F982 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] optimizing with non-linear constraints
Envoyé de mon iPhone > Le 1 oct. 2015 à 15:17, Ravi Varadhana écrit : > > I would recommend that you use auglag() rather than constrOptim.nl() in the > package "alabama." It is a better algorithm, and it does not require > feasible starting values. Thanks - that was one question I wanted to ask later. I will do so, Rainer > Best, > Ravi > > -Original Message- > From: Rainer M Krug [mailto:rai...@krugs.de] > Sent: Thursday, October 01, 2015 3:37 AM > To: Ravi Varadhan > Cc: 'r-help@r-project.org' > Subject: Re: optimizing with non-linear constraints > > Ravi Varadhan writes: > >> Hi Rainer, >> It is very simple to specify the constraints (linear or nonlinear) in >> "alabama" . They are specified in a function called `hin', where the >> constraints are written such that they are positive. > > OK - I somehow missed the part that, when the values x are valid, i.e. in the > range as defined by the conditions, the result of hin(x) that they are all > positive. > >> Your two nonlinear constraints would be written as follows: >> >> hin <- function(x, LAI) { >> h <- rep(NA, 2) >> h[1] <- LAI^x[2] / x[3] + x[1] >> h[2] <- 1 - x[1] - LAI^x[2] / x[3] >> h >> } > > Makes perfect sense. > >> >> Please take a look at the help page. If it is still not clear, you can >> contact me offline. > > Yup - I did. But I somehow missed the fact stated above. > > I am using constrOptim() and constrOptim.nl() for a paper and am compiling a > separate document which explains how to get the constraints for the two > functions step by step - I will make it available as a blog post and a pdf. > > I might have further questions concerning the different fitting functions and > which ones are the most appropriate in my case. > > Thanks a lot, > > Rainer > > >> Best, >> Ravi >> >> Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) >> Associate Professor, Department of Oncology Division of Biostatistics >> & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns >> Hopkins University >> 550 N. Broadway, Suite -E >> Baltimore, MD 21205 >> 410-502-2619 >> >> >>[[alternative HTML version deleted]] >> > > -- > Rainer M. Krug > email: Rainerkrugsde > PGP: 0x0F52F982 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] optimizing with non-linear constraints
Hi I have posted the following question on stackoverflow [1] but haven't received a response yet. Has somebody here any idea, how to formulate non-linear constraints using e.g. the packages alabama or nlopr? The question is pasted below. I am really stuck with this. Thanks, Rainer , | I am successful in using constrOptim() for linear constraints (thanks to | a comment in my earlier question), but I now have a problem with | non-linear constraints. | | Consider the following example: | | I want to fit a function FUN(X1, X2, ... X12) | | X1 = dep.a | X2 = dep.b | X3 = dep.c | ... for all z0. , na. and zjoint. | | and have the following constraint | (link to formulas: | http://stackoverflow.com/questions/32845169/how-to-optimize-with-non-linear-constraints-in-r | ) | | | With some re-formating and h > 0 and LAI > 0 I get for thew first one | | -X1 <= LAI^X2 / X3 < 1 - X1 | | where LAI is simply a number which constant for each fit. | | I saw the packages alabama and nloptr but I don't manage to get my head | around how I can specify these types of constraints? | | Also a web search did not yield any helpful information for me. | | Could somebody provide some info how I can convert these constraints | into arguments for the fitting functions (e.g. hin, heq in the alabama | package)? ` Footnotes: [1] http://stackoverflow.com/questions/32845169/how-to-optimize-with-non-linear-constraints-in-r -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D):+49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug PGP: 0x0F52F982 signature.asc Description: PGP signature __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] optimizing with non-linear constraints
Hi Rainer, It is very simple to specify the constraints (linear or nonlinear) in "alabama" . They are specified in a function called `hin', where the constraints are written such that they are positive. Your two nonlinear constraints would be written as follows: hin <- function(x, LAI) { h <- rep(NA, 2) h[1] <- LAI^x[2] / x[3] + x[1] h[2] <- 1 - x[1] - LAI^x[2] / x[3] h } Please take a look at the help page. If it is still not clear, you can contact me offline. Best, Ravi Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg) Associate Professor, Department of Oncology Division of Biostatistics & Bionformatics Sidney Kimmel Comprehensive Cancer Center Johns Hopkins University 550 N. Broadway, Suite -E Baltimore, MD 21205 410-502-2619 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.