Optimization problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Optimization problem

nntx
As a simple example, I want to find minimum value for x^2, but it can't be obtained by:
f<-function(x)x^2
optimize(f,lower=-1,upper=1)

What are other methods to deal with this? I tried DEoptim, still doesn't work. Any suggustions will be extremely helpful! THanks!


Shelly
Reply | Threaded
Open this post in threaded view
|

Re: Optimization problem

Peter Dalgaard-2

On Apr 10, 2013, at 03:24 , nntx wrote:

> As a simple example, I want to find minimum value for x^2, but it can't be
> obtained by:
> f<-function(x)x^2
> optimize(f,lower=-1,upper=1)

Works fine for me. What did you expect it to do?

> f<-function(x)x^2
> optimize(f,lower=-1,upper=1)
$minimum
[1] -2.775558e-17

$objective
[1] 7.70372e-34

-pd

>
> What are other methods to deal with this? I tried DEoptim, still doesn't
> work. Any suggustions will be extremely helpful! THanks!
>
>
> Shelly
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4663821.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Optimization problem

nntx
Thank you professor. I think the minimum value of x^2 between -1 and 1 should be x=0, y=0. but the result is not that. I am thinking is any wrong with my thought?
Thanks for helping me out!
Reply | Threaded
Open this post in threaded view
|

Re: Optimization problem

Rui Barradas
Hello,

Your thoght is mathematically right but numerically wrong. The result
given by optimize is so close to the real minimum that numerical
accuracy comes in and it becomes indistinguishable from the value you're
expecting.
You get the minimum up to a certain accuracy, not more.

Hope this helps,

Rui Barradas

Em 10-04-2013 19:33, nntx escreveu:

> Thank you professor. I think the minimum value of x^2 between -1 and 1 should
> be x=0, y=0. but the result is not that. I am thinking is any wrong with my
> thought?
> Thanks for helping me out!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4663821p4663898.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Optimization problem

nntx
Rui, thanks for your reply. You meant that it is the issue of accuracy? So if I change the numerical accuracy, my results can be output? Thanks a lot!
Reply | Threaded
Open this post in threaded view
|

Re: Optimization problem

Rui Barradas
Hello,

You cannot change the numerical accuracy, it's a built-in constant. To
see it use

?.Machine
.Machine$double.eps  # smallest value different from zero


Actually, .Machine$double.eps is the "the smallest positive
floating-point number x such that 1 + x != 1"

You can try the following function

is.zero <- function(x, eps = .Machine$double.eps^0.5) abs(x) < eps

is.zero(your_value)  # TRUE?


Or even try ?all.equal

all.equal(your_value, 0)


Hope this helps,

Rui Barradas

Em 10-04-2013 22:13, nntx escreveu:

> Rui, thanks for your reply. You meant that it is the issue of accuracy? So if
> I change the numerical accuracy, my results can be output? Thanks a lot!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp4663821p4663928.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.