| Title: | A Deep Dynamic Experimental Self-Organizing Neural Network Framework |
|---|---|
| Description: | Provides a fully native R deep learning framework for constructing, training, evaluating, and inspecting Deep Dynamic Ensemble Self Organizing Neural Networks at research scale. The core engine is an object oriented R6 class-based implementation with explicit control over layer layout, dimensional flow, forward propagation, back propagation, and transparent optimizer state updates. The framework does not rely on external deep learning back ends, enabling direct inspection of model state, reproducible numerical behavior, and fine grained architectural control without requiring compiled dependencies or graphics processing unit specific run times. Users can define dimension agnostic single layer or deep multi-layer networks without hard coded architecture limits, with per layer configuration vectors for activation functions, derivatives, dropout behavior, and initialization strategies automatically aligned to network depth through controlled replication or truncation. Reproducible workflows can be executed through high level helpers for fit, run, and predict across binary classification, multi-class classification, and regression modes. Training pipelines support optional self organization, adaptive learning rate behavior, and structured ensemble orchestration in which candidate models are evaluated under user specified performance metrics and selectively promoted or pruned to refine a primary ensemble, enabling controlled ensemble evolution over successive runs. Ensemble evaluation includes fused prediction strategies in which member outputs may be combined through weighted averaging, arithmetic averaging, or voting mechanisms to generate consolidated metrics for research level comparison and reproducible per-seed assessment. The framework supports multiple optimization approaches, including stochastic gradient descent, adaptive moment estimation, and look ahead methods, alongside configurable regularization controls such as L1, L2, and mixed penalties with separate weight and bias update logic. Evaluation features provide threshold tuning, relevance scoring, receiver operating characteristic and precision recall curve generation, area under curve computation, regression error diagnostics, and report ready metric outputs. The package also includes artifact path management, debug state utilities, structured run level metadata persistence capturing seeds, configuration states, thresholds, metrics, ensemble transitions, fused evaluation artifacts, and model identifiers, as well as reproducible scripts and vignettes documenting end to end experiments. Kingma and Ba (2015) <doi:10.48550/arXiv.1412.6980> "Adam: A Method for Stochastic Optimization". Hinton et al. (2012) <https://www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf> "Neural Networks for Machine Learning (RMSprop lecture notes)". Duchi et al. (2011) <https://jmlr.org/papers/v12/duchi11a.html> "Adaptive Subgradient Methods for Online Learning and Stochastic Optimization". Zeiler (2012) <doi:10.48550/arXiv.1212.5701> "ADADELTA: An Adaptive Learning Rate Method". Zhang et al. (2019) <doi:10.48550/arXiv.1907.08610> "Lookahead Optimizer: k steps forward, 1 step back". You et al. (2019) <doi:10.48550/arXiv.1904.00962> "Large Batch Optimization for Deep Learning: Training BERT in 76 minutes (LAMB)". McMahan et al. (2013) <https://research.google.com/pubs/archive/41159.pdf> "Ad Click Prediction: a View from the Trenches (FTRL-Proximal)". Klambauer et al. (2017) <https://proceedings.neurips.cc/paper/6698-self-normalizing-neural-networks.pdf> "Self-Normalizing Neural Networks (SELU)". Maas et al. (2013) <https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf> "Rectifier Nonlinearities Improve Neural Network Acoustic Models (Leaky ReLU / rectifiers)". |
| Authors: | Mathew William Armitage Fok [aut, cre] |
| Maintainer: | Mathew William Armitage Fok <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 7.1.11 |
| Built: | 2026-05-08 06:30:16 UTC |
| Source: | https://github.com/mathatter/ddesonn |
ddesonn_activation_defaults()
Compute sensible activation functions for hidden and output layers based on the modelling mode and stage (training or prediction).
DDESONN_activation_defaults(...) ddesonn_activation_defaults( mode = c("binary", "multiclass", "regression"), hidden_sizes = NULL, stage = c("train", "predict") )DDESONN_activation_defaults(...) ddesonn_activation_defaults( mode = c("binary", "multiclass", "regression"), hidden_sizes = NULL, stage = c("train", "predict") )
... |
Additional arguments passed through to
|
mode |
Problem mode. One of |
|
Integer vector describing the hidden layer widths. |
|
stage |
Stage for which activations are required. Either |
Same as ddesonn_activation_defaults().
A list of activation functions suitable for passing into the underlying R6 classes.
ddesonn_activation_defaults("binary", hidden_sizes = c(32, 16)) ddesonn_activation_defaults("regression", hidden_sizes = 64, stage = "predict")ddesonn_activation_defaults("binary", hidden_sizes = c(32, 16)) ddesonn_activation_defaults("regression", hidden_sizes = 64, stage = "predict")
A collection of derivative functions corresponding to DDESONN activation functions.
binary_activation_derivative(x) custom_binary_activation_derivative(x, threshold = -1.08) custom_activation_derivative(z) bent_identity_derivative(x) relu_derivative(x) softplus_derivative(x) leaky_relu_derivative(x, alpha = 0.01) elu_derivative(x, alpha = 1) tanh_derivative(x) sigmoid_derivative(x) hard_sigmoid_derivative(x) swish_derivative(x) sigmoid_binary_derivative(x) gelu_derivative(x) selu_derivative(x, lambda = 1.0507, alpha = 1.67326) mish_derivative(x) maxout_derivative(x, w1 = 0.5, b1 = 1, w2 = -0.5, b2 = 0.5) prelu_derivative(x, alpha = 0.01) softmax_derivative(x) bent_relu_derivative(x) bent_sigmoid_derivative(x) arctangent_derivative(x) sinusoid_derivative(x) gaussian_derivative(x) isrlu_derivative(x, alpha = 1) bent_swish_derivative(x) parametric_bent_relu_derivative(x, beta = 1) leaky_bent_derivative(x, alpha = 0.01) inverse_linear_unit_derivative(x) tanh_relu_hybrid_derivative(x) custom_bent_piecewise_derivative(x, threshold = 0.5) sigmoid_sharp_derivative(x, temp = 5) leaky_selu_derivative(x, alpha = 0.01, lambda = 1.0507) identity_derivative(x)binary_activation_derivative(x) custom_binary_activation_derivative(x, threshold = -1.08) custom_activation_derivative(z) bent_identity_derivative(x) relu_derivative(x) softplus_derivative(x) leaky_relu_derivative(x, alpha = 0.01) elu_derivative(x, alpha = 1) tanh_derivative(x) sigmoid_derivative(x) hard_sigmoid_derivative(x) swish_derivative(x) sigmoid_binary_derivative(x) gelu_derivative(x) selu_derivative(x, lambda = 1.0507, alpha = 1.67326) mish_derivative(x) maxout_derivative(x, w1 = 0.5, b1 = 1, w2 = -0.5, b2 = 0.5) prelu_derivative(x, alpha = 0.01) softmax_derivative(x) bent_relu_derivative(x) bent_sigmoid_derivative(x) arctangent_derivative(x) sinusoid_derivative(x) gaussian_derivative(x) isrlu_derivative(x, alpha = 1) bent_swish_derivative(x) parametric_bent_relu_derivative(x, beta = 1) leaky_bent_derivative(x, alpha = 0.01) inverse_linear_unit_derivative(x) tanh_relu_hybrid_derivative(x) custom_bent_piecewise_derivative(x, threshold = 0.5) sigmoid_sharp_derivative(x, temp = 5) leaky_selu_derivative(x, alpha = 0.01, lambda = 1.0507) identity_derivative(x)
x |
Numeric vector/matrix. |
threshold |
Threshold. |
z |
Numeric vector/matrix. |
alpha |
Leak factor. |
lambda |
SELU lambda. |
w1 |
Weight 1. |
b1 |
Bias 1. |
w2 |
Weight 2. |
b2 |
Bias 2. |
beta |
Beta parameter. |
temp |
Temperature/sharpness. |
Vector of zeros.
Vector of zeros.
Zero array with same dims.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Vector of zeros.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Gradient of active affine branch.
Derivative matrix.
Derivative matrix (approx).
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix.
Derivative matrix/vector.
Matrix of ones with same dimensions as x.
A collection of activation functions used by DDESONN. These functions operate on numeric vectors/matrices and preserve shape.
binary_activation(x) custom_binary_activation(x, threshold = -1.08) custom_activation(z) bent_identity(x) relu(x) softplus(x) leaky_relu(x, alpha = 0.01) elu(x, alpha = 1) tanh(x) sigmoid(x) hard_sigmoid(x) swish(x) sigmoid_binary(x) gelu(x) selu(x, lambda = 1.0507, alpha = 1.67326) mish(x) prelu(x, alpha = 0.01) softmax(z) maxout(x, w1 = 0.5, b1 = 1, w2 = -0.5, b2 = 0.5) bent_relu(x) bent_sigmoid(x) arctangent(x) sinusoid(x) gaussian(x) isrlu(x, alpha = 1) bent_swish(x) parametric_bent_relu(x, beta = 1) leaky_bent(x, alpha = 0.01) inverse_linear_unit(x) tanh_relu_hybrid(x) custom_bent_piecewise(x, threshold = 0.5) sigmoid_sharp(x, temp = 5) leaky_selu(x, alpha = 0.01, lambda = 1.0507) identity(x)binary_activation(x) custom_binary_activation(x, threshold = -1.08) custom_activation(z) bent_identity(x) relu(x) softplus(x) leaky_relu(x, alpha = 0.01) elu(x, alpha = 1) tanh(x) sigmoid(x) hard_sigmoid(x) swish(x) sigmoid_binary(x) gelu(x) selu(x, lambda = 1.0507, alpha = 1.67326) mish(x) prelu(x, alpha = 0.01) softmax(z) maxout(x, w1 = 0.5, b1 = 1, w2 = -0.5, b2 = 0.5) bent_relu(x) bent_sigmoid(x) arctangent(x) sinusoid(x) gaussian(x) isrlu(x, alpha = 1) bent_swish(x) parametric_bent_relu(x, beta = 1) leaky_bent(x, alpha = 0.01) inverse_linear_unit(x) tanh_relu_hybrid(x) custom_bent_piecewise(x, threshold = 0.5) sigmoid_sharp(x, temp = 5) leaky_selu(x, alpha = 0.01, lambda = 1.0507) identity(x)
x |
Numeric vector/matrix. |
threshold |
Threshold for piecewise. |
z |
Numeric vector/matrix. |
alpha |
Leak factor. |
lambda |
SELU lambda. |
w1 |
Weight 1. |
b1 |
Bias 1. |
w2 |
Weight 2. |
b2 |
Bias 2. |
beta |
Beta parameter. |
temp |
Temperature/sharpness. |
Many functions coerce inputs to matrix form and preserve dimensions. Some functions are experimental and may not be suitable for training.
A matrix of 0/1 values with the same dimensions as x.
A matrix of 0/1 values with the same dimensions as x.
A matrix of 0/1 values with the same dimensions as z.
Bent identity transform.
ReLU transform.
Softplus transform.
Leaky ReLU transform.
ELU transform.
tanh transform.
Sigmoid transform.
Hard sigmoid transform.
Swish transform.
0/1 matrix.
GELU transform.
SELU transform.
Mish transform.
PReLU transform.
Row-wise softmax probabilities.
Elementwise max of two affine transforms.
Bent ReLU transform.
Bent sigmoid transform.
atan transform.
sin transform.
exp(-x^2).
ISRLU transform.
Bent swish transform.
Parametric bent ReLU transform.
Leaky bent transform.
x/(1+abs(x)).
Hybrid transform.
Piecewise transform.
Sharpened sigmoid.
Leaky SELU transform.
Base identity function.
ddesonn_artifacts_root()
Defaults to a session-scoped temp directory so examples/tests/vignettes do not write into the user home, working directory, or package tree by default.
DDESONN_artifacts_root(...) ddesonn_artifacts_root(output_root = NULL)DDESONN_artifacts_root(...) ddesonn_artifacts_root(output_root = NULL)
... |
Additional arguments passed through to
|
output_root |
Optional base directory for artifacts. When NULL, a temp-directory location is selected automatically. |
Override order (first non-empty wins):
output_root argument
Sys.getenv("DDESONN_ARTIFACTS_ROOT")
getOption("DDESONN_OUTPUT_ROOT")
Same as ddesonn_artifacts_root().
Absolute path to the artifacts directory (created if missing).
Returns a named list snapshot of objects currently stored in the private package debug/state environment.
ddesonn_debug_state()ddesonn_debug_state()
A named list of objects from DDESONN internal state.
ddesonn_dropout_defaults()
Produce a simple dropout configuration matching the supplied hidden layer sizes.
DDESONN_dropout_defaults(...) ddesonn_dropout_defaults(hidden_sizes)DDESONN_dropout_defaults(...) ddesonn_dropout_defaults(hidden_sizes)
... |
Additional arguments passed through to
|
|
Integer vector describing the hidden layer widths. |
Same as ddesonn_dropout_defaults().
A list of dropout rates for each hidden layer.
ddesonn_dropout_defaults(c(64, 32))ddesonn_dropout_defaults(c(64, 32))
ddesonn_fit()
Train a ddesonn_model (backed by DDESONN) using matrices or
data frames, handling label coercion, validation data, and training control
defaults.
DDESONN_fit(...) ddesonn_fit( model, x, y, validation = NULL, self_org = NULL, ..., verbose = FALSE, verboseLow = FALSE, debug = FALSE )DDESONN_fit(...) ddesonn_fit( model, x, y, validation = NULL, self_org = NULL, ..., verbose = FALSE, verboseLow = FALSE, debug = FALSE )
... |
Named overrides for entries in |
model |
A model created by |
x |
Training features. |
y |
Training targets/labels. |
validation |
Optional list containing |
self_org |
Optional logical override for the legacy self-organization
phase. |
verbose |
Logical; emit detailed progress output when TRUE. |
verboseLow |
Logical; emit important progress output when TRUE. |
debug |
Logical; emit debug diagnostics when TRUE. |
Same as ddesonn_fit().
The trained model (invisibly). The underlying R6 object is modified
in-place and the last training result is stored under model$last_training.
data <- mtcars x <- data[, c("disp", "hp", "wt", "qsec", "drat")] y <- data$am model <- ddesonn_model(input_size = ncol(x), output_size = 1, hidden_sizes = 8) ddesonn_fit(model, x, y, num_epochs = 1, lr = 0.05, validation_metrics = FALSE) # Regression example (mtcars) with explicit scheduler controls. # If you do NOT want LR decay, set lr_decay_rate = 1.0. reg_x <- mtcars[, c("disp", "hp", "wt", "qsec", "drat")] reg_y <- mtcars$mpg reg_model <- ddesonn_model( input_size = ncol(reg_x), # number of input features output_size = 1, # one numeric target hidden_sizes = c(16, 8), # hidden-layer widths classification_mode = "regression" # problem type ) ddesonn_fit( model = reg_model, # model object from ddesonn_model() x = reg_x, # training predictors y = reg_y, # training target num_epochs = 10, # training epochs lr = 0.05, # initial learning rate lr_decay_rate = 0.5, # decay multiplier (use 1.0 to disable) lr_decay_epoch = 20L, # decay step interval in epochs lr_min = 1e-5, # lower bound for learning rate validation_metrics = FALSE # disable validation metric pass in this example )data <- mtcars x <- data[, c("disp", "hp", "wt", "qsec", "drat")] y <- data$am model <- ddesonn_model(input_size = ncol(x), output_size = 1, hidden_sizes = 8) ddesonn_fit(model, x, y, num_epochs = 1, lr = 0.05, validation_metrics = FALSE) # Regression example (mtcars) with explicit scheduler controls. # If you do NOT want LR decay, set lr_decay_rate = 1.0. reg_x <- mtcars[, c("disp", "hp", "wt", "qsec", "drat")] reg_y <- mtcars$mpg reg_model <- ddesonn_model( input_size = ncol(reg_x), # number of input features output_size = 1, # one numeric target hidden_sizes = c(16, 8), # hidden-layer widths classification_mode = "regression" # problem type ) ddesonn_fit( model = reg_model, # model object from ddesonn_model() x = reg_x, # training predictors y = reg_y, # training target num_epochs = 10, # training epochs lr = 0.05, # initial learning rate lr_decay_rate = 0.5, # decay multiplier (use 1.0 to disable) lr_decay_epoch = 20L, # decay step interval in epochs lr_min = 1e-5, # lower bound for learning rate validation_metrics = FALSE # disable validation metric pass in this example )
ddesonn_model()
Initialise a ddesonn_model (R6) instance backed by the legacy
DDESONN class, while handling sensible defaults for activations and node
counts.
DDESONN_model(...) ddesonn_model( input_size, output_size, hidden_sizes = c(64, 32), num_networks = 1L, lambda = 0.00028, classification_mode = c("binary", "multiclass", "regression"), ML_NN = TRUE, activation_functions = NULL, activation_functions_predict = NULL, init_method = "he", custom_scale = 1, N = NULL, ensembles = NULL, ensemble_number = 0L, verbose = FALSE, verboseLow = FALSE, debug = FALSE )DDESONN_model(...) ddesonn_model( input_size, output_size, hidden_sizes = c(64, 32), num_networks = 1L, lambda = 0.00028, classification_mode = c("binary", "multiclass", "regression"), ML_NN = TRUE, activation_functions = NULL, activation_functions_predict = NULL, init_method = "he", custom_scale = 1, N = NULL, ensembles = NULL, ensemble_number = 0L, verbose = FALSE, verboseLow = FALSE, debug = FALSE )
... |
Additional arguments passed through to
|
input_size |
Number of input features. |
output_size |
Number of outputs. |
|
Integer vector describing hidden layer widths. |
|
num_networks |
Number of SONN members to initialise within the ensemble. |
lambda |
Regularisation strength. |
classification_mode |
Problem mode: |
ML_NN |
Logical; whether to initialise a multi-layer SONN. |
activation_functions |
Optional list of activation functions for training. |
activation_functions_predict |
Optional list of activation functions used during prediction. |
init_method |
Weight initialisation scheme passed to the legacy constructor. |
custom_scale |
Optional scaling factor for the initialiser. |
N |
Optional total node count. If omitted it is inferred from the architecture. |
ensembles |
Optional pre-existing ensemble container. |
ensemble_number |
Identifier used when combining multiple ensembles. |
verbose |
Logical; emit detailed progress output when TRUE. |
verboseLow |
Logical; emit important progress output when TRUE. |
debug |
Logical; emit debug diagnostics when TRUE. |
Same as ddesonn_model().
A ddesonn_model (R6) instance ready for training.
model <- ddesonn_model( input_size = 5, output_size = 1, hidden_sizes = c(32, 16), classification_mode = "binary" )model <- ddesonn_model( input_size = 5, output_size = 1, hidden_sizes = c(32, 16), classification_mode = "binary" )
ddesonn_optimizer_options()
List the optimizer strings understood by the legacy DDESONN training loop.
DDESONN_optimizer_options(...) ddesonn_optimizer_options()DDESONN_optimizer_options(...) ddesonn_optimizer_options()
... |
Additional arguments passed through to
|
Same as ddesonn_optimizer_options().
A character vector of supported optimiser identifiers.
ddesonn_optimizer_options()ddesonn_optimizer_options()
ddesonn_plots_dir()
Legacy alias for ddesonn_plots_dir()
Resolve the plots directory inside the artifacts root.
DDESONN_plots_dir(...) ddesonn_plots_dir(output_root = NULL)DDESONN_plots_dir(...) ddesonn_plots_dir(output_root = NULL)
... |
Additional arguments passed through to
|
output_root |
Optional base directory for artifacts. When NULL, a temp-directory location is selected automatically. |
Same as ddesonn_plots_dir().
Absolute path to the plots directory.
ddesonn_predict()
Internal prediction engine / forward-pass primitive that
produces ensemble or per-model predictions from a trained ddesonn_model.
For user-facing inference, prefer predict.ddesonn_model(), which wraps
this helper to provide a stable API for type/aggregate/threshold
handling and return shapes.
Multiclass note: For multiclass classification, y should be encoded as integer class indices 1..K (or a one-hot matrix whose columns follow the model’s class order), otherwise accuracy comparisons may be incorrect.
DDESONN_predict(...) ddesonn_predict( model, new_data, aggregate = c("mean", "median", "none"), type = c("response", "class"), threshold = NULL, verbose = FALSE, verboseLow = FALSE, debug = FALSE )DDESONN_predict(...) ddesonn_predict( model, new_data, aggregate = c("mean", "median", "none"), type = c("response", "class"), threshold = NULL, verbose = FALSE, verboseLow = FALSE, debug = FALSE )
... |
Additional arguments passed through to
|
model |
A trained model produced by |
new_data |
New feature matrix or data frame. |
aggregate |
Aggregation strategy across ensemble members. One of
|
type |
Prediction type. |
threshold |
Optional threshold override when |
verbose |
Logical; emit detailed progress output when TRUE. |
verboseLow |
Logical; emit important progress output when TRUE. |
debug |
Logical; emit debug diagnostics when TRUE. |
Same as ddesonn_predict().
A list containing the aggregated prediction matrix and the
per-model outputs when aggregate = "none".
# ============================================================ # Example 1 — Manual API (minimal, CRAN-safe) # ============================================================ # This is the base mtcars binary classification example. # The exact same setup is used again below in the full workflow script. data <- mtcars target <- "am" features <- setdiff(colnames(data), target) x <- data[, features] y <- data[[target]] model <- ddesonn_model( input_size = ncol(x), output_size = 1, hidden_sizes = c(32, 16), classification_mode = "binary", activation_functions = c("relu", "relu", "sigmoid"), activation_functions_predict = c("relu", "relu", "sigmoid"), num_networks = 1 ) ddesonn_fit( model, x, y, num_epochs = 3, lr = 0.02, validation_metrics = FALSE ) preds <- ddesonn_predict(model, x) head(preds$prediction) # ============================================================ # Example 2 — Same example, extended (A–D scenarios) # ============================================================ # This is the SAME mtcars example shown above. # The only difference is that the full script adds: # - train/validation/test splitting # - scaling (fit on training data) # - ensemble configurations # - scenario orchestration (A–D) # View the full version of this same example: system.file("scripts", "DDESONN_mtcars_A-D_examples.R", package = "DDESONN") # Repository path: # /DDESONN/inst/scripts/DDESONN_mtcars_A-D_examples.R# ============================================================ # Example 1 — Manual API (minimal, CRAN-safe) # ============================================================ # This is the base mtcars binary classification example. # The exact same setup is used again below in the full workflow script. data <- mtcars target <- "am" features <- setdiff(colnames(data), target) x <- data[, features] y <- data[[target]] model <- ddesonn_model( input_size = ncol(x), output_size = 1, hidden_sizes = c(32, 16), classification_mode = "binary", activation_functions = c("relu", "relu", "sigmoid"), activation_functions_predict = c("relu", "relu", "sigmoid"), num_networks = 1 ) ddesonn_fit( model, x, y, num_epochs = 3, lr = 0.02, validation_metrics = FALSE ) preds <- ddesonn_predict(model, x) head(preds$prediction) # ============================================================ # Example 2 — Same example, extended (A–D scenarios) # ============================================================ # This is the SAME mtcars example shown above. # The only difference is that the full script adds: # - train/validation/test splitting # - scaling (fit on training data) # - ensemble configurations # - scenario orchestration (A–D) # View the full version of this same example: system.file("scripts", "DDESONN_mtcars_A-D_examples.R", package = "DDESONN") # Repository path: # /DDESONN/inst/scripts/DDESONN_mtcars_A-D_examples.R
ddesonn_run()
This helper re-creates the four orchestration modes that previously lived in
TestDDESONN.R:
DDESONN_run(...) ddesonn_run( x, y, classification_mode = c("binary", "multiclass", "regression"), hidden_sizes = c(64, 32), seeds = 1L, do_ensemble = FALSE, num_networks = if (isTRUE(do_ensemble)) 3L else 1L, num_temp_iterations = 0L, validation = NULL, x_valid = NULL, y_valid = NULL, model_overrides = list(), training_overrides = list(), temp_overrides = NULL, prediction_data = NULL, test = NULL, x_test = NULL, y_test = NULL, prediction_type = c("response", "class"), aggregate = c("mean", "median", "none"), seed_aggregate = c("mean", "median", "none"), threshold = NULL, output_root = NULL, plot_controls = NULL, save_models = TRUE, verbose = FALSE, verboseLow = FALSE, debug = FALSE )DDESONN_run(...) ddesonn_run( x, y, classification_mode = c("binary", "multiclass", "regression"), hidden_sizes = c(64, 32), seeds = 1L, do_ensemble = FALSE, num_networks = if (isTRUE(do_ensemble)) 3L else 1L, num_temp_iterations = 0L, validation = NULL, x_valid = NULL, y_valid = NULL, model_overrides = list(), training_overrides = list(), temp_overrides = NULL, prediction_data = NULL, test = NULL, x_test = NULL, y_test = NULL, prediction_type = c("response", "class"), aggregate = c("mean", "median", "none"), seed_aggregate = c("mean", "median", "none"), threshold = NULL, output_root = NULL, plot_controls = NULL, save_models = TRUE, verbose = FALSE, verboseLow = FALSE, debug = FALSE )
... |
Additional arguments passed through to
|
x |
Training features (the training split) as a data frame, matrix, or tibble. |
y |
Training labels/targets (the training split). |
classification_mode |
Overall problem mode. One of |
|
Integer vector describing the hidden layer widths. |
|
seeds |
Integer vector of seeds. A separate model (or ensemble stack) is trained for each seed. |
do_ensemble |
Logical flag selecting the ensemble container modes
(scenarios C/D). When |
num_networks |
Number of ensemble members inside each
|
num_temp_iterations |
Number of TEMP iterations to run when
|
validation |
Optional validation list with elements |
x_valid |
Optional validation features. Overrides |
y_valid |
Optional validation labels. Overrides |
model_overrides |
Named list forwarded to |
training_overrides |
Named list forwarded to |
temp_overrides |
Optional named list forwarded to |
prediction_data |
Optional features for prediction. When supplied, predictions are computed for each seed/iteration. |
test |
Optional test list with elements |
x_test |
Optional test features. Overrides |
y_test |
Optional test labels. Overrides |
prediction_type |
Passed to |
aggregate |
Aggregation strategy within a single model (across ensemble members). |
seed_aggregate |
Aggregation strategy across seeds. Set to |
threshold |
Optional threshold override for classification prediction. |
output_root |
Optional directory where legacy-style artifacts are
written. When |
plot_controls |
Optional list passed through to |
save_models |
Logical; if |
verbose |
Logical; emit detailed progress output when TRUE. |
verboseLow |
Logical; emit important progress output when TRUE. |
debug |
Logical; emit debug diagnostics when TRUE. |
Scenario A – single model (do_ensemble = FALSE, num_networks = 1).
Scenario B – single run with multiple members inside a single model
(do_ensemble = FALSE, num_networks > 1).
Scenario C – main ensemble container (do_ensemble = TRUE,
num_temp_iterations = 0).
Scenario D – main ensemble plus TEMP iterations (do_ensemble = TRUE,
num_temp_iterations > 0).
The function accepts a training set, optional validation data, and optional
prediction features. It repeatedly instantiates ddesonn_model() objects,
fits them with ddesonn_fit(), and (when requested) calls
ddesonn_predict() to surface aggregated predictions.
Discovering available training overrides
training_overrides is a direct pass-through to ddesonn_fit(). To see the
baseline defaults used by ddesonn_run(), call:
ddesonn_training_defaults(classification_mode, hidden_sizes)
To see all tunable training arguments, see ?ddesonn_fit.
Same as ddesonn_run().
A list (classed as "ddesonn_run_result") containing the
configuration, per-seed models, and optional prediction summaries.
# ============================================================ # DDESONN — FULL example using package data in inst/extdata # (binary classification; train/valid/test split; scale train-only) # ============================================================ library(DDESONN) set.seed(111) # ------------------------------------------------------------ # 1) Locate package extdata folder (robust across check/install) # ------------------------------------------------------------ ext_dir <- system.file("extdata", package = "DDESONN") if (!nzchar(ext_dir)) { stop("Could not find DDESONN extdata folder. Is the package installed?", call. = FALSE) } # ------------------------------------------------------------ # 1b) Find CSVs (recursive + check-dir edge cases) # ------------------------------------------------------------ csvs <- list.files( ext_dir, pattern = "\\\\.csv$", full.names = TRUE, recursive = TRUE ) # Defensive fallback for rare nested layouts if (!length(csvs)) { ext_dir2 <- file.path(ext_dir, "inst", "extdata") if (dir.exists(ext_dir2)) { csvs <- list.files( ext_dir2, pattern = "\\\\.csv$", full.names = TRUE, recursive = TRUE ) } } if (!length(csvs)) { message(sprintf( "No .csv files found under: %s — skipping example.", ext_dir )) } else { hf_path <- file.path(ext_dir, "heart_failure_clinical_records.csv") data_path <- if (file.exists(hf_path)) hf_path else csvs[[1]] cat("[extdata] using:", data_path, "\\n") # ------------------------------------------------------------ # 2) Load data # ------------------------------------------------------------ df <- read.csv(data_path) # Prefer DEATH_EVENT if present; otherwise infer a binary target target_col <- if ("DEATH_EVENT" %in% names(df)) { "DEATH_EVENT" } else { cand <- names(df)[vapply(df, function(col) { v <- suppressWarnings(as.numeric(col)) if (all(is.na(v))) return(FALSE) u <- unique(v[is.finite(v)]) length(u) <= 2 && all(sort(u) %in% c(0, 1)) }, logical(1))] if (!length(cand)) { stop( "Could not infer a binary target column. ", "Provide a binary CSV in extdata or rename target to DEATH_EVENT.", call. = FALSE ) } cand[[1]] } cat("[data] target_col =", target_col, "\\n") # ------------------------------------------------------------ # 3) Build X and y # ------------------------------------------------------------ y_all <- matrix(as.integer(df[[target_col]]), ncol = 1) x_df <- df[, setdiff(names(df), target_col), drop = FALSE] x_all <- as.matrix(x_df) storage.mode(x_all) <- "double" # ------------------------------------------------------------ # 4) Split 70 / 15 / 15 # ------------------------------------------------------------ n <- nrow(x_all) idx <- sample.int(n) n_train <- floor(0.70 * n) n_valid <- floor(0.15 * n) i_tr <- idx[1:n_train] i_va <- idx[(n_train + 1):(n_train + n_valid)] i_te <- idx[(n_train + n_valid + 1):n] x_train <- x_all[i_tr, , drop = FALSE] y_train <- y_all[i_tr, , drop = FALSE] x_valid <- x_all[i_va, , drop = FALSE] y_valid <- y_all[i_va, , drop = FALSE] x_test <- x_all[i_te, , drop = FALSE] y_test <- y_all[i_te, , drop = FALSE] cat(sprintf("[split] train=%d valid=%d test=%d\\n", nrow(x_train), nrow(x_valid), nrow(x_test))) # ------------------------------------------------------------ # 5) Scale using TRAIN stats only (no leakage) # ------------------------------------------------------------ x_train_s <- scale(x_train) ctr <- attr(x_train_s, "scaled:center") scl <- attr(x_train_s, "scaled:scale") scl[!is.finite(scl) | scl == 0] <- 1 x_valid_s <- sweep(sweep(x_valid, 2, ctr, "-"), 2, scl, "/") x_test_s <- sweep(sweep(x_test, 2, ctr, "-"), 2, scl, "/") mx <- suppressWarnings(max(abs(x_train_s))) if (!is.finite(mx) || mx == 0) mx <- 1 x_train <- x_train_s / mx x_valid <- x_valid_s / mx x_test <- x_test_s / mx # ------------------------------------------------------------ # 6) Run DDESONN # ------------------------------------------------------------ res <- ddesonn_run( x = x_train, y = y_train, classification_mode = "binary", hidden_sizes = c(64, 32), seeds = 1L, do_ensemble = FALSE, validation = list( x = x_valid, y = y_valid ), test = list( x = x_test, y = y_test ), training_overrides = list( init_method = "he", optimizer = "adagrad", lr = 0.125, lambda = 0.00028, activation_functions = list(relu, relu, sigmoid), dropout_rates = list(0.10), loss_type = "CrossEntropy", validation_metrics = TRUE, num_epochs = 360, final_summary_decimals = 6L ), plot_controls = list( evaluate_report = list( roc_curve = TRUE, pr_curve = FALSE ) ) ) }# ============================================================ # DDESONN — FULL example using package data in inst/extdata # (binary classification; train/valid/test split; scale train-only) # ============================================================ library(DDESONN) set.seed(111) # ------------------------------------------------------------ # 1) Locate package extdata folder (robust across check/install) # ------------------------------------------------------------ ext_dir <- system.file("extdata", package = "DDESONN") if (!nzchar(ext_dir)) { stop("Could not find DDESONN extdata folder. Is the package installed?", call. = FALSE) } # ------------------------------------------------------------ # 1b) Find CSVs (recursive + check-dir edge cases) # ------------------------------------------------------------ csvs <- list.files( ext_dir, pattern = "\\\\.csv$", full.names = TRUE, recursive = TRUE ) # Defensive fallback for rare nested layouts if (!length(csvs)) { ext_dir2 <- file.path(ext_dir, "inst", "extdata") if (dir.exists(ext_dir2)) { csvs <- list.files( ext_dir2, pattern = "\\\\.csv$", full.names = TRUE, recursive = TRUE ) } } if (!length(csvs)) { message(sprintf( "No .csv files found under: %s — skipping example.", ext_dir )) } else { hf_path <- file.path(ext_dir, "heart_failure_clinical_records.csv") data_path <- if (file.exists(hf_path)) hf_path else csvs[[1]] cat("[extdata] using:", data_path, "\\n") # ------------------------------------------------------------ # 2) Load data # ------------------------------------------------------------ df <- read.csv(data_path) # Prefer DEATH_EVENT if present; otherwise infer a binary target target_col <- if ("DEATH_EVENT" %in% names(df)) { "DEATH_EVENT" } else { cand <- names(df)[vapply(df, function(col) { v <- suppressWarnings(as.numeric(col)) if (all(is.na(v))) return(FALSE) u <- unique(v[is.finite(v)]) length(u) <= 2 && all(sort(u) %in% c(0, 1)) }, logical(1))] if (!length(cand)) { stop( "Could not infer a binary target column. ", "Provide a binary CSV in extdata or rename target to DEATH_EVENT.", call. = FALSE ) } cand[[1]] } cat("[data] target_col =", target_col, "\\n") # ------------------------------------------------------------ # 3) Build X and y # ------------------------------------------------------------ y_all <- matrix(as.integer(df[[target_col]]), ncol = 1) x_df <- df[, setdiff(names(df), target_col), drop = FALSE] x_all <- as.matrix(x_df) storage.mode(x_all) <- "double" # ------------------------------------------------------------ # 4) Split 70 / 15 / 15 # ------------------------------------------------------------ n <- nrow(x_all) idx <- sample.int(n) n_train <- floor(0.70 * n) n_valid <- floor(0.15 * n) i_tr <- idx[1:n_train] i_va <- idx[(n_train + 1):(n_train + n_valid)] i_te <- idx[(n_train + n_valid + 1):n] x_train <- x_all[i_tr, , drop = FALSE] y_train <- y_all[i_tr, , drop = FALSE] x_valid <- x_all[i_va, , drop = FALSE] y_valid <- y_all[i_va, , drop = FALSE] x_test <- x_all[i_te, , drop = FALSE] y_test <- y_all[i_te, , drop = FALSE] cat(sprintf("[split] train=%d valid=%d test=%d\\n", nrow(x_train), nrow(x_valid), nrow(x_test))) # ------------------------------------------------------------ # 5) Scale using TRAIN stats only (no leakage) # ------------------------------------------------------------ x_train_s <- scale(x_train) ctr <- attr(x_train_s, "scaled:center") scl <- attr(x_train_s, "scaled:scale") scl[!is.finite(scl) | scl == 0] <- 1 x_valid_s <- sweep(sweep(x_valid, 2, ctr, "-"), 2, scl, "/") x_test_s <- sweep(sweep(x_test, 2, ctr, "-"), 2, scl, "/") mx <- suppressWarnings(max(abs(x_train_s))) if (!is.finite(mx) || mx == 0) mx <- 1 x_train <- x_train_s / mx x_valid <- x_valid_s / mx x_test <- x_test_s / mx # ------------------------------------------------------------ # 6) Run DDESONN # ------------------------------------------------------------ res <- ddesonn_run( x = x_train, y = y_train, classification_mode = "binary", hidden_sizes = c(64, 32), seeds = 1L, do_ensemble = FALSE, validation = list( x = x_valid, y = y_valid ), test = list( x = x_test, y = y_test ), training_overrides = list( init_method = "he", optimizer = "adagrad", lr = 0.125, lambda = 0.00028, activation_functions = list(relu, relu, sigmoid), dropout_rates = list(0.10), loss_type = "CrossEntropy", validation_metrics = TRUE, num_epochs = 360, final_summary_decimals = 6L ), plot_controls = list( evaluate_report = list( roc_curve = TRUE, pr_curve = FALSE ) ) ) }
ddesonn_training_defaults()
Build a list of training hyperparameters that mirror the expectations of the legacy DDESONN training loop.
DDESONN_training_defaults(...) ddesonn_training_defaults( mode = c("binary", "multiclass", "regression"), hidden_sizes = NULL )DDESONN_training_defaults(...) ddesonn_training_defaults( mode = c("binary", "multiclass", "regression"), hidden_sizes = NULL )
... |
Additional arguments passed through to
|
mode |
Problem mode used to determine sensible defaults. |
|
Integer vector describing the hidden layer widths. |
Same as ddesonn_training_defaults().
A named list that can be modified and supplied to ddesonn_fit().
ddesonn_training_defaults("binary", hidden_sizes = c(32, 16)) # Inspect regression defaults (includes LR decay by default). cfg_reg <- ddesonn_training_defaults("regression", hidden_sizes = c(16, 8)) cfg_reg$lr cfg_reg$lr_decay_rate cfg_reg$lr_decay_epoch cfg_reg$lr_min # If you prefer a fixed LR in regression, disable decay explicitly. cfg_reg$lr_decay_rate <- 1.0ddesonn_training_defaults("binary", hidden_sizes = c(32, 16)) # Inspect regression defaults (includes LR decay by default). cfg_reg <- ddesonn_training_defaults("regression", hidden_sizes = c(16, 8)) cfg_reg$lr cfg_reg$lr_decay_rate cfg_reg$lr_decay_epoch cfg_reg$lr_min # If you prefer a fixed LR in regression, disable decay explicitly. cfg_reg$lr_decay_rate <- 1.0
This is the canonical user-facing wrapper around ddesonn_predict(). It
standardizes arguments (type, aggregate, threshold) and normalizes the
output structure for inference workflows.
Multiclass note: For multiclass classification, y should be encoded as integer class indices 1..K (or a one-hot matrix whose columns follow the model’s class order), otherwise accuracy comparisons may be incorrect.
## S3 method for class 'ddesonn_model' predict( object, newdata, ..., aggregate = c("mean", "median", "none"), type = c("response", "class"), threshold = NULL, verbose = FALSE, verboseLow = FALSE, debug = FALSE )## S3 method for class 'ddesonn_model' predict( object, newdata, ..., aggregate = c("mean", "median", "none"), type = c("response", "class"), threshold = NULL, verbose = FALSE, verboseLow = FALSE, debug = FALSE )
object |
A ddesonn_model (R6) returned by ddesonn_run() / ddesonn_model(). |
newdata |
Matrix/data.frame of predictors. |
... |
Unused. |
aggregate |
Aggregation strategy across ensemble members. |
type |
Prediction type. |
threshold |
Optional threshold override when |
verbose |
Logical; emit detailed progress output when TRUE. |
verboseLow |
Logical; emit important progress output when TRUE. |
debug |
Logical; emit debug diagnostics when TRUE. |
Print a summary of a DDESONN run result
## S3 method for class 'ddesonn_run_result' print(x, ...)## S3 method for class 'ddesonn_run_result' print(x, ...)
x |
A |
... |
Unused. |
x, invisibly.