Re: [R] Calling optim and .C

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Thu, 06 Nov 2008 15:05:56 +1300

On 6/11/2008, at 11:39 AM, Armin Meier wrote:

> Hi all,
> I want to optimize a function fn using optim. This function fn calls
> the .C function in it with a function name and arguments given to fn,
> i.e. something like this pseudocode:
>
> fn <- function(par, "some params for fn") {... .C
> ("Cfunction", ...) ...}
> optim(par, fn, "some params for fn")
>
> In my case this doesn't work, but is it possible in general and I made
> some error?

Yes it is possible in general, so you've goofed somewhere in your code. Join the club.

The optim() function doesn't care how ``fn'' does its calculations as long
as it does them and doesn't crash. In particular it doesn't care whether
``fn'' calls .C() to do all or part of those computations.

If ``fn'' works on its own (i.e. when not called by optim()) then it would
seem that the problem is not with your call to .C() but with the syntax of
your call to optim().

Remember that the ... arguments must be given in the name=value form.

Remember that optim() usually doesn't like it if fn() returns Inf or NA or NaN.

That's about all I can come up with in the way of ideas. Good luck.

        cheers,

                Rolf Turner

P. S. ``... this doesn't work ...'' is too vague to be useful. In what way
doesn't it work? What sort of error do you get? If you give the information
that the Posting Guide calls for, you may get a more helpful answer.

                R. T.

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

R-help_at_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. Received on Thu 06 Nov 2008 - 02:08:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 06 Nov 2008 - 11:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive