[R] optimization problem in R ... can this be done?
Spencer Graves
spencer.graves at pdf.com
Sat Jun 25 20:16:11 CEST 2005
Part of the R culture is a statement by Simon Blomberg immortalized
in library(fortunes) as, "This is R. There is no if. Only how."
I can't see now how I would automate a complete solution to your
problem in general. However, given a specific g(x, n), I would start by
writing a function to use "expand.grid" and "contour" to make a contour
plot of g(x, n) over specified ranges for x = seq(0, x.max, length=npts)
and n = seq(0, n.max, npts) for a specified number of points npts. Then
I'd play with x.max, n.max, and npts until I got what I wanted. With
the right choices for x.max, n.max, and npts, the solution will be
obvious from the plot. In some cases, nothing more will be required.
If I wanted more than that, I would need to exploit further some
specifics of the problem. For that, permit me to restate some of what I
think I understood of your specific problem:
(1) For fixed n, g(x, n) is monotonically decreasing in x>0.
(2) For fixed x, g(x, n) has only two local maxima, one at n=0 (or
n=eps>0, esp arbitrarily small) and the other at n2(x), say, with a
local minimum in between at n1(x), say.
With this, I would write functions to find n1(x) and n2(x) given x.
I might not even need n1(x) if I could figure out how to obtain n2(x)
without it. Then I'd make a plot with two lines (using "plot" and
"lines") of g(x, 0) and g(x, n2(x)) vs. x.
By the time I'd done all that, if I still needed more, I'd probably
have ideas about what else to do.
hope this helps.
spencer graves
Gregory Gentlemen wrote:
> Im trying to ascertain whether or not the facilities of R are sufficient for solving an optimization problem I've come accross. Because of my limited experience with R, I would greatly appreciate some feedback from more frequent users.
> The problem can be delineated as such:
>
> A utility function, we shall call g is a function of x, n ... g(x,n). g has the properties: n > 0, x lies on the real line. g may take values along the real line. g is such that g(x,n)=g(-x,n). g is a decreasing function of x for any n; for fixed x, g(x,n) is smooth and intially decreases upon reaching an inflection point, thereafter increasing until it reaches a maxima and then declinces (neither concave nor convex).
>
> My optimization problem is to find the largest positive x such that g(x,n) is less than zero for all n. In fact, because of the symmetry of g around x, we need only consider x > 0. Such an x does exists in this problem, and of course g obtains a maximum value of 0 at some n for this value of x. my issue is writing some code to systematically obtain this value.
>
> Is R capable of handling such a problem? (i.e. through some sort of optimization fucntion, or some sort of grid search with the relevant constraints)
>
> Any suggestions would be appreciated.
>
> Gregory Gentlemen
> gregory_gentlemen at yahoo.ca
>
>
>
> The following is a sketch of an optimization problem I need to solve.
>
> __________________________________________________
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list