I'd generally echo Ben's suggestions.
In particular, it is likely useful to time sections of objective calculation
with
microbenchmark. My experience is that only some sections of objective are
critical,
so only parts need be coded outside R. Sometimes changing to different R code
can
be enough. Ben didn't mention Fortran. Now getting old-fashioned, but it can
be
very fast for some operations, but be careful to count the call and return i.e.,
time outside the replaced objective code, not just inside the sub-programs.
About 10 years ago managed to get better than 10* speedup with approach
replacing
"bits and pieces"
Cheers, JN
On 2025-12-29 14:42, Ben Bolker wrote:> In my experience statistical fitting problems are more typically
> compute-bound (CPU) rather than memory-bound; again, speaking only from my
> experience, having too *little* memory will cause severe problems, but
> having more memory than necessary doesn't help.
>
> Usually the work has to go into speeding up the objective function:
>
> providing gradients of the objective function (either analytically or by
> autodiff) can make a huge difference (e.g. see the RTMB package ... [R]TMB
> are heavily used in fisheries, FWIW)
> you might be able to parallelize the objective-function computations.
> Parallelized optimization algorithms do exist (e.g. Kyle and Neira 2014),
> but I don't know if anyone has implemented them in R ...
> translating objective functions into C++ etc. (possibly with threaded
> computation using OpenMP)
>
> Klein, Kyle, and Julian Neira. 2014. ?Nelder-Mead Simplex Optimization
> Routine for Large-Scale Problems: A Distributed Memory
> Implementation.? *Computational
> Economics* 43 (4): 447?61. https://doi.org/10.1007/s10614-013-9377-8.
>
> I'm not sure those address your problem, but that's my best guess
based on
> what you've told us
>
> On Fri, Dec 26, 2025 at 5:01?AM Ruben Roa Ureta via R-help <
> r-help at r-project.org> wrote:
>
>> Dear R experts.
>>
>> I am running customized versions of nonlinear models in my package
CatDyn.
>> These are models with 140 parameters to estimate and composite
likelihoods
>> made of mixtures of adjusted profile normal, adjusted profile
lognormal,
>> and a robust version of the lognormal.
>> There are 3^6 composite likelihoods, because of 3 core likelihoods and
6
>> agents acting to produce the data for the model, each one having one of
the
>> 3 likelihoods.
>> The numerical methods I'm using are CG and spg, as these worked the
best
>> for these models in other, smaller optimization problems within the
same
>> set of models in CatDyn.
>>
>> My motivation for this message is that the optimization is taking days
for
>> each of the 3^6 composite likelihoods on an Ubuntu 24.04 AMD Ryzen? 7
8700G
>> w/ Radeon? 780M Graphics?16 with 128 GB RAM.
>> I was expecting much faster optimization with 128 GB RAM.
>>
>> Some of you may have experience in running large nonlinear optimization
>> problems in R.
>> Is there any advice on how to speed up these rather large-ish
optimization
>> problems in R?
>> Either software, hardware, or both?
>>
>> I apologize in advance if you consider this not a proper question for
the
>> mail list.
>>
>> Ruben
>> ---
>> Ruben H. Roa-Ureta, Ph. D.
>> Consultant in Statistical Modeling
>> ORCID ID 0000-0002-9620-5224
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> https://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.