| Title: | Random Vector Functional Link Networks with glmnet Backend |
|---|---|
| Description: | Implements Random Vector Functional Link (RVFL) networks using glmnet for elastic-net regularized output layer training. Supports Gaussian, uniform, and Sobol random projections with various activation functions. |
| Authors: | T. Moudiki [aut, cre] |
| Maintainer: | T. Moudiki <[email protected]> |
| License: | GPL-2 |
| Version: | 0.1.0 |
| Built: | 2026-05-23 09:06:33 UTC |
| Source: | https://github.com/thierrymoudiki/rvflnet |
Apply scaling to new data
.apply_scaling(x, center, scale_vec).apply_scaling(x, center, scale_vec)
x |
input matrix |
center |
centering vector |
scale_vec |
scaling vector |
scaled matrix
Compute scaling parameters from data
.compute_scaling(x, scale_input = TRUE).compute_scaling(x, scale_input = TRUE)
x |
input matrix |
scale_input |
logical, whether to scale |
list with center and scale vectors
Internal helper for generating random projection matrix
.generate_random_weights(p, n_hidden, W_type, seed).generate_random_weights(p, n_hidden, W_type, seed)
p |
number of input features |
|
number of hidden units |
|
W_type |
type of random weights ("gaussian", "sobol", "uniform") |
seed |
random seed for reproducibility |
random weight matrix of dimension p x n_hidden
Internal helper for consistent preprocessing
.prepare_rvfl_data( x, W, center = NULL, scale_vec = NULL, scale_input = TRUE, activation, include_original = TRUE ).prepare_rvfl_data( x, W, center = NULL, scale_vec = NULL, scale_input = TRUE, activation, include_original = TRUE )
x |
input matrix |
W |
random weight matrix |
center |
centering vector (if NULL, compute from data) |
scale_vec |
scaling vector (if NULL, compute from data) |
scale_input |
logical, whether to scale inputs |
activation |
activation function |
include_original |
logical, whether to include original features |
list with Z (design matrix) and preprocessing parameters
Internal helper to build the RVFL design matrix.
.rvfl_features(x, W, center, scale_vec, activation).rvfl_features(x, W, center, scale_vec, activation)
x |
numeric matrix of predictors |
W |
random projection matrix |
center |
centering vector |
scale_vec |
scaling vector |
activation |
activation function name or custom function |
augmented design matrix cbind(x, hidden features)
Extract best lambda from CV object
best_lambda(model, which = c("min", "1se"))best_lambda(model, which = c("min", "1se"))
model |
cv.rvflnet object |
which |
which lambda to return ("min" or "1se") |
numeric lambda value
Extract coefficients from cross-validated RVFLNet model
## S3 method for class 'cv.rvflnet' coef(object, s = "lambda.min", ...)## S3 method for class 'cv.rvflnet' coef(object, s = "lambda.min", ...)
object |
cv.rvflnet object |
s |
lambda value ("lambda.min", "lambda.1se", or numeric) |
... |
additional arguments passed to coef.glmnet |
coefficient matrix. See coef.rvflnet for interpretation notes.
## Not run: coef(cv_model, s = "lambda.min") ## End(Not run)## Not run: coef(cv_model, s = "lambda.min") ## End(Not run)
Extract coefficients from RVFLNet model
## S3 method for class 'rvflnet' coef(object, s = NULL, ...)## S3 method for class 'rvflnet' coef(object, s = NULL, ...)
object |
rvflnet object |
s |
lambda value (passed to glmnet) |
... |
additional arguments passed to coef.glmnet |
coefficient matrix. NOTE: Coefficients apply to the augmented feature space [original features | random hidden features]. The first p coefficients correspond to original inputs, remaining n_hidden to random features. These are NOT directly interpretable as "feature importance" in the original input space due to the nonlinear random projection.
## Not run: coef(model, s = "lambda.min") ## End(Not run)## Not run: coef(model, s = "lambda.min") ## End(Not run)
Fits RVFL features then applies cv.glmnet.
cv.rvflnet( x, y, n_hidden = 200L, activation = c("sigmoid", "tanh", "relu", "identity"), W_type = c("gaussian", "uniform", "sobol"), seed = 1, scale = TRUE, include_original = TRUE, store_y = FALSE, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), ... )cv.rvflnet( x, y, n_hidden = 200L, activation = c("sigmoid", "tanh", "relu", "identity"), W_type = c("gaussian", "uniform", "sobol"), seed = 1, scale = TRUE, include_original = TRUE, store_y = FALSE, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), ... )
x |
design matrix |
y |
response vector |
|
number of hidden units |
|
activation |
activation function |
W_type |
random feature type ("gaussian", "uniform", "sobol") |
seed |
random seed |
scale |
logical scaling |
include_original |
logical, whether to include original features |
store_y |
logical, whether to store y in model |
family |
response type |
... |
additional arguments passed to glmnet::cv.glmnet |
object of class "cv.rvflnet"
## Not run: x <- matrix(rnorm(100*5), 100, 5) y <- x[,1] + sin(x[,2]) + rnorm(100, 0, 0.1) cv_model <- cv.rvflnet(x, y, n_hidden = 50, nfolds = 5) plot(cv_model) predict(cv_model, newx = x[1:10,]) ## End(Not run)## Not run: x <- matrix(rnorm(100*5), 100, 5) y <- x[,1] + sin(x[,2]) + rnorm(100, 0, 0.1) cv_model <- cv.rvflnet(x, y, n_hidden = 50, nfolds = 5) plot(cv_model) predict(cv_model, newx = x[1:10,]) ## End(Not run)
Extract fitted values from cross-validated RVFLNet model
## S3 method for class 'cv.rvflnet' fitted(object, s = "lambda.min", ...)## S3 method for class 'cv.rvflnet' fitted(object, s = "lambda.min", ...)
object |
cv.rvflnet object |
s |
lambda value |
... |
additional arguments |
fitted values
Extract fitted values from RVFLNet model
## S3 method for class 'rvflnet' fitted(object, s = NULL, ...)## S3 method for class 'rvflnet' fitted(object, s = NULL, ...)
object |
rvflnet object |
s |
lambda value |
... |
additional arguments |
fitted values
Extract activation function
get_activation(model)get_activation(model)
model |
rvflnet or cv.rvflnet object |
character
Extract weight type
get_weight_type(model)get_weight_type(model)
model |
rvflnet or cv.rvflnet object |
character
Check if object is a CV-RVFLNet model
is.cv.rvflnet(x)is.cv.rvflnet(x)
x |
object to check |
logical
Check if object is an RVFLNet model
is.rvflnet(x)is.rvflnet(x)
x |
object to check |
logical
Plot CV curve for RVFLNet
## S3 method for class 'cv.rvflnet' plot(x, ...)## S3 method for class 'cv.rvflnet' plot(x, ...)
x |
cv.rvflnet object |
... |
passed to plot.glmnet |
## Not run: plot(cv_model) ## End(Not run)## Not run: plot(cv_model) ## End(Not run)
Generic plot method for rvflnet objects
## S3 method for class 'rvflnet' plot(x, type = c("coef"), ...)## S3 method for class 'rvflnet' plot(x, type = c("coef"), ...)
x |
rvflnet object |
type |
type of plot ("coef" for coefficient path) |
... |
additional arguments passed to plot functions |
Predict method for cross-validated RVFLNet
## S3 method for class 'cv.rvflnet' predict(object, newx = NULL, s = "lambda.min", type = "response", ...)## S3 method for class 'cv.rvflnet' predict(object, newx = NULL, s = "lambda.min", type = "response", ...)
object |
cv.rvflnet model |
newx |
new data matrix (if NULL, returns fitted values if available) |
s |
lambda value ("lambda.min", "lambda.1se", or numeric) |
type |
type of prediction ("response", "coefficients", etc.) |
... |
additional arguments passed to predict.glmnet |
predictions
## Not run: predictions <- predict(cv_model, newx = x_test, s = "lambda.min") ## End(Not run)## Not run: predictions <- predict(cv_model, newx = x_test, s = "lambda.min") ## End(Not run)
Predict method for RVFLNet
## S3 method for class 'rvflnet' predict(object, newx = NULL, s = NULL, type = "response", ...)## S3 method for class 'rvflnet' predict(object, newx = NULL, s = NULL, type = "response", ...)
object |
rvflnet model |
newx |
new data matrix (if NULL, returns fitted values if available) |
s |
lambda value (passed to glmnet) |
type |
type of prediction ("response", "coefficients", etc.) |
... |
additional arguments passed to predict.glmnet |
predictions
## Not run: predictions <- predict(model, newx = x_test, s = "lambda.min") ## End(Not run)## Not run: predictions <- predict(model, newx = x_test, s = "lambda.min") ## End(Not run)
Print cross-validated RVFLNet model
## S3 method for class 'cv.rvflnet' print(x, ...)## S3 method for class 'cv.rvflnet' print(x, ...)
x |
cv.rvflnet object |
... |
ignored |
Print RVFLNet model
## S3 method for class 'rvflnet' print(x, ...)## S3 method for class 'rvflnet' print(x, ...)
x |
rvflnet object |
... |
ignored |
Residuals method for cross-validated RVFLNet
## S3 method for class 'cv.rvflnet' residuals(object, s = "lambda.min", type = "response", ...)## S3 method for class 'cv.rvflnet' residuals(object, s = "lambda.min", type = "response", ...)
object |
cv.rvflnet object |
s |
lambda value ("lambda.min", "lambda.1se", or numeric) |
type |
type of residuals |
... |
additional arguments |
residuals vector
Residuals method for RVFLNet
## S3 method for class 'rvflnet' residuals(object, s = NULL, type = "response", ...)## S3 method for class 'rvflnet' residuals(object, s = NULL, type = "response", ...)
object |
rvflnet object |
s |
lambda value |
type |
type of residuals ("response", "deviance", etc.) |
... |
additional arguments |
residuals vector
## Not run: model <- rvflnet(x, y, store_y = TRUE) residuals(model, s = "lambda.min") ## End(Not run)## Not run: model <- rvflnet(x, y, store_y = TRUE) residuals(model, s = "lambda.min") ## End(Not run)
Fits an RVFL model using glmnet on augmented random feature space.
rvflnet( x, y, n_hidden = 200L, activation = c("sigmoid", "tanh", "relu", "identity"), W_type = c("gaussian", "uniform", "sobol"), seed = 1, scale = TRUE, include_original = TRUE, store_y = FALSE, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), ... )rvflnet( x, y, n_hidden = 200L, activation = c("sigmoid", "tanh", "relu", "identity"), W_type = c("gaussian", "uniform", "sobol"), seed = 1, scale = TRUE, include_original = TRUE, store_y = FALSE, family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"), ... )
x |
design matrix |
y |
response vector |
|
number of random hidden units (must be > 0) |
|
activation |
activation function ("tanh", "relu", "sigmoid", "identity", or custom function) |
W_type |
type of random weights ("gaussian", "uniform", "sobol") |
seed |
random seed for reproducibility |
scale |
logical, whether to standardize inputs |
include_original |
logical, whether to include original features (default TRUE) |
store_y |
logical, whether to store y in model (for residuals, default FALSE) |
family |
response type ("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"). For family = "cox", y must be a Surv object from the survival package. |
... |
additional arguments passed to glmnet::glmnet |
object of class "rvflnet"
## Not run: x <- matrix(rnorm(100*5), 100, 5) y <- x[,1] + sin(x[,2]) + rnorm(100, 0, 0.1) model <- rvflnet(x, y, n_hidden = 50, activation = "tanh") predict(model, newx = x[1:10,]) coef(model) # Note: coefficients apply to [X | random features] space ## End(Not run)## Not run: x <- matrix(rnorm(100*5), 100, 5) y <- x[,1] + sin(x[,2]) + rnorm(100, 0, 0.1) model <- rvflnet(x, y, n_hidden = 50, activation = "tanh") predict(model, newx = x[1:10,]) coef(model) # Note: coefficients apply to [X | random features] space ## End(Not run)
Summary method for cross-validated RVFLNet
## S3 method for class 'cv.rvflnet' summary(object, s = "lambda.min", ...)## S3 method for class 'cv.rvflnet' summary(object, s = "lambda.min", ...)
object |
cv.rvflnet object |
s |
lambda value ("lambda.min" or "lambda.1se") |
... |
additional arguments |
invisible summary object
Summary method for RVFLNet
## S3 method for class 'rvflnet' summary(object, s = NULL, ...)## S3 method for class 'rvflnet' summary(object, s = NULL, ...)
object |
rvflnet object |
s |
lambda value |
... |
additional arguments |
invisible summary object