| Title: | Tensor Regression with Stochastic Low-Rank Updates |
|---|---|
| Description: | Provides methods for low-rank tensor regression with tensor-valued predictors and scalar covariates. Model estimation is performed using stochastic optimization with random-walk updates for low-rank factor matrices. Computationally intensive components for coefficient estimation and prediction are implemented in C++ via 'Rcpp'. The package also includes tools for cross-validation and prediction error assessment. |
| Authors: | Ritwick Mondal [aut, cre] |
| Maintainer: | Ritwick Mondal <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-12 08:22:14 UTC |
| Source: | https://github.com/cran/TensorMCMC |
Simple rank comparison via in-sample RMSE
cv.tensor.reg(x.train, z.train, y.train, ranks = 1:3, nsweep = 50)cv.tensor.reg(x.train, z.train, y.train, ranks = 1:3, nsweep = 50)
x.train |
Training tensor X data. |
z.train |
Training scalar covariates. |
y.train |
Training response vector. |
ranks |
Vector of rank values to test. |
nsweep |
Number of stochastic update iterations. |
A data.frame with ranks and corresponding in-sample RMSE.
posterior mean for tensor regression
getmean(X, beta, rank, rank.exclude = NULL)getmean(X, beta, rank, rank.exclude = NULL)
X |
Input tensor. |
beta |
Estimated coefficient tensor. |
rank |
Rank used in tensor decomposition. |
rank.exclude |
Optional rank values to exclude. |
Mean tensor.
This function calls 'getmean_cpp' to compute the posterior mean from tensor X and beta list.
getmean_cpp(X_vec, beta, n, p, d, rank)getmean_cpp(X_vec, beta, n, p, d, rank)
X_vec |
Flattened tensor (numeric vector of length n*p*d) |
beta |
List of p×d matrices (length = rank) |
n |
Number of observations |
p |
Number of rows in each beta matrix |
d |
Number of columns in each beta matrix |
rank |
Rank of tensor decomposition |
Numeric vector of length n
This function calls the underlying C++ function 'predict_tensor_cpp' to compute predicted responses given a flattened tensor, low-rank coefficient matrices, and scalar covariate coefficients.
predict_tensor_cpp(X_vec, beta, gam, n, p, d, rank)predict_tensor_cpp(X_vec, beta, gam, n, p, d, rank)
X_vec |
Flattened tensor (numeric vector of length n*p*d) |
beta |
List of p×d matrices representing tensor coefficients |
gam |
Numeric vector of scalar coefficients |
n |
Number of observations |
p |
Number of rows in each beta matrix |
d |
Number of columns in each beta matrix |
rank |
Rank of tensor decomposition |
Numeric vector of length n
Predict tensor regression (wrapper)
predict_tensor_reg(fit, x.new, z.new, scale = TRUE)predict_tensor_reg(fit, x.new, z.new, scale = TRUE)
fit |
tensor.reg object |
x.new |
new tensor predictors |
z.new |
new scalar covariates |
scale |
Logical; whether to scale predictors |
Predicted response vector
Prediction from tensor regression (S3 method)
## S3 method for class 'tensor.reg' predict(object, x.new, z.new, scale = TRUE, ...)## S3 method for class 'tensor.reg' predict(object, x.new, z.new, scale = TRUE, ...)
object |
tensor.reg object |
x.new |
new tensor predictors (n x p x d) |
z.new |
new scalar covariates (n x pgamma) |
scale |
Logical; whether to scale predictors |
... |
additional arguments |
Predicted response vector
Inverse-gamma random number generator
rigamma(n, shape, rate)rigamma(n, shape, rate)
n |
Number of samples. |
shape |
Shape parameter of the gamma distribution. |
rate |
Rate parameter of the gamma distribution. |
A numeric vector of inverse-gamma samples.
root-mean-square error (RMSE)
rmse(a, b)rmse(a, b)
a |
Predicted values. |
b |
True observed values. |
RMSE value.
Low-rank tensor regression with stochastic updates
tensor.reg( z.train, x.train, y.train, nsweep = 50, rank = 2, scale = TRUE, alpha.lasso = 1 )tensor.reg( z.train, x.train, y.train, nsweep = 50, rank = 2, scale = TRUE, alpha.lasso = 1 )
z.train |
Matrix of scalar covariates (n x pgamma) |
x.train |
3D array of tensor predictors (n x p x d) |
y.train |
Response vector (length n) |
nsweep |
Number of stochastic update iterations (default 50) |
rank |
Rank of tensor decomposition (default 2) |
scale |
whether to scale predictors and response (default TRUE) |
alpha.lasso |
LASSO tuning parameter for initial estimate (default 1) |
A list with beta.store, gam.store, rank, p, d, and scaling info
This function calls the C++ function 'update_beta_cpp' to perturb beta matrices.
update_beta_cpp(beta, p, d, rank, sigma)update_beta_cpp(beta, p, d, rank, sigma)
beta |
List of p×d matrices (length = rank) |
p |
Number of rows in each beta matrix |
d |
Number of columns in each beta matrix |
rank |
Rank of tensor decomposition |
sigma |
Standard deviation of Gaussian noise |
Updated list of beta matrices