profile_nonlinear: Profile nonlinear mixed-model operations

View source: R/FUN_nonlinear_profile.R

profile_nonlinearR Documentation

Profile nonlinear mixed-model operations

Description

Reuses fitted-model contexts to time separate predictor, derivative, conditional-curvature, objective, score and prediction operations for native nonlinear and reference specification fits. Does not refit or mutate the supplied model.

Usage

profile_nonlinear(object, replications=3L, control=NULL, inference=FALSE)

Arguments

object

A fitted native nonlinear or reference specification mmes model.

replications

Positive integer number of timed repetitions after one warmup.

control

Optional mmes_control() providing the profiling memory budget and, when requested, post-fit inference settings. Other fitted numerical choices remain unchanged.

inference

Whether to explicitly profile post-fit uncertainty as well. Defaults to FALSE; profiling never implicitly computes PEV.

Details

Use mmes_control(diagnostics=list(profile="force")) at fitting time to retain preparation, outer-optimization and result-construction elapsed seconds. Marginal evaluation time is included in outer optimization and must not be added again. Default fitting retains no timing profile.

The profiling table measures curve means, curve Jacobians, exact conditional curvature at the saved latent mode, the marginal objective (including mode search), the marginal objective with its analytic score, and conditional prediction. These operation timings are inclusive, overlapping and not additive. The difference between objective and score timings can indicate derivative cost, but timer resolution and run-to-run variation limit that comparison. Context reconstruction is timed separately. Whole-optimizer timing and iteration/evaluation counts come from the fit, not a second fit. No automatic inference or stochastic starts are introduced.

For reference specification fits, the table instead measures the saved predictor, its numerical Jacobian, conditional curvature when random coordinates are present, the objective, its numerical score and prediction. The saved reference likelihood context is reused without an outer refit. Objective and score evaluations may optimize conditional modes as required by the likelihood. Reference evaluation does not expose native cumulative-work counters; its context reconstruction time is zero because no reconstruction is performed.

Reported memory consists of retained R object sizes and the actual workspace admission policy, not measured native peak resident memory. Before nonlinear Hessian assembly a sparse-support graph bounds dense fill separately within each connected random component, including cross-category curvature edges. This bound scales linearly for independent groups but can be conservative for a large connected sparse relationship graph. The estimated workspace is

8(180n+80q+12\,nnz(Z)+8\,nnz(Q)+8\,nnz(C)) +64\sum_j q_j^2

bytes, with predictor rows n, latent coordinates q, prior precision Q, observation curvature C, and component sizes q_j. Admission occurs before sparse Hessian products/factorization. For random curves the support includes both additive and curve incidence, even when a curve derivative is zero. This is a conservative operation-local bound, not an operating-system cap or an exact symbolic-fill estimate. Existing score-panel, reduced-rank, prediction, quadrature and post-fit dense workspace checks also apply. No full observation or random design is densified to evaluate the curve.

Value

A serializable list with table, context reconstruction time, fit-time profile (if requested when fitting), dimensions, cumulative native work counters, optimizer/initialization diagnostics, memory information and R/platform/BLAS metadata. Timings are seconds; fitBytes and sparseDesignBytes are bytes. Very short operations can time as zero.

See Also

nonlinear_curve, post_nonlinear, mmes_control

Examples

## Not run: 
fit <- mmes(y~0+curve_term("growth"), random=~group, data=dat,
  curves=list(growth=nonlinear_curve("x")),
  method=mmes_method(objective="ml"),
  control=mmes_control(
    diagnostics=list(profile="force")))
profile_nonlinear(fit)

## End(Not run)

sommer documentation built on Nov. 14, 2026, 5:07 p.m.