runSA: Stochastic approximation for parameter fitting

View source: R/runSA.R

runSAR Documentation

Stochastic approximation for parameter fitting

Description

Estimate species interaction parameters and (optionally) environmental preference parameters by stochastic approximation (SA). The function runs multiple SA optimizations in parallel (when threads > 1) using foreach.

Usage

runSA(
  ocmat,
  enmat = NULL,
  rep = 128,
  threads = 1,
  we = 0.001,
  totalit = 1000,
  lambda = 0.01,
  intv = 100,
  runadamW = TRUE,
  maxlr = 0.005,
  sparse = TRUE,
  getall = FALSE,
  reporting = TRUE
)

Arguments

ocmat

Numeric matrix (0/1). Rows are samples and columns are species.

enmat

Optional numeric matrix. Environmental variables for each sample. Should be normalized/standardized beforehand.

rep

Integer. Number of parallel runs (replicates) for optimization.

threads

Integer. Number of cores used when running in parallel.

we

Numeric. Weight decay parameter for AdamW.

totalit

Integer. Total number of optimization iterations.

lambda

Numeric. Sparsity penalty parameter (used when sparse = TRUE).

intv

Integer. Interval of iterations at which intermediate results are recorded.

runadamW

Logical. If TRUE, use AdamW-style optimization.

maxlr

Numeric. Maximum learning rate.

sparse

Logical. If TRUE, apply sparsity constraint.

getall

Logical. If TRUE, return all replicate trajectories.

reporting

Logical. If TRUE, print progress messages.

Value

If getall = TRUE, a list of SA trajectories (length rep). Otherwise, a list with two elements, c(params, enmat) is returned. params is the concatenated matrix of the estimated parameter set:

h

Implicit environmental effects on species occurrence

J

Species-species interaction matrix

g

(If enmat is not NULL) Explicit effects of the environmental factors.


ELAplus documentation built on May 28, 2026, 5:09 p.m.