| Type: | Package |
| Title: | A Deep Dynamic Experimental Self-Organizing Neural Network Framework |
| Version: | 7.5.21 |
| 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. An optional Shiny workbench provides guided data preparation, background training, validation checkpoint or final epoch weight selection, model inspection, saved model prediction, and reproducible R recipes. Best validation checkpoint selection restores both weights and biases for inference; both selection modes run the requested training epochs. 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://static.googleusercontent.com/media/research.google.com/en//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)". |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1.0) |
| Imports: | R6, stats, utils, dplyr, openxlsx, tidyr, pROC, PRROC, reshape2, digest, ggplot2 |
| Suggests: | shiny, callr, testthat, jsonlite, withr, knitr, rmarkdown, foreach, quantmod, randomForest, reticulate, zoo, readxl, tibble |
| VignetteBuilder: | knitr |
| URL: | https://github.com/MatHatter/DDESONN |
| BugReports: | https://github.com/MatHatter/DDESONN/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-11-27 21:36:16 UTC; wfky1 |
| Author: | Mathew William Armitage Fok [aut, cre] |
| Maintainer: | Mathew William Armitage Fok <quiksilver67213@yahoo.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-28 20:20:08 UTC |
DDESONN: 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. An optional Shiny workbench provides guided data preparation, background training, validation checkpoint or final epoch weight selection, model inspection, saved model prediction, and reproducible R recipes. Best validation checkpoint selection restores both weights and biases for inference; both selection modes run the requested training epochs. 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://static.googleusercontent.com/media/research.google.com/en//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)".
Optional Shiny graphical interface
The package includes a guided graphical user interface (GUI) for data preparation, model training/evaluation, saved-model prediction and viewing research results. Install the optional app dependencies once, then launch from an interactive R session:
install.packages(c("shiny", "callr"))
shiny::runApp(system.file("shiny", "benchmark", package = "DDESONN",
mustWork = TRUE))
Start with Iris on Data, review Features and prepare the data, train on Build & Train, then inspect Model / Results. Use the saved-model workflow to load a workbench bundle and evaluate or predict rows from a CSV. Information icons, Vignettes and Show full R code provide in-app guidance.
Experiments displays saved results without starting training. Current shows the clean matched DDESONN/Keras study with 100 seeds per condition, using an experimental native float32 adapter on one fixed split. Historical compares 1,000 standard-AdaGrad DDESONN runs with archived legacy observations, retains overlapping inputs and does not rerun Keras.
vignette("packaged-data-workbench", package = "DDESONN")
Author(s)
Maintainer: Mathew William Armitage Fok quiksilver67213@yahoo.com
See Also
Useful links:
DDESONN R6 class
Description
Internal R6 class backing the DDESONN framework.
Legacy alias for ddesonn_activation_defaults()
Description
Compute sensible activation functions for hidden and output layers based on the modelling mode and stage (training or prediction).
Usage
DDESONN_activation_defaults(...)
ddesonn_activation_defaults(
mode = c("binary", "multiclass", "regression"),
hidden_sizes = NULL,
stage = c("train", "predict")
)
Arguments
... |
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 |
Value
Same as ddesonn_activation_defaults().
A list of activation functions suitable for passing into the underlying R6 classes.
Examples
ddesonn_activation_defaults("binary", hidden_sizes = c(32, 16))
ddesonn_activation_defaults("regression", hidden_sizes = 64, stage = "predict")
Legacy alias for ddesonn_artifacts_root()
Description
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.
Usage
DDESONN_artifacts_root(...)
ddesonn_artifacts_root(output_root = NULL)
Arguments
... |
Additional arguments passed through to
|
output_root |
Optional base directory for artifacts. When NULL, a temp-directory location is selected automatically. |
Details
Override order (first non-empty wins):
output_root argument
Sys.getenv("DDESONN_ARTIFACTS_ROOT")
getOption("DDESONN_OUTPUT_ROOT")
Value
Same as ddesonn_artifacts_root().
Absolute path to the artifacts directory (created if missing).
Legacy alias for ddesonn_dropout_defaults()
Description
Produce a simple dropout configuration matching the supplied hidden layer sizes.
Usage
DDESONN_dropout_defaults(...)
ddesonn_dropout_defaults(hidden_sizes)
Arguments
... |
Additional arguments passed through to
|
|
Integer vector describing the hidden layer widths. |
Value
Same as ddesonn_dropout_defaults().
A list of dropout rates for each hidden layer.
Examples
ddesonn_dropout_defaults(c(64, 32))
Legacy alias for ddesonn_fit()
Description
Train a ddesonn_model (backed by DDESONN) using matrices or
data frames, handling label coercion, validation data, and training control
defaults.
Usage
DDESONN_fit(...)
ddesonn_fit(
model,
x,
y,
validation = NULL,
self_org = NULL,
...,
verbose = FALSE,
verboseLow = FALSE,
debug = FALSE,
average_gradients = NULL,
sequence_data = NULL,
sequence_length = 48L,
ssm_state_dim = 16L,
ssm_conv = 4L,
ssm_training = c("joint", "pretrain"),
ssm_lr = NULL
)
Arguments
... |
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. |
average_gradients |
Optional logical switch: FALSE sums dense weight and bias gradients; TRUE averages both. NULL inherits the model's saved setting. Older models without this metadata retain summed weights/averaged biases. This does not change the separate SSM encoder gradient contract. |
sequence_data |
Aligned samples by timesteps by channels sequence array. |
sequence_length, ssm_state_dim, ssm_conv |
Compatibility arguments; SSM models use their saved sequence configuration. |
ssm_training |
|
ssm_lr |
Optional non-negative encoder learning rate. |
Value
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.
See Also
Examples
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
)
Legacy alias for ddesonn_model()
Description
Initialise a ddesonn_model (R6) instance backed by the legacy
DDESONN class, while handling sensible defaults for activations and node
counts.
Usage
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,
sequence_encoder = "none",
sequence_data = NULL,
sequence_length = 48L,
ssm_state_dim = 16L,
ssm_conv = 4L,
average_gradients = FALSE
)
Arguments
... |
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. |
sequence_encoder |
Use |
sequence_data |
Aligned samples by timesteps by channels sequence array. |
sequence_length |
Number of timesteps per sequence window. |
ssm_state_dim |
Number of encoder state dimensions. |
ssm_conv |
Width of the encoder's causal convolution. |
average_gradients |
Logical. FALSE (default) sums dense weight and bias gradients over the batch; TRUE averages both before clipping/regularization. |
Value
Same as ddesonn_model().
A ddesonn_model (R6) instance ready for training.
See Also
Examples
model <- ddesonn_model(
input_size = 5,
output_size = 1,
hidden_sizes = c(32, 16),
classification_mode = "binary"
)
Legacy alias for ddesonn_optimizer_options()
Description
List the optimizer strings understood by the legacy DDESONN training loop.
Usage
DDESONN_optimizer_options(...)
ddesonn_optimizer_options()
Arguments
... |
Additional arguments passed through to
|
Details
The default is standard adagrad. Legacy custom Adagrad (also
called adagrad_x during development) has been removed. Historical
training results and optimizer state are not interchangeable.
Value
Same as ddesonn_optimizer_options().
A character vector of supported optimiser identifiers.
Examples
ddesonn_optimizer_options()
Legacy alias for ddesonn_predict()
Description
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.
Usage
DDESONN_predict(...)
ddesonn_predict(
model,
new_data,
aggregate = c("mean", "median", "none"),
type = c("response", "class"),
threshold = NULL,
verbose = FALSE,
verboseLow = FALSE,
debug = FALSE,
sequence_data = NULL,
sequence_length = 48L,
ssm_state_dim = 16L,
ssm_conv = 4L
)
Arguments
... |
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. |
sequence_data |
Aligned samples by timesteps by channels sequence array. |
sequence_length |
Number of timesteps per sequence window. |
ssm_state_dim |
Number of encoder state dimensions. |
ssm_conv |
Width of the encoder's causal convolution. |
Value
Same as ddesonn_predict().
A list containing the aggregated prediction matrix and the
per-model outputs when aggregate = "none".
See Also
Examples
# ============================================================
# 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
Legacy alias for ddesonn_run()
Description
This helper re-creates the four orchestration modes that previously lived in
TestDDESONN.R:
Usage
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,
sequence_encoder = "none",
sequence_data = NULL,
sequence_length = 48L,
ssm_state_dim = 16L,
ssm_conv = 4L,
prediction_sequence_data = NULL,
dataset_name = NULL
)
Arguments
... |
Additional arguments passed through to
|
x |
Training features (the training split) as a data frame, matrix, or tibble. |
y |
Training labels or targets. Classification accepts class labels or a one-hot matrix. Validation and test labels use the training class order. |
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, or a list containing
|
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. Print the full run report and detailed diagnostics. |
verboseLow |
Logical. Print a compact run summary and important progress
messages. Set this directly on |
debug |
Logical. Enable debug diagnostics.
Does not set |
sequence_encoder |
Optional sequence encoder, |
sequence_data |
Training sequence array aligned to |
sequence_length |
Expected number of timesteps in each sequence. |
ssm_state_dim |
SSM latent state/embedding dimension. |
ssm_conv |
SSM causal convolution width. |
prediction_sequence_data |
Sequence array aligned to matrix-form
|
dataset_name |
Optional built-in dataset name or input filename for the run report. Directory components are removed. |
Details
The default console output includes the usual evaluation output. Set
verboseLow = TRUE to add a compact run summary or verbose = TRUE for
the full report. The returned run always includes the full report.
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.
Tracing training methods from R
Top-level verbose = TRUE shows the full report and split prediction traces.
Set verbose = TRUE inside training_overrides for finer-grained training
traces. Add it to the same list as any other training overrides. Both
settings can be used together.
The two R6 classes are defined in R/DDESONN.R. DDESONN$train()
coordinates the network members. SONN$train_network() runs one network's
epoch loop and applies optimizer updates. SONN$learn() computes the
forward and backward passes and returns gradients. SONN$predict()
runs inference and can be called during training to compute metrics.
Selecting epochs for method traces
trace_epochs selects begin/end markers for four R6 methods in
R/DDESONN.R: DDESONN$train() during batch preparation, and
SONN$train_network(), SONN$learn(), and SONN$predict() inside the
training epoch loop. Selected end markers include elapsed wall-clock time.
The durations can include calls to other traced methods.
For example, set
training_overrides = list(trace_epochs = list(all = FALSE, train = 5:10, learn = 10:15)).
A positive whole-number vector selects epochs, TRUE selects all epochs,
and FALSE suppresses that method's markers. Set all = TRUE or
all = FALSE as the default for omitted methods. An explicit method
selection overrides it. Without all, omitted methods follow the usual
verbosity settings. Only begin/end markers are filtered. Other diagnostics
and the training schedule stay the same.
Without trace_epochs, no epoch filter is applied. The verbosity and debug
settings do not activate it. Explicit selections work with debug, verbose, and
verboseLow all off. Use verbose = TRUE inside training_overrides
if you also need detailed diagnostics from the training methods. The
epoch filter controls method begin/end markers, and the verbosity flags
and debug keep their usual behavior.
Epoch numbers start at 1 and restart for each fit. Ranges include both
endpoints, so learn = 1:10 traces epochs 1 through 10. Epoch 0 is invalid.
For train, the markers bracket the
container's batch preparation for each epoch. For train_network, they
bracket one network's full epoch. learn and in-training predict are
traced at the epoch that calls them. Predictions outside the epoch loop
use the usual verbosity settings. TEMP fits inherit the selection unless
temp_overrides supplies its own trace_epochs.
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.
Value
Same as ddesonn_run().
A list (classed as "ddesonn_run_result") containing the
configuration, per-seed models, and optional prediction summaries.
Examples
# ============================================================
# 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",
# For this example, start with verboseLow for a compact summary.
# verboseLow = TRUE,
# verbose = TRUE, # Full report and detailed prediction traces.
# Verbose output may include more diagnostics in future releases.
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
)
)
)
}
Legacy alias for ddesonn_training_defaults()
Description
Build a list of training hyperparameters that mirror the expectations of the legacy DDESONN training loop.
Usage
DDESONN_training_defaults(...)
ddesonn_training_defaults(
mode = c("binary", "multiclass", "regression"),
hidden_sizes = NULL
)
Arguments
... |
Additional arguments passed through to
|
mode |
Problem mode used to determine sensible defaults. |
|
Integer vector describing the hidden layer widths. |
Value
Same as ddesonn_training_defaults().
A named list that can be modified and supplied to ddesonn_fit().
Examples
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.0
SONN R6 class
Description
Internal legacy R6 class backing the SONN engine. Future proof when build out SONN.Rd in DDESONN/man
Activation derivatives (DDESONN)
Description
A collection of derivative functions corresponding to DDESONN activation functions.
Usage
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)
Arguments
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. |
Value
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.
Activation functions (DDESONN)
Description
A collection of activation functions used by DDESONN. These functions operate on numeric vectors/matrices and preserve shape.
Usage
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)
Arguments
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. |
Details
Many functions coerce inputs to matrix form and preserve dimensions. Some functions are experimental and may not be suitable for training.
Value
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.
Inspect internal DDESONN debug state
Description
Returns a named list snapshot of objects currently stored in the private package debug/state environment.
Usage
ddesonn_debug_state()
Value
A named list of objects from DDESONN internal state.
Legacy alias for ddesonn_plots_dir()
Description
Legacy alias for ddesonn_plots_dir()
Resolve the plots directory inside the artifacts root.
Usage
DDESONN_plots_dir(...)
ddesonn_plots_dir(output_root = NULL)
Arguments
... |
Additional arguments passed through to
|
output_root |
Optional base directory for artifacts. When NULL, a temp-directory location is selected automatically. |
Value
Same as ddesonn_plots_dir().
Absolute path to the plots directory.
Build causal fixed-length sequences
Description
Constructs an array of samples by time by features without using observations after a sample's end index.
Usage
ddesonn_sequence_data(data, sequence_length = 48L, pad = FALSE)
Arguments
data |
Finite numeric observations in chronological order. |
sequence_length |
Positive window length. |
pad |
Left-pad leading windows. |
Value
A numeric three-dimensional array with an end_index attribute.
Native-R selective state-space sequence encoder
Description
Initialise, evaluate, differentiate, scale, and reset the optional native-R causal selective state-space encoder.
Usage
ddesonn_ssm_init(
sequence_features,
state_dim = 16L,
conv_width = 4L,
seed = NULL
)
ddesonn_ssm_reset_state(encoder, state = NULL)
ddesonn_ssm_forward(encoder, sequence_data, return_cache = FALSE)
ddesonn_ssm_encode(encoder, sequence_data, fit_scale = FALSE)
ddesonn_ssm_backward(encoder, cache, grad_embedding)
Arguments
sequence_features |
Number of input channels in each sequence. |
state_dim |
Number of encoder state dimensions. |
conv_width |
Width of the causal convolution. |
seed |
Optional seed for parameter initialization. |
encoder |
Encoder returned by |
state |
Optional replacement state, or |
sequence_data |
Numeric array with dimensions samples by timesteps by channels. |
return_cache |
Whether to return intermediate values needed by the backward pass. |
fit_scale |
Whether to fit scaling statistics on these sequences. |
cache |
Forward-pass cache returned with |
grad_embedding |
Per-sample embedding gradients before averaging over samples. |
Details
The encoder is experimental and opt-in; sequence_encoder = "none" is the
default. The backward pass takes per-sample embedding gradients before sample
averaging and returns parameter and input gradients averaged over samples.
For mean squared error across states, supply twice the embedding residual
divided by the number of states; do not also divide by the sample count.
Encoding and supervised encoder training reuse identical sequence windows.
Scaling statistics and the mean-loss gradient retain the original sample
multiplicities, including different labels attached to the same window.
Value
An encoder, forward result, gradient list, or embedding matrix, depending on the function called.
Predict method for DDESONN models
Description
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.
Usage
## 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,
sequence_data = NULL,
sequence_length = 48L,
ssm_state_dim = 16L,
ssm_conv = 4L
)
Arguments
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. |
sequence_data |
Aligned samples by timesteps by channels sequence array. |
sequence_length |
Number of timesteps per sequence window. |
ssm_state_dim |
Number of encoder state dimensions. |
ssm_conv |
Width of the encoder's causal convolution. |
Print a summary of a DDESONN run result
Description
Print a summary of a DDESONN run result
Usage
## S3 method for class 'ddesonn_run_result'
print(x, ...)
Arguments
x |
A |
... |
Unused. |
Value
x, invisibly.