| Title: | Kolmogorov-Arnold Fourier Networks in R |
|---|---|
| Description: | Provides an R implementation of Kolmogorov-Arnold Fourier Networks using the torch backend. The package supports regression, binary classification, multiclass classification, formula and matrix interfaces, mini-batch training, validation splits, early stopping, standardization, best-model restoration, and KAF-specific diagnostics. |
| Authors: | Guillaume Sidoine [aut, cre] |
| Maintainer: | Guillaume Sidoine <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-29 10:45:51 UTC |
| Source: | https://github.com/gsidoine/rkaf |
Extracts the trainable Random Fourier Feature weights and biases from a KAF model.
extract_fourier_params(object, layer = NULL)extract_fourier_params(object, layer = NULL)
object |
A fitted object returned by |
layer |
Optional integer. If supplied, only extract parameters from this layer. |
A data frame with Fourier weights and biases.
Extracts the learned GELU/base and Fourier branch scales from each KAF layer.
extract_kaf_scales(object)extract_kaf_scales(object)
object |
A fitted object returned by |
A data frame with one row per layer-feature pair.
Convenience wrapper around nn_kaf() using a more user-facing API.
kaf( input_dim, output_dim = 1, hidden = c(64, 64), num_grids = 16, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )kaf( input_dim, output_dim = 1, hidden = c(64, 64), num_grids = 16, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )
input_dim |
Integer. Number of input features. |
output_dim |
Integer. Number of output dimensions. |
|
Integer vector. Hidden layer sizes. |
|
num_grids |
Integer. Number of Fourier frequencies per KAF layer. |
dropout |
Numeric. Dropout probability. |
use_layernorm |
Logical. Whether to apply layer normalization. |
activation_expectation |
Numeric. Scaling constant for Fourier initialization. |
fourier_init_scale |
Numeric. Initial scale of the Fourier branch. |
A torch KAF network.
Fits a KAF model for regression using mean squared error loss.
kaf_fit( x, y, task = c("auto", "regression", "binary", "multiclass"), hidden = c(64, 64), num_grids = 16, dropout = 0, use_layernorm = TRUE, fourier_init_scale = 0.01, epochs = 1000, lr = 0.001, batch_size = NULL, shuffle = TRUE, validation_split = 0, x_val = NULL, y_val = NULL, weight_decay = 0, standardize_x = TRUE, standardize_y = NULL, patience = NULL, verbose = TRUE, print_every = 100, seed = NULL, restore_best = TRUE, min_delta = 0 )kaf_fit( x, y, task = c("auto", "regression", "binary", "multiclass"), hidden = c(64, 64), num_grids = 16, dropout = 0, use_layernorm = TRUE, fourier_init_scale = 0.01, epochs = 1000, lr = 0.001, batch_size = NULL, shuffle = TRUE, validation_split = 0, x_val = NULL, y_val = NULL, weight_decay = 0, standardize_x = TRUE, standardize_y = NULL, patience = NULL, verbose = TRUE, print_every = 100, seed = NULL, restore_best = TRUE, min_delta = 0 )
x |
Matrix, data frame, vector, or 2D torch tensor of predictors. |
y |
Vector, matrix, data frame, or torch tensor of targets. |
task |
Character. One of |
|
Integer vector. Hidden layer sizes. |
|
num_grids |
Integer. Number of Fourier frequencies per KAF layer. |
dropout |
Numeric. Dropout probability. |
use_layernorm |
Logical. Whether to apply layer normalization. |
fourier_init_scale |
Numeric. Initial scale of the Fourier branch. |
epochs |
Integer. Maximum number of training epochs. |
lr |
Numeric. Learning rate. |
batch_size |
Optional integer. Mini-batch size. If |
shuffle |
Logical. Whether to shuffle training rows each epoch. |
validation_split |
Numeric in |
x_val |
Optional validation predictors. |
y_val |
Optional validation targets. |
weight_decay |
Numeric. Adam weight decay. |
standardize_x |
Logical. Whether to standardize predictors using the training-set mean and standard deviation. |
standardize_y |
Logical or |
patience |
Optional integer. Number of epochs without improvement before early stopping. |
verbose |
Logical. Whether to print progress. |
print_every |
Integer. Print frequency. |
seed |
Optional integer random seed. |
restore_best |
Logical. Whether to restore the best observed model state after training. |
min_delta |
Numeric. Minimum loss improvement required to update the best model state. |
An object of class "kaf_fit".
Fits a Kolmogorov-Arnold Fourier Network using a formula and data frame.
This is a convenience wrapper around kaf_fit() for regression tasks.
kaf_fit_formula( formula, data, include_intercept = FALSE, na.action = stats::na.omit, ... )kaf_fit_formula( formula, data, include_intercept = FALSE, na.action = stats::na.omit, ... )
formula |
A model formula, such as |
data |
A data frame. |
include_intercept |
Logical. Whether to keep the model-matrix intercept
column. Defaults to |
na.action |
Missing-value handling function passed to |
... |
Additional arguments passed to |
An object of class "kaf_fit".
Torch module implementing a stacked Kolmogorov-Arnold Fourier Network.
nn_kaf( layers, num_grids = 8, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )nn_kaf( layers, num_grids = 8, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )
layers |
Integer vector. Network architecture, including input and
output dimensions. For example, |
num_grids |
Integer. Number of Fourier frequencies per KAF layer. |
dropout |
Numeric. Dropout probability. |
use_layernorm |
Logical. Whether to apply layer normalization before the Fourier feature block. |
activation_expectation |
Numeric. Scaling constant for Fourier initialization. |
fourier_init_scale |
Numeric. Initial scale of the Fourier component. |
A torch nn_module.
Torch module implementing one KAF layer using a hybrid GELU and trainable Random Fourier Features activation.
nn_kaf_layer( input_dim, output_dim, num_grids = 8, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )nn_kaf_layer( input_dim, output_dim, num_grids = 8, dropout = 0, use_layernorm = TRUE, activation_expectation = 1.64, fourier_init_scale = 0.01 )
input_dim |
Integer. Input dimension. |
output_dim |
Integer. Output dimension. |
num_grids |
Integer. Number of Fourier frequencies. |
dropout |
Numeric. Dropout probability. |
use_layernorm |
Logical. Whether to apply layer normalization before the Fourier feature block. |
activation_expectation |
Numeric. Scaling constant for Fourier initialization. |
fourier_init_scale |
Numeric. Initial scale of the Fourier component. |
The layer computes a feature-wise hybrid activation of the form:
followed by a linear projection to the output dimension.
A torch nn_module.
Torch module implementing trainable random Fourier features for Kolmogorov-Arnold Fourier Networks.
nn_random_fourier_features( input_dim, num_grids = 8, dropout = 0, activation_expectation = 1.64 )nn_random_fourier_features( input_dim, num_grids = 8, dropout = 0, activation_expectation = 1.64 )
input_dim |
Integer. Input dimension. |
num_grids |
Integer. Number of Fourier frequencies. |
dropout |
Numeric. Dropout probability. |
activation_expectation |
Numeric. Scaling constant for initialization. |
A torch nn_module.
Visualizes the learned base/GELU and Fourier branch scales for a selected KAF layer.
plot_kaf_scales(object, layer = 1, type = c("ratio", "branch"), ...)plot_kaf_scales(object, layer = 1, type = c("ratio", "branch"), ...)
object |
A fitted object returned by |
layer |
Integer. Layer to inspect. |
type |
Character. Either |
... |
Additional arguments passed to base plotting functions. |
Invisibly returns the extracted scale data.
Plot a fitted KAF model
## S3 method for class 'kaf_fit' plot(x, type = c("loss", "fit"), newdata = NULL, y = NULL, ...)## S3 method for class 'kaf_fit' plot(x, type = c("loss", "fit"), newdata = NULL, y = NULL, ...)
x |
A fitted object returned by |
type |
Character. Either |
newdata |
Optional predictors used when |
y |
Optional observed target values used when |
... |
Additional arguments passed to base plotting functions. |
Invisibly returns x.
Predict from a fitted KAF model
## S3 method for class 'kaf_fit' predict( object, newdata, type = c("response", "prob", "class", "link"), threshold = 0.5, as_tensor = FALSE, ... )## S3 method for class 'kaf_fit' predict( object, newdata, type = c("response", "prob", "class", "link"), threshold = 0.5, as_tensor = FALSE, ... )
object |
A fitted object returned by |
newdata |
Matrix, data frame, vector, or 2D torch tensor. |
type |
Character. Prediction type. |
threshold |
Numeric. Classification threshold used for binary class predictions. |
as_tensor |
Logical. If |
... |
Unused. |
Predictions as a vector, matrix, factor, or torch tensor.
Print a fitted KAF model
## S3 method for class 'kaf_fit' print(x, ...)## S3 method for class 'kaf_fit' print(x, ...)
x |
A fitted object returned by |
... |
Unused. |
Invisibly returns x.