Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Ravi Varadhan
For those interested in esoteric of special functions, here is a nice
reference on the Lambert W function:

http://www.cs.uwaterloo.ca/research/tr/1993/03/W.pdf

Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Hans W Borchers
Sent: Wednesday, July 28, 2010 11:11 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] Optimization problem with nonlinear constraint

Uli Kleinwechter  uni-hohenheim.de> writes:

> 
> Dear Ravi,
> 
> As I've already written to you, the problem indeed is to find a solution 
> to the transcendental equation y = x * T^(x-1), given y and T and the 
> optimization problem below only a workaround.


I don't think optimization is the right approach for simply inverting
a simple function.

The inverse of the function  x \to x * e^x  is the Lambert W function.
So the solution in your case is:

W(log(T)*y*T) / log(T)  # hope I transformed it correctly.

Now, how to compute Lambert's W ? Well, look into the 'gsl' package
and, alas, there is the function lambert_W0.

Your example:

y <-   3
T <- 123

library(gsl)
lambert_W0(log(T)*y*T)/log(T)
# [1] 1.191830


Regards,  Hans Werner


> 
> John C. Nash has been so kind to help me on here. In case anyone faces a 
> similar problem in the future, the solution looks as follows:
> 
> *
> 
> func1 <- function(y,x,T){
>  out <- x*T^(x-1)-y
>  return(out)
> }
> 
> # Assign the known values to y and T:
> y <-   3
> T <- 123
> 
> root <- uniroot(func1,c(-10,100),y=y,T=T)
> print(root)
> 
> 
> 
> Somewhat simpler than I thought
> 
> Thanks again!
> 
> Uli
>

__
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-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.


Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Ravi Varadhan
Very nice, Hans!  I didn't know of the existence of Lambert W function
(a.k.a Omega function) before.  I didn't know that it occurs in the solution
of exponential decay with delay: dy/dy = a * y(t - 1).  Apparently it is
more than 250 years old!

Thanks,
Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Hans W Borchers
Sent: Wednesday, July 28, 2010 11:11 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] Optimization problem with nonlinear constraint

Uli Kleinwechter  uni-hohenheim.de> writes:

> 
> Dear Ravi,
> 
> As I've already written to you, the problem indeed is to find a solution 
> to the transcendental equation y = x * T^(x-1), given y and T and the 
> optimization problem below only a workaround.


I don't think optimization is the right approach for simply inverting
a simple function.

The inverse of the function  x \to x * e^x  is the Lambert W function.
So the solution in your case is:

W(log(T)*y*T) / log(T)  # hope I transformed it correctly.

Now, how to compute Lambert's W ? Well, look into the 'gsl' package
and, alas, there is the function lambert_W0.

Your example:

y <-   3
T <- 123

library(gsl)
lambert_W0(log(T)*y*T)/log(T)
# [1] 1.191830


Regards,  Hans Werner


> 
> John C. Nash has been so kind to help me on here. In case anyone faces a 
> similar problem in the future, the solution looks as follows:
> 
> *
> 
> func1 <- function(y,x,T){
>  out <- x*T^(x-1)-y
>  return(out)
> }
> 
> # Assign the known values to y and T:
> y <-   3
> T <- 123
> 
> root <- uniroot(func1,c(-10,100),y=y,T=T)
> print(root)
> 
> 
> 
> Somewhat simpler than I thought
> 
> Thanks again!
> 
> Uli
>

__
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-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.


Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Hans W Borchers
Uli Kleinwechter  uni-hohenheim.de> writes:

> 
> Dear Ravi,
> 
> As I've already written to you, the problem indeed is to find a solution 
> to the transcendental equation y = x * T^(x-1), given y and T and the 
> optimization problem below only a workaround.


I don't think optimization is the right approach for simply inverting
a simple function.

The inverse of the function  x \to x * e^x  is the Lambert W function.
So the solution in your case is:

W(log(T)*y*T) / log(T)  # hope I transformed it correctly.

Now, how to compute Lambert's W ? Well, look into the 'gsl' package
and, alas, there is the function lambert_W0.

