Skip to content
Prev 277063 / 398506 Next

performance of adaptIntegrate vs. integrate

baptiste auguie <baptiste.auguie <at> googlemail.com> writes:
Cubature is astonishingly slow here though it was robust and accurate in
most cases I used it. You may write to the maintainer for more information.

Even a pure R implementation of adaptive Gauss-Kronrod as in pracma::quadgk
is faster than cubature:

    library(pracma)
    time3 <- system.time(replicate(1e3, 
      { d <<- quadgk(integrand, -1, 1) }        # 0.0177240954011303
    ) )
    #  user  system  elapsed 
    # 0.899   0.002    0.897

If your functions are somehow similar and you are willing to dispense with
the adaptive part, then compute Gaussian quadrature nodes xi and weights wi
for the fixed interval and compute sum(wi * fj(xi)) for each function fj.
This avoids recomputing nodes and weights for every call or function.

Package 'gaussquad' provides such nodes and weights. Or copy the relevant
calculations from quadgk (the usual (7,15)-rule).

Regards, Hans Werner