| Title: | Self-Organizing Nebulous Growths for Dimensionality Reduction |
|---|---|
| Description: | A SONG-inspired tool for nonlinear dimensionality reduction and data visualization in R, implementing the Self-Organizing Nebulous Growths (SONG) algorithm of Senanayake et al. (2021) <doi:10.1109/TNNLS.2020.3023941> natively in R and C++ and staying as close to the reference implementation as is feasible across the two ecosystems. SONG is a parametric method that supports incremental addition of new data to existing visualizations without reinitialization, handles both homogeneous and heterogeneous data increments, and is robust to noise and highly mixed clusters. Clustering quality matches the reference closely (validated by reference-parity tests); the default visualization is close in global structure but not identical in absolute layout. Includes an interactive Shiny application for comparing SONG, t-SNE, and UMAP visualizations side-by-side. |
| Authors: | R. Heller [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-8006-9742>), Damith A. Senanayake [cph] (Author of the original SONG algorithm and its BSD-3-Clause Python implementation; see inst/COPYRIGHTS) |
| Maintainer: | R. Heller <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-29 10:32:39 UTC |
| Source: | https://github.com/CTTIR/songR |
Creates a ggplot2 plot of a "song_model" object. Requires
ggplot2 to be installed.
autoplot.song_model( object, type = c("embedding", "codebook", "graph"), color_by = NULL, ... )autoplot.song_model( object, type = c("embedding", "codebook", "graph"), color_by = NULL, ... )
object |
A |
type |
Character. One of |
color_by |
Optional vector for coloring points. |
... |
Ignored. |
A ggplot object.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
if (requireNamespace("ggplot2", quietly = TRUE)) { model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) # Use songR::autoplot.song_model(model, color_by = iris$Species) # or ensure songR is loaded with library(songR) for dispatch }if (requireNamespace("ggplot2", quietly = TRUE)) { model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) # Use songR::autoplot.song_model(model, color_by = iris$Species) # or ensure songR is loaded with library(songR) for dispatch }
Visualize a "song_model" as a scatter plot of the embedding,
the codebook, or the codebook graph with edges.
## S3 method for class 'song_model' plot(x, type = c("embedding", "codebook", "graph"), color_by = NULL, ...)## S3 method for class 'song_model' plot(x, type = c("embedding", "codebook", "graph"), color_by = NULL, ...)
x |
A |
type |
Character. One of |
color_by |
Optional vector (factor or numeric) of length equal to
the number of input points (for |
... |
Additional arguments passed to |
Invisible NULL.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) plot(model, color_by = iris$Species)model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) plot(model, color_by = iris$Species)
Maps new data points into an existing SONG embedding by assigning each point to its nearest coding vector and returning that coding vector's embedding coordinates. This does not train or mutate the model. Multiple points assigned to one prototype have identical coordinates; these coordinates are not physical locations or evidence of contact.
## S3 method for class 'song_model' predict(object, newdata, ..., feature_manifest = NULL)## S3 method for class 'song_model' predict(object, newdata, ..., feature_manifest = NULL)
object |
A trained |
newdata |
Numeric matrix of new data ( |
... |
Ignored. |
feature_manifest |
The unchanged manifest supplied at training, if any.
Named features must follow training order. See |
A numeric matrix (n_new x d) of embedding coordinates.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
model <- song(as.matrix(iris[1:120, 1:4]), epochs = 5L, seed = 42) new_coords <- predict(model, newdata = as.matrix(iris[121:150, 1:4]))model <- song(as.matrix(iris[1:120, 1:4]), epochs = 5L, seed = 42) new_coords <- predict(model, newdata = as.matrix(iris[121:150, 1:4]))
Prints a concise summary of a "song_model" object.
## S3 method for class 'song_model' print(x, ...)## S3 method for class 'song_model' print(x, ...)
x |
A |
... |
Ignored. |
Invisible x.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) print(model)model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) print(model)
Opens a Shiny application that compares SONG, t-SNE, and UMAP visualizations side-by-side on user-supplied or example data. The app features a dark mode toggle (persisted via localStorage), uses the viridis plasma color scale for all plots, and supports uploading custom CSV/RDS data, tuning SONG hyperparameters, running incremental updates, and exporting embeddings.
run_songR_app(launch.browser = TRUE)run_songR_app(launch.browser = TRUE)
launch.browser |
Logical. Whether to open the app in the browser
(default: |
Invisible NULL. The function is called for its side effect
of launching the Shiny app.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
if (interactive()) { run_songR_app() }if (interactive()) { run_songR_app() }
Performs nonlinear dimensionality reduction using the Self-Organizing
Nebulous Growths (SONG) algorithm. SONG builds a codebook of coding
vectors connected by a topology-preserving graph, then maps the graph
into a low-dimensional embedding space. Unlike t-SNE and UMAP, the
resulting model supports incremental updates with new data via
update.song_model.
song( X, d = 2L, k = 3L, epsilon = 0.9, epochs = 50L, alpha = 1, a = 1.577, b = 0.895, spread_factor = 0.5, neg_sample_rate = 5L, max_age = 3L, e_min = NULL, max_prototypes = NULL, lr_sigma = 5, dispersion = TRUE, seed = NULL, verbose = TRUE, feature_manifest = NULL )song( X, d = 2L, k = 3L, epsilon = 0.9, epochs = 50L, alpha = 1, a = 1.577, b = 0.895, spread_factor = 0.5, neg_sample_rate = 5L, max_age = 3L, e_min = NULL, max_prototypes = NULL, lr_sigma = 5, dispersion = TRUE, seed = NULL, verbose = TRUE, feature_manifest = NULL )
X |
Numeric matrix of input data ( |
d |
Integer. Output dimensionality (default: 2). |
k |
Integer. Neighborhood size for the coding-vector graph.
Corresponds to |
epsilon |
Numeric. Edge decay rate, in |
epochs |
Integer. Number of self-organisation iterations
(default: 50, matching Python's |
alpha |
Numeric. Initial SO learning rate (default: 1.0). |
a |
Numeric. Rational-quadratic kernel parameter (default: 1.577,
from |
b |
Numeric. Rational-quadratic kernel parameter (default: 0.895). |
spread_factor |
Numeric. Controls growth threshold
|
neg_sample_rate |
Integer. Number of negative samples per positive edge during repulsion (default: 5). |
max_age |
Integer. Controls automatic edge pruning: edges weaker
than |
e_min |
Numeric or |
max_prototypes |
Integer or |
lr_sigma |
Numeric. Decay constant for the SO learning-rate
schedule: |
dispersion |
Logical. If |
seed |
Integer or |
verbose |
Logical. Whether to print progress per epoch (default: TRUE). |
feature_manifest |
Optional data frame with exactly these character
columns, in order: |
Named training columns are bound in exact order and must also be named in prediction and updates. An explicit manifest must be supplied again, unchanged, to predict or update a model trained with one. Missing/nonfinite measurements are rejected; no feature is silently reordered or imputed. Unnamed training data retains positional compatibility and cannot verify feature semantics. Legacy models without a contract also retain positional behavior.
An S3 object of class "song_model" containing:
Embedding coordinates of coding vectors (n_coding x d).
Coding vectors (n_coding x D).
Directed adjacency matrix (n_coding x n_coding).
Symmetric adjacency matrix.
Integer vector of length n: nearest CV index.
Embedding coordinates for all input points (n x d).
List of all hyperparameters used.
Versioned feature order, declared metadata and missing-value policy.
Projection version, parent identifier and reprojection policy.
Number of epochs actually run.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
update.song_model, predict.song_model,
plot.song_model
model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) plot(model, color_by = iris$Species)model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) plot(model, color_by = iris$Species)
A list containing a simulated dataset of 1600 points in 20 dimensions, organized into 8 Gaussian clusters. Designed for benchmarking and demonstrating dimensionality reduction methods.
songR_blobssongR_blobs
A list with three elements:
Numeric matrix (1600 x 20) of simulated features.
Factor of length 1600 indicating cluster membership.
Character string describing the dataset.
Simulated data inspired by the experimental setup in Senanayake et al. (2021) doi:10.1109/TNNLS.2020.3023941.
data(songR_blobs) str(songR_blobs)data(songR_blobs) str(songR_blobs)
Provides a detailed summary of a "song_model" object, including
quantization error and edge statistics.
## S3 method for class 'song_model' summary(object, ...)## S3 method for class 'song_model' summary(object, ...)
object |
A |
... |
Ignored. |
Invisible object.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) summary(model)model <- song(as.matrix(iris[, 1:4]), epochs = 5L, seed = 42) summary(model)
Adds new data to an existing SONG model. This is the key differentiator
of SONG over t-SNE and UMAP: training continues from the existing model.
Coding vectors, edges and embedding positions may change. The supplied
object is unchanged; use predict.song_model() for frozen projection.
## S3 method for class 'song_model' update( object, X_new, epochs = 50L, alpha = NULL, verbose = TRUE, ..., feature_manifest = NULL, seed = NULL )## S3 method for class 'song_model' update( object, X_new, epochs = 50L, alpha = NULL, verbose = TRUE, ..., feature_manifest = NULL, seed = NULL )
object |
A |
X_new |
Numeric matrix of new data ( |
epochs |
Integer. Number of additional training epochs (default: 50). |
alpha |
Numeric or |
verbose |
Logical. Whether to print progress (default: TRUE). |
... |
Ignored. |
feature_manifest |
The unchanged manifest supplied at training, if any.
Named features must follow training order. See |
seed |
Optional integer seed for update training. |
lineage schema 1.0.0 records a revision, a deterministic SHA-256 model
identifier and its parent identifier. Identifiers bind the ordered projection
codebook, coordinates, feature contract and revision ancestry, not the full
training history or authenticity of a manually modified object.
Each update requires reprojection of all earlier observations with the new
model before combining coordinates. Earlier input rows are not retained or
automatically reprojected. Initial revisions start at 1. Updates to legacy
models start a new revision history at 1 with parent_history set to
legacy_unversioned and a parent projection fingerprint. Save the model
together with any exported projection to retain its version.
Coincident embedding positions reflect prototype assignment; they do not
establish cell contact or physical spatial distance.
An updated "song_model" object with grown codebook
incorporating the new data. embedding and assignments describe only
X_new; n_input counts all training rows across updates.
Senanayake, D. A., Wang, W., Naik, S. H., & Halgamuge, S. (2021). Self-Organizing Nebulous Growths for Robust and Incremental Data Visualization. IEEE Transactions on Neural Networks and Learning Systems, 32(10), 4588–4602. doi:10.1109/TNNLS.2020.3023941
model <- song(as.matrix(iris[1:100, 1:4]), epochs = 5L, seed = 42) model <- update(model, as.matrix(iris[101:150, 1:4]), epochs = 5L)model <- song(as.matrix(iris[1:100, 1:4]), epochs = 5L, seed = 42) model <- update(model, as.matrix(iris[101:150, 1:4]), epochs = 5L)