samQL: Training function of Sparse Additive Regression with...

View source: R/samQL.R

samQLR Documentation

Training function of Sparse Additive Regression with Quadratic Loss

Description

Fit a sparse additive regression model with quadratic loss.

Usage

samQL(
  X,
  y,
  p = 3,
  lambda = NULL,
  nlambda = NULL,
  lambda.min.ratio = 0.005,
  thol = 1e-05,
  max.ite = 1e+05,
  regfunc = "L1",
  dfmax = NULL,
  verbose = FALSE,
  dev.ratio.thr = NULL,
  dev.change.thr = NULL,
  solver = c("actnewton", "actgd"),
  type.gaussian = c("naive", "covariance", "auto")
)

Arguments

X

Numeric training matrix with n rows (samples) and d columns (features).

y

Numeric response vector of length n.

p

The number of basis spline functions. The default value is 3.

lambda

Optional user-supplied regularization sequence. If provided, use a decreasing sequence; warm starts are used along the path and are usually much faster than fitting a single value.

nlambda

The number of lambda values. The default value is 30.

lambda.min.ratio

Smallest lambda as a fraction of lambda.max (the smallest value that keeps all component functions at zero). The default is 5e-3.

thol

Stopping tolerance. The default value is 1e-5.

max.ite

Maximum number of iterations. The default value is 1e5.

regfunc

A string indicating the regularizer. The default value is "L1". You can also assign "MCP" or "SCAD" to it.

dfmax

Maximum number of non-zero groups allowed. When the number of non-zero groups reaches dfmax, the regularization path is terminated early. NULL (default) means no limit.

verbose

Logical; if TRUE, print iteration info for each lambda.

dev.ratio.thr

Deviance ratio threshold for early stopping. When the deviance ratio 1 - D(\lambda)/D_0 exceeds this value the regularization path is terminated early. NULL (default) disables this criterion.

dev.change.thr

Relative deviance change threshold for early stopping. When the relative change in deviance over the last few lambda steps falls below this value, the path is terminated. NULL (default) disables this criterion.

solver

Which solver to use: "actnewton" (default, active-set Newton) or "actgd" (group active gradient descent with strong rule screening). "actgd" only supports L1 regularization and is automatically replaced by "actnewton" when regfunc is "MCP" or "SCAD".

type.gaussian

Which internal update strategy to use: "naive" (default) maintains an n-dimensional residual vector, "covariance" precomputes the Gram matrix and updates gradients incrementally. "covariance" is faster when d * p < n and is silently ignored (falls back to "naive") otherwise. "auto" selects automatically based on d * p < n.

Details

The solver combines block coordinate descent, fast iterative soft-thresholding, and Newton updates. Computation is accelerated by warm starts and active-set screening.

Value

p

The number of basis spline functions used in training.

X.min

Per-feature minimums from training data (used to rescale test data).

X.ran

Per-feature ranges from training data (used to rescale test data).

lambda

Sequence of regularization parameters used in training.

w

Solution path matrix with size d*p by length(lambda); each column corresponds to one regularization parameter.

intercept

The solution path of the intercept.

df

Degrees of freedom along the solution path (number of non-zero component functions).

knots

The p-1 by d matrix. Each column contains the knots applied to the corresponding variable.

Boundary.knots

The 2 by d matrix. Each column contains the boundary points applied to the corresponding variable.

func_norm

Functional norm matrix (d by length(lambda)); each column corresponds to one regularization parameter.

sse

Sums of square errors of the solution path.

See Also

SAM,plot.samQL,print.samQL,predict.samQL

Examples


## generating training data
n = 100
d = 500
X = 0.5*matrix(runif(n*d),n,d) + matrix(rep(0.5*runif(n),d),n,d)

## generating response
y = -2*sin(X[,1]) + X[,2]^2-1/3 + X[,3]-1/2 + exp(-X[,4])+exp(-1)-1

## Training
out.trn = samQL(X,y)
out.trn

## plotting solution path
plot(out.trn)

## generating testing data
nt = 1000
Xt = 0.5*matrix(runif(nt*d),nt,d) + matrix(rep(0.5*runif(nt),d),nt,d)

yt = -2*sin(Xt[,1]) + Xt[,2]^2-1/3 + Xt[,3]-1/2 + exp(-Xt[,4])+exp(-1)-1

## predicting response
out.tst = predict(out.trn,Xt)

SAM documentation built on March 13, 2026, 9:08 a.m.