Your example:

y <-   3
T <- 123

library(gsl)
lambert_W0(log(T)*y*T)/log(T)
# [1] 1.191830


Regards,  Hans Werner


> 
> John C. Nash has been so kind to help me on here. In case anyone faces a 
> similar problem in the future, the solution looks as follows:
> 
> *
> 
> func1 <- function(y,x,T){
>  out <- x*T^(x-1)-y
>  return(out)
> }
> 
> # Assign the known values to y and T:
> y <-   3
> T <- 123
> 
> root <- uniroot(func1,c(-10,100),y=y,T=T)
> print(root)
> 
> 
> 
> Somewhat simpler than I thought
> 
> Thanks again!
> 
> Uli
>

__
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.


Re: [R] Optimization problem with nonlinear constraint

2010-07-28 Thread Uli Kleinwechter

Dear Ravi,

As I've already written to you, the problem indeed is to find a solution 
to the transcendental equation y = x * T^(x-1), given y and T and the 
optimization problem below only a workaround.


John C. Nash has been so kind to help me on here. In case anyone faces a 
similar problem in the future, the solution looks as follows:


*

func1 <- function(y,x,T){
out <- x*T^(x-1)-y
return(out)
}

# Assign the known values to y and T:
y <-   3
T <- 123

root <- uniroot(func1,c(-10,100),y=y,T=T)
print(root)



Somewhat simpler than I thought

Thanks again!

Uli



Am 26.07.2010 17:44, schrieb Ravi Varadhan:

Hi Uli,

I am not sure if this is the problem that you really want to solve.  The
answer is the solution to the equation y = x * T^(x-1), provided a solution
exists.  There is no optimization involved here.  What is the real problem
that you are trying to solve?

If you want to solve a more meaningful constrained optimization problem, you
may want to try the "abalama" package which I just put on CRAN.  It can
optimize smooth nonlinear functions subject to linear and nonlinear equality
and inequality constraints.

http://cran.r-project.org/web/packages/alabama/index.html

Let me know if you run into any problems using it.

Best,
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Uli Kleinwechter
Sent: Monday, July 26, 2010 10:16 AM
To: r-help@r-project.org
Subject: [R] Optimization problem with nonlinear constraint

Dear all,

I'm looking for a way to solve a simple optimization problem with a
nonlinear constraint. An example would be

max x   s.t.   y = x * T ^(x-1)

where y and T are known values.

optim() and constrOptim() do only allow for box or linear constraints,
so I did not succedd here. I also found hints to donlp2 but this does
not seem to be available anymore.

Any hints are welcome,

Uli



__
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.


Re: [R] Optimization problem with nonlinear constraint

2010-07-26 Thread Ravi Varadhan
Hi Uli,

I am not sure if this is the problem that you really want to solve.  The
answer is the solution to the equation y = x * T^(x-1), provided a solution
exists.  There is no optimization involved here.  What is the real problem
that you are trying to solve?

If you want to solve a more meaningful constrained optimization problem, you
may want to try the "abalama" package which I just put on CRAN.  It can
optimize smooth nonlinear functions subject to linear and nonlinear equality
and inequality constraints.

http://cran.r-project.org/web/packages/alabama/index.html

Let me know if you run into any problems using it.

Best,
Ravi.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Uli Kleinwechter
Sent: Monday, July 26, 2010 10:16 AM
To: r-help@r-project.org
Subject: [R] Optimization problem with nonlinear constraint

Dear all,

I'm looking for a way to solve a simple optimization problem with a 
nonlinear constraint. An example would be

max x   s.t.   y = x * T ^(x-1)

where y and T are known values.

optim() and constrOptim() do only allow for box or linear constraints, 
so I did not succedd here. I also found hints to donlp2 but this does 
not seem to be available anymore.

Any hints are welcome,

Uli

-- 

Uli Kleinwechter
Agricultural and Food Policy Group (420a)
University of Hohenheim
D-70593 Stuttgart
E-mail: u.kleinwech...@uni-hohenheim.de

__
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-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.