Dear Morphometrics community,

I have been working on accelerating resistant fitting in R and would
like to share a preliminary benchmark comparing my implementation,
myrfit2() (attached), with the R package RPS: Resistant Procrustes
Superimposition (Pacheco G, Torcida S, Ferraggine V, Lotto F (2018).
RPS: Resistant Procrustes Superimposition. DOI:
10.32614/CRAN.package.RPS. R package version 1.0.1.).
Although resistant fitting is rarely used in practical applications
(for a **good** number of statistical and differential-geometry
reasons that I will not list here), it remains a classic pedagogical
example of the different approaches available in modern shape
analysis. Making it feasible to apply to large datasets could
therefore be a useful option.
I developed myrfit2() by moving computationally intensive operations
into C++ using Rcpp. The implementation is self-contained in a single
R source file: the C++ kernels are compiled automatically at the first
function call and cached for reuse within the same R session. This
avoids the need for a separately compiled package and prevents
compilation overhead from recurring on subsequent calls.
The code requires the Rcpp package and, if not already available, the
appropriate build tools (Rtools on Windows). To use it, simply copy
and paste the code into the R console.

Preliminary benchmark
All benchmarks were run on a PC with 13th Gen Intel(R) Core(TM)
i9-13900HX, 63,7 GB of RAM, running Microsoft Windows 11 Pro, using R
version 4.5.2 (2025-10-31 ucrt).
On my system, using the same input array, with dimensions [1:20, 1:3,
1:10], I obtained the following elapsed times:
RPS (robgit_RPS): 12.39 seconds
myrfit2(): 0.06 seconds
This corresponds to an approximately 207-fold speed-up, or about 99.5%
less elapsed time, for this particular test.
In a separate test involving an array dim = c(400, 3, 400) it tooks 65 sec.
RPS freezes on this dataset.
These results are preliminary and depend on the hardware and dataset.
More extensive benchmarking, with repeated runs and matched
algorithmic settings, would be needed to establish how the speed-up
scales with dataset size and to ensure that the compared procedures
perform equivalent computational tasks.

A typical use:

arru <- array(rnorm(20 * 3 * 10), dim = c(20, 3, 10))
system.time(provarps<-RPS::robgit_RPS(arru[1:20,1:3,1:10]))
system.time(provamyrfit2<-myrfit2(arru[1:20,1:3,1:10]))
range(provarps-provamyrfit2)


Role of AI assistance
I **of course** used ChatGPT as an assistant during development,
particularly for translating computational bottlenecks into C++ and
integrating Rcpp. The process turned out to be considerably more
laborious than expected from my initial prompt. Nevertheless, given my
limited Rcpp programming skills, I doubt I could have achieved this
result without AI assistance.
I would welcome feedback from the community on the implementation
strategy, potential further optimizations, and appropriate
benchmarking practices.

Best regards
Paolo Piras

-- 
You received this message because you are subscribed to the Google Groups 
"Morphmet" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/morphmet2/CAAdPgfPOuwec-B0DzuP%2Bg-VF%3DkjcJr-652y01ecKUzcPpWX52Q%40mail.gmail.com.

Attachment: myrfit2.r
Description: Binary data

Reply via email to