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

Reply via email to