| Title: | Unified Simulation of Isomorphisms Between Ant Colony Intelligence and Machine Learning |
|---|---|
| Description: | Implements the full suite of simulation, visualization, and analysis tools for exploring the mathematical isomorphisms between ant colony decision-making and three major paradigms of machine learning: random forests (Part I: variance reduction through decorrelation), boosting (Part II: bias reduction through adaptive recruitment), and neural networks (Part III: gradient-based generational learning). Accompanies the trilogy "Isomorphic Functionalities between Ant Colony and Ensemble Learning" (Fokoué, Babbitt, and Levental, 2026, <doi:10.48550/arXiv.2603.20328>, <doi:10.48550/arXiv.2604.00038>). |
| Authors: | Yuval Levental [aut, cre], Gregory Babbitt [aut], Ernest Fokoué [aut] |
| Maintainer: | Yuval Levental <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-22 08:48:40 UTC |
| Source: | https://github.com/ylevental/isomorphismsim_full |
Implements the full suite of simulation, visualization, and analysis tools for exploring the mathematical isomorphisms between ant colony intelligence and three major paradigms of machine learning: random forests (Part I), boosting (Part II), and neural networks (Part III).
generate_regression_dataSynthetic regression data
simulate_ant_colonyAgent-based colony simulation
within_colony_correlationPairwise ant correlation
variance_decomposition_experimentRF variance decomposition
colony_variance_experimentColony variance decomposition
isomorphism_testDirect isomorphism comparison
optimal_decorrelation_experimentOptimal theta sweep
sensitivity_analysisRobustness across conditions
create_isomorphism_schematicFigure 1: schematic
plot_variance_decompositionFigure 2: variance
plot_correlation_decayFigure 3: correlation decay
plot_optimal_decorrelationFigure 4: optimal theta
plot_sensitivity_heatmapFigure 5: sensitivity
generate_classification_dataSynthetic classification data
adaboostAdaBoost with decision stumps
predict_adaboostPredict from AdaBoost ensemble
acarAnt Colony Adaptive Recruitment
calculate_marginsBoosting margin computation
calculate_quorum_marginColony quorum margin
weak_learnability_experimentWeak learnability test
convergence_experiment_boostConvergence comparison
noise_experiment_boostNoise robustness comparison
plot_weak_learnabilityFigure 1: weak learnability
plot_weight_pheromoneFigure 2: weight/pheromone
plot_margin_quorumFigure 3: margin/quorum
plot_convergence_boostFigure 4: convergence
plot_noise_robustness_boostFigure 5: noise
generate_synthetic_dataSynthetic data with complexity
gaclGenerational Ant Colony Learning
simple_neural_networkSingle-layer neural network
plot_isomorphismFigure 1: gradient isomorphism
plot_learning_curvesFigure 2: learning curves
plot_pheromone_weightFigure 3: pheromone/weight
plot_learning_rate_sensitivityFigure 4: LR sensitivity
plot_noise_robustness_nnFigure 5: noise robustness
plot_convergence_complexityFigure 6: complexity
plot_gradient_dynamicsFigure 7: gradient dynamics
plot_plasticityFigure 8: plasticity/adaptation
launch_appInteractive explorer (Part I or Part II)
Maintainer: Yuval Levental [email protected]
Authors:
Gregory Babbitt [email protected]
Ernest Fokoué [email protected]
Useful links:
Report bugs at https://github.com/ylevental/IsomorphismSim_Full/issues
Simulates the adaptive recruitment dynamics of an ant colony, implementing Algorithm 3 (ACAR) from the Part II manuscript.
acar( site_qualities, n_ants = 50, n_waves = 100, rho = 0.1, gamma = 0.5, alpha = 1, beta = 1, noise_sd = 0.5, early_stop = TRUE )acar( site_qualities, n_ants = 50, n_waves = 100, rho = 0.1, gamma = 0.5, alpha = 1, beta = 1, noise_sd = 0.5, early_stop = TRUE )
site_qualities |
Numeric vector of true site qualities. |
n_ants |
Number of ants released per wave. |
n_waves |
Maximum number of recruitment waves. |
rho |
Evaporation rate in |
gamma |
Pheromone deposition rate. |
alpha |
Pheromone influence exponent. |
beta |
Heuristic influence exponent. |
noise_sd |
Standard deviation of observation noise. |
early_stop |
Logical; stop early when consensus is reached. |
A list with:
Matrix (waves x K) of pheromone concentrations.
Vector of colony fitness per wave.
Integer vector of colony decisions per wave.
Index of the chosen site.
Implements the AdaBoost algorithm using decision stumps as weak learners, following Freund & Schapire (1997).
adaboost(X, y, M = 100)adaboost(X, y, M = 100)
X |
Numeric matrix of predictors (n x p). |
y |
Numeric vector of labels in {-1, +1}. |
M |
Integer number of boosting iterations. |
A list with components models (list of stumps),
alpha (learner weights), and weight_history (M x n matrix
of instance weights at each iteration).
Computes the normalized margin of each training instance.
calculate_margins(result, X, y)calculate_margins(result, X, y)
result |
Output of |
X |
Predictor matrix. |
y |
Label vector. |
Numeric vector of margins.
Computes the normalized pheromone margin between the best and second-best sites, analogous to boosting margins.
calculate_quorum_margin(result)calculate_quorum_margin(result)
result |
Output of |
Numeric scalar: the quorum margin.
Sweeps colony size and exploration probability, computing decision accuracy and the empirical variance/correlation of ant assessments.
colony_variance_experiment( n_ants_values = c(10, 20, 30, 50, 100), p_explore_values = seq(0, 1, by = 0.2), n_replicates = 50, n_sites = 5, site_qualities = c(10, 8, 6, 4, 2) )colony_variance_experiment( n_ants_values = c(10, 20, 30, 50, 100), p_explore_values = seq(0, 1, by = 0.2), n_replicates = 50, n_sites = 5, site_qualities = c(10, 8, 6, 4, 2) )
n_ants_values |
Integer vector of colony sizes |
p_explore_values |
Numeric vector of exploration probabilities |
n_replicates |
Monte Carlo replicates |
n_sites |
Number of candidate nest sites |
site_qualities |
True site quality vector |
A data.frame with columns n_ants, p_explore, accuracy_mean,
accuracy_sd, var_mean, cor_mean
Compares convergence of AdaBoost and ACAR across iterations. For AdaBoost: test-set accuracy using first m iterations. For ACAR: P(correct final decision) using m waves, averaged across independent replicates.
convergence_experiment_boost( n_boost_reps = 30, n_acar_reps = 200, max_iters = 80, verbose = TRUE )convergence_experiment_boost( n_boost_reps = 30, n_acar_reps = 200, max_iters = 80, verbose = TRUE )
n_boost_reps |
Number of Monte Carlo replicates for AdaBoost. |
n_acar_reps |
Number of Monte Carlo replicates for ACAR. |
max_iters |
Maximum iterations / waves. |
verbose |
Logical; if |
A data.frame with columns iteration, accuracy,
system, and rep.
Plots theoretical alongside empirical
values from both random forest and ant colony experiments.
create_isomorphism_schematic(rf_results, colony_results)create_isomorphism_schematic(rf_results, colony_results)
rf_results |
Output of |
colony_results |
Output of |
A ggplot object
Searches over all features and thresholds to find the stump that minimizes the weighted classification error.
find_best_stump(X, y, D)find_best_stump(X, y, D)
X |
Numeric matrix of predictors. |
y |
Label vector in {-1, +1}. |
D |
Weight vector (sums to 1). |
A list describing the best stump: feature, threshold,
and direction.
Implements the full GACL algorithm with configurable parameters. Pheromone evolution across generations follows update equations isomorphic to stochastic gradient descent.
gacl( site_qualities, n_ants = 100, n_generations = 50, n_waves = 10, rho_wave = 0.3, rho_gen = 0.1, gamma = 0.5, alpha = 1, beta = 1, noise_sd = 0.2 )gacl( site_qualities, n_ants = 100, n_generations = 50, n_waves = 10, rho_wave = 0.3, rho_gen = 0.1, gamma = 0.5, alpha = 1, beta = 1, noise_sd = 0.2 )
site_qualities |
Numeric vector of true qualities for K sites. |
n_ants |
Number of ants per generation (default 100). |
n_generations |
Number of generations to simulate (default 50). |
n_waves |
Number of recruitment waves per generation (default 10). |
rho_wave |
Within-generation evaporation rate (default 0.3). |
rho_gen |
Between-generation evaporation rate, analogous to the
learning rate |
gamma |
Pheromone deposition rate (default 0.5). |
alpha |
Pheromone influence exponent (default 1). |
beta |
Heuristic influence exponent (default 1). |
noise_sd |
Standard deviation of observation noise (default 0.2). |
A list with components:
Matrix (generations x K) of pheromone levels.
Numeric vector of colony fitness per generation.
Numeric vector of negative fitness (loss analog).
Integer vector; best site per generation.
Best site at the last generation.
result <- gacl(c(10, 7, 5, 4, 3), n_generations = 30) plot(result$fitness_history, type = "l")result <- gacl(c(10, 7, 5, 4, 3), n_generations = 30) plot(result$fitness_history, type = "l")
Runs all experiments and saves Figures 1–5 as PDFs in the specified output directory.
generate_all_figures(output_dir, verbose = TRUE)generate_all_figures(output_dir, verbose = TRUE)
output_dir |
Path to directory for saved figures. No default is
provided to avoid writing to the user's home filespace; use
|
verbose |
Logical; if |
Invisible NULL. Figures are saved as side effects.
Creates a binary classification problem where the true boundary
depends on the first three features: ,
with optional label noise.
generate_classification_data(n = 500, p = 10, noise = 0.2)generate_classification_data(n = 500, p = 10, noise = 0.2)
n |
Number of observations. |
p |
Number of features. |
noise |
Fraction of labels flipped. |
A list with X (n x p matrix), y (label vector), and
true_labels.
Creates data with a known sparse signal (first 5 features active) and controllable signal-to-noise ratio. Used to benchmark both random forest and ant colony simulation experiments.
generate_regression_data(n = 1000, p = 50, signal_strength = 1, noise_sd = 1)generate_regression_data(n = 1000, p = 50, signal_strength = 1, noise_sd = 1)
n |
Number of observations |
p |
Number of features |
signal_strength |
Multiplier for the true signal |
noise_sd |
Standard deviation of additive Gaussian noise |
A list with components:
A data.frame of features (n rows, p columns)
Numeric response vector
True function values (without noise)
d <- generate_regression_data(n = 200, p = 20, signal_strength = 2, noise_sd = 1) plot(d$f_true, d$y, xlab = "True signal", ylab = "Observed response")d <- generate_regression_data(n = 200, p = 20, signal_strength = 2, noise_sd = 1) plot(d$f_true, d$y, xlab = "True signal", ylab = "Observed response")
Creates a binary classification dataset with a non-linear decision boundary whose complexity can be varied.
generate_synthetic_data(n = 1000, p = 5, noise = 0.1, complexity = 2)generate_synthetic_data(n = 1000, p = 5, noise = 0.1, complexity = 2)
n |
Number of samples (default 1000). |
p |
Number of features (default 5). |
noise |
Label-flip noise rate, between 0 and 0.5 (default 0.1). |
complexity |
Complexity of the boundary: 1 = linear, 2 = quadratic, 3 = complex with interactions (default 2). |
A list with components X (matrix), y (labels with
noise), and true_labels.
d <- generate_synthetic_data(n = 500, p = 5, complexity = 2) table(d$y)d <- generate_synthetic_data(n = 500, p = 5, complexity = 2) table(d$y)
Runs random forest and ant colony under matched values
(m_try/p = p_explore) and compares the resulting pairwise
correlation and ensemble variance.
isomorphism_test(n_replicates = 50, p_vals = c(0.1, 0.3, 0.5, 0.7, 0.9))isomorphism_test(n_replicates = 50, p_vals = c(0.1, 0.3, 0.5, 0.7, 0.9))
n_replicates |
Monte Carlo replicates per |
p_vals |
Numeric vector of |
A data.frame with theta, system, correlation, cor_sd,
ensemble_var, var_sd
Opens an interactive Shiny application for exploring the ant colony / machine learning isomorphisms.
launch_app(part = c("part1", "part2"), ...)launch_app(part = c("part1", "part2"), ...)
part |
Which part of the trilogy to explore: |
... |
Additional arguments passed to |
No return value, called for side effects (launches a Shiny app).
if (interactive()) launch_app("part1") if (interactive()) launch_app("part2")if (interactive()) launch_app("part1") if (interactive()) launch_app("part2")
Compares how AdaBoost and ACAR degrade under increasing noise. Both systems are measured as P(correct) across independent replicates. Parameters are calibrated so both show visible, parallel degradation.
noise_experiment_boost( noise_levels = seq(0, 0.45, by = 0.05), n_replicates = 50, verbose = TRUE )noise_experiment_boost( noise_levels = seq(0, 0.45, by = 0.05), n_replicates = 50, verbose = TRUE )
noise_levels |
Numeric vector of noise fractions (0 to 0.45). |
n_replicates |
Number of Monte Carlo replicates per level. |
verbose |
Logical; if |
A data.frame with columns noise, accuracy, and
system.
Sweeps ensemble size and to find the performance-optimal
decorrelation parameter. Uses MSE for random forests and 1-accuracy
for ant colonies so both metrics point downward.
optimal_decorrelation_experiment( ensemble_sizes = c(10, 30, 100), theta_values = seq(0.1, 0.9, by = 0.1), n_replicates = 30 )optimal_decorrelation_experiment( ensemble_sizes = c(10, 30, 100), theta_values = seq(0.1, 0.9, by = 0.1), n_replicates = 30 )
ensemble_sizes |
Integer vector of ensemble sizes |
theta_values |
Numeric vector of |
n_replicates |
Monte Carlo replicates |
A data.frame with M, theta, system, performance, se
Supplementary: Colony Accuracy vs Size
plot_colony_accuracy(colony_results)plot_colony_accuracy(colony_results)
colony_results |
Output of |
A ggplot object
Plot Figure 4: Convergence Rates
plot_convergence_boost(results)plot_convergence_boost(results)
results |
Output of |
A ggplot object.
Three-panel plot showing convergence for linear, quadratic, and complex decision boundaries.
plot_convergence_complexity(n_replicates = 15, n_generations = 50)plot_convergence_complexity(n_replicates = 15, n_generations = 50)
n_replicates |
Replicates per complexity (default 15). |
n_generations |
Generations/epochs (default 50). |
Invisibly, NULL.
Figure 3: Correlation Decay Comparison
plot_correlation_decay(iso_results)plot_correlation_decay(iso_results)
iso_results |
Output of |
A ggplot object
Two-panel plot comparing the error signal and gradient magnitude in both systems.
plot_gradient_dynamics(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50)plot_gradient_dynamics(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50)
site_qualities |
Numeric vector of site qualities. |
n_generations |
Generations/epochs (default 50). |
Invisibly, a list with both results.
Runs one GACL and one neural-network simulation and overlays their normalised error/loss trajectories.
plot_isomorphism(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50, ...)plot_isomorphism(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50, ...)
site_qualities |
Numeric vector of site qualities (default
|
n_generations |
Number of generations/epochs (default 50). |
... |
Additional graphical parameters passed to |
Invisibly, a list with the GACL and NN results.
Runs multiple GACL and neural-network replicates, plots individual traces, mean curves, and SE ribbons.
plot_learning_curves( site_qualities = c(10, 7, 5, 4, 3), n_replicates = 20, n_generations = 50, ... )plot_learning_curves( site_qualities = c(10, 7, 5, 4, 3), n_replicates = 20, n_generations = 50, ... )
site_qualities |
Numeric vector of site qualities. |
n_replicates |
Number of independent replicates (default 20). |
n_generations |
Number of generations/epochs (default 50). |
... |
Additional graphical parameters. |
Invisibly, a list with gacl_mat and nn_mat.
Sweeps the evaporation rate / learning rate and plots final normalised performance for both systems with error bars.
plot_learning_rate_sensitivity( site_qualities = c(10, 7, 5, 4, 3), learning_rates = c(0.02, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5), n_replicates = 15, n_generations = 30 )plot_learning_rate_sensitivity( site_qualities = c(10, 7, 5, 4, 3), learning_rates = c(0.02, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5), n_replicates = 15, n_generations = 30 )
site_qualities |
Numeric vector of site qualities. |
learning_rates |
Numeric vector of rates to test. |
n_replicates |
Replicates per rate (default 15). |
n_generations |
Generations/epochs per run (default 30). |
Invisibly, a data frame of summary statistics.
Plot Figure 3: Margin vs Quorum
plot_margin_quorum(boost_result, X, y, acar_result)plot_margin_quorum(boost_result, X, y, acar_result)
boost_result |
Output of |
X |
Predictor matrix used in boosting. |
y |
Label vector used in boosting. |
acar_result |
Output of |
A combined patchwork plot.
Plot Figure 5: Noise Robustness
plot_noise_robustness_boost(results)plot_noise_robustness_boost(results)
results |
Output of |
A ggplot object.
Sweeps noise levels and compares degradation in both systems.
plot_noise_robustness_nn( site_qualities = c(10, 7, 5, 4, 3), noise_levels = seq(0, 0.5, by = 0.05), n_replicates = 15 )plot_noise_robustness_nn( site_qualities = c(10, 7, 5, 4, 3), noise_levels = seq(0, 0.5, by = 0.05), n_replicates = 15 )
site_qualities |
Numeric vector of site qualities. |
noise_levels |
Numeric vector of noise levels to test. |
n_replicates |
Replicates per level (default 15). |
Invisibly, a summary data frame.
Figure 4: Optimal Decorrelation
plot_optimal_decorrelation(optimal_results)plot_optimal_decorrelation(optimal_results)
optimal_results |
Output of |
A ggplot object
Two-panel plot comparing the evolution of pheromone concentrations across sites with the evolution of representative neural-network weights across epochs.
plot_pheromone_weight(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50)plot_pheromone_weight(site_qualities = c(10, 7, 5, 4, 3), n_generations = 50)
site_qualities |
Numeric vector of site qualities. |
n_generations |
Number of generations/epochs (default 50). |
Invisibly, the GACL result.
Simulates an environmental shift at the midpoint and compares the recovery dynamics of both systems.
plot_plasticity(n_replicates = 15)plot_plasticity(n_replicates = 15)
n_replicates |
Replicates (default 15). |
Invisibly, NULL.
Figure 5: Sensitivity Heat-map
plot_sensitivity_heatmap(sensitivity_results)plot_sensitivity_heatmap(sensitivity_results)
sensitivity_results |
Output of |
A ggplot object
Side-by-side panels showing (A) correlation vs m_try/p and
(B) theoretical vs empirical ensemble variance.
plot_variance_decomposition(rf_results)plot_variance_decomposition(rf_results)
rf_results |
Output of |
A combined ggplot (via ggpubr::ggarrange)
Plot Figure 1: Weak Learnability Theorem
plot_weak_learnability(results)plot_weak_learnability(results)
results |
Output of |
A ggplot object.
Plot Figure 2: Weight vs Pheromone Evolution
plot_weight_pheromone(boost_result, acar_result, site_qualities)plot_weight_pheromone(boost_result, acar_result, site_qualities)
boost_result |
Output of |
acar_result |
Output of |
site_qualities |
Numeric vector used in the ACAR call. |
A combined patchwork plot.
Predict with an AdaBoost Ensemble
predict_adaboost(result, X, up_to = NULL)predict_adaboost(result, X, up_to = NULL)
result |
Output of |
X |
Numeric predictor matrix. |
up_to |
Optional integer; use only the first |
Numeric prediction vector in {-1, +1}.
Predict with a Decision Stump
predict_stump(stump, X)predict_stump(stump, X)
stump |
A stump list from |
X |
Numeric predictor matrix. |
Numeric prediction vector in {-1, +1}.
Tests whether the isomorphism holds under varying signal strengths,
noise levels, and values.
sensitivity_analysis( signal_strengths = c(0.5, 1, 2, 5), noise_levels = c(0.5, 1, 2, 4), n_replicates = 20 )sensitivity_analysis( signal_strengths = c(0.5, 1, 2, 5), noise_levels = c(0.5, 1, 2, 4), n_replicates = 20 )
signal_strengths |
Numeric vector of signal multipliers |
noise_levels |
Numeric vector of noise standard deviations |
n_replicates |
Monte Carlo replicates |
A data.frame with signal, noise, theta, system,
correlation, cor_sd
Runs AdaBoost and ant colony adaptive recruitment in parallel.
sim_boost_recruitment(n_iterations = 100, n_ants = 50, n_sites = 10, evaporation_rate = 0.1, noise_level = 0.15, n_rep = 100)sim_boost_recruitment(n_iterations = 100, n_ants = 50, n_sites = 10, evaporation_rate = 0.1, noise_level = 0.15, n_rep = 100)
n_iterations |
Number of boosting iterations / recruitment waves. |
n_ants |
Number of ants. |
n_sites |
Number of candidate sites. |
evaporation_rate |
Pheromone evaporation rate. |
noise_level |
Noise level for data generation. |
n_rep |
Monte Carlo replicates for convergence curves. |
An S3 object of class "boost_recruitment" with elements
$boost and $colony (numeric learning curves),
and print() and plot() methods.
Tracks the colony's probability estimates over time, demonstrating convergence to the best site via Thompson sampling and recruitment.
sim_colony_convergence(n_ants = 50, n_sites = 5, site_qualities = c(0.9, 0.7, 0.5, 0.3, 0.1), n_steps = 200, p_explore = 0.3)sim_colony_convergence(n_ants = 50, n_sites = 5, site_qualities = c(0.9, 0.7, 0.5, 0.3, 0.1), n_steps = 200, p_explore = 0.3)
n_ants |
Number of ants. |
n_sites |
Number of candidate sites. |
site_qualities |
True quality vector. |
n_steps |
Number of time steps. |
p_explore |
Exploration probability. |
An S3 object of class "colony_convergence" with print()
and plot() methods.
Sweeps the decorrelation parameter theta for both random forests and ant colonies and returns empirical pairwise correlations.
sim_decorrelation(theta_range = seq(0, 1, by = 0.05), n_sites = 20, n_ants = 50, n_trees = 50, n_features = 20, n_rep = 200)sim_decorrelation(theta_range = seq(0, 1, by = 0.05), n_sites = 20, n_ants = 50, n_trees = 50, n_features = 20, n_rep = 200)
theta_range |
Numeric vector of theta values. |
n_sites |
Number of candidate sites (ant colony). |
n_ants |
Number of ants. |
n_trees |
Number of trees. |
n_features |
Number of features (p). |
n_rep |
Monte Carlo replicates per theta. |
An S3 object of class "decorrelation" with print() and
plot() methods.
Simulates generational pheromone evolution alongside neural network training via SGD.
sim_gradient_colony(n_generations = 50, n_ants = 30, n_trails = 10, evaporation_rate = 0.05, learning_rate = 0.05, hidden_units = c(16, 8), task = "classification", n_rep = 50)sim_gradient_colony(n_generations = 50, n_ants = 30, n_trails = 10, evaporation_rate = 0.05, learning_rate = 0.05, hidden_units = c(16, 8), task = "classification", n_rep = 50)
n_generations |
Number of generations / epochs. |
n_ants |
Number of ants per generation. |
n_trails |
Number of trails / sites. |
evaporation_rate |
Pheromone evaporation rate. |
learning_rate |
Neural network learning rate. |
|
Integer vector of hidden layer sizes. |
|
task |
|
n_rep |
Number of replicates for learning curves. |
An S3 object of class "gradient_colony" with elements
$colony and $neural_net (numeric vectors of normalized
performance), and print(), summary(), and plot() methods.
Computes margin distributions for boosting and ant colony quorum decisions.
sim_margin_analysis(n_iterations = 200, n_ants = 100, noise_level = 0.2)sim_margin_analysis(n_iterations = 200, n_ants = 100, noise_level = 0.2)
n_iterations |
Number of boosting iterations. |
n_ants |
Number of ants. |
noise_level |
Noise level. |
An S3 object of class "margin_analysis" with print()
and plot() methods.
Demonstrates neural plasticity / colony adaptation correspondence, with optional environmental shift.
sim_plasticity(n_generations = 300, n_trails = 20, ltp_rate = 0.1, ltd_rate = 0.05, prune_threshold = 0.01, genesis_rate = 0.02, env_shift_at = NULL)sim_plasticity(n_generations = 300, n_trails = 20, ltp_rate = 0.1, ltd_rate = 0.05, prune_threshold = 0.01, genesis_rate = 0.02, env_shift_at = NULL)
n_generations |
Number of generations. |
n_trails |
Number of trails. |
ltp_rate |
Long-term potentiation / reinforcement rate. |
ltd_rate |
Long-term depression / evaporation rate. |
prune_threshold |
Pruning threshold. |
genesis_rate |
New trail formation rate. |
env_shift_at |
Generation at which environment shifts ( |
An S3 object of class "plasticity_sim" with print()
and plot() methods.
Simulates both an ant colony and a random forest across a range of ensemble sizes and correlation levels, validating the variance decomposition formula.
sim_variance_decomp(N_range = c(5, 10, 25, 50, 100), rho_range = seq(0, 1, by = 0.2), sigma2 = 1, n_rep = 500)sim_variance_decomp(N_range = c(5, 10, 25, 50, 100), rho_range = seq(0, 1, by = 0.2), sigma2 = 1, n_rep = 500)
N_range |
Integer vector of ensemble sizes. |
rho_range |
Numeric vector of pairwise correlation levels. |
sigma2 |
Individual unit variance. |
n_rep |
Number of Monte Carlo replicates. |
An S3 object of class "variance_decomp" with print(),
summary(), and plot() methods.
Implements a single-hidden-layer perceptron trained with mini-batch SGD
and binary cross-entropy loss. Under the isomorphism, weight updates
correspond to pheromone updates in gacl().
simple_neural_network( X, y, n_epochs = 50, batch_size = 32, learning_rate = 0.1, n_hidden = 10, validation_split = 0.2 )simple_neural_network( X, y, n_epochs = 50, batch_size = 32, learning_rate = 0.1, n_hidden = 10, validation_split = 0.2 )
X |
Numeric matrix of input features (n x p). |
y |
Numeric vector of labels ({-1, 1} or {0, 1}). |
n_epochs |
Number of training epochs (default 50). |
batch_size |
Mini-batch size (default 32). |
learning_rate |
Learning rate |
|
Number of hidden units (default 10). |
|
validation_split |
Fraction of data held out for validation (default 0.2). |
A list with components:
Numeric vector of training loss per epoch.
Numeric vector of validation loss per epoch.
Numeric vector of validation accuracy per epoch.
Numeric vector of gradient L2 norm per epoch.
List of weight matrices (W1, b1, W2, b2).
d <- generate_synthetic_data(n = 300, p = 5) nn <- simple_neural_network(d$X[1:240, ], d$y[1:240], n_epochs = 30) plot(nn$val_acc, type = "l")d <- generate_synthetic_data(n = 300, p = 5) nn <- simple_neural_network(d$X[1:240, ], d$y[1:240], n_epochs = 30) plot(nn$val_acc, type = "l")
Agent-based simulation of Temnothorax-style nest-site selection. Each ant probabilistically explores or follows pheromone trails, makes noisy observations of site quality, and contributes to recruitment. The colony reaches a decision when recruitment exceeds a quorum threshold.
simulate_ant_colony( n_ants = 50, n_sites = 5, site_qualities = c(10, 8, 6, 4, 2), p_explore = 0.3, n_steps = 100, noise_sd = 2, quorum_threshold = 20, alpha = 0.1, beta = 0.05, gamma = 0.2 )simulate_ant_colony( n_ants = 50, n_sites = 5, site_qualities = c(10, 8, 6, 4, 2), p_explore = 0.3, n_steps = 100, noise_sd = 2, quorum_threshold = 20, alpha = 0.1, beta = 0.05, gamma = 0.2 )
n_ants |
Number of ants in the colony |
n_sites |
Number of candidate nest sites |
site_qualities |
Numeric vector of true site quality values |
p_explore |
Probability that an ant explores independently
(vs following pheromone). This is the decorrelation parameter,
analogous to |
n_steps |
Maximum number of simulation time steps |
noise_sd |
Standard deviation of observation noise |
quorum_threshold |
Recruitment level that triggers a colony decision |
alpha |
Learning rate for pheromone updates |
beta |
Pheromone evaporation rate (0 to 1) |
gamma |
Recruitment strength multiplier |
A list with components:
List of per-step snapshots (pheromone, recruitment, preferences)
Colony-average quality estimates per site
Final recruitment levels per site
Index of chosen site
Matrix of visit counts (n_ants x n_sites)
Matrix of estimated qualities (n_ants x n_sites)
sim <- simulate_ant_colony(n_ants = 30, p_explore = 0.4) cat("Colony chose site", sim$decision, "\n")sim <- simulate_ant_colony(n_ants = 30, p_explore = 0.4) cat("Colony chose site", sim$decision, "\n")
Compares two numeric vectors (e.g. colony fitness and NN loss) using a Kolmogorov-Smirnov test, correlation analysis, or dynamic time warping.
test_isomorphism(ant_result, ml_result, method = c("ks", "correlation", "dtw"))test_isomorphism(ant_result, ml_result, method = c("ks", "correlation", "dtw"))
ant_result |
Numeric vector (colony learning curve). |
ml_result |
Numeric vector (ML learning curve). |
method |
One of |
An S3 object of class "iso_test" with print() and
summary() methods.
Convenience wrapper that returns only the weight history.
track_weights(X, y, M = 50)track_weights(X, y, M = 50)
X |
Predictor matrix. |
y |
Label vector. |
M |
Number of iterations. |
An M x n matrix of instance weights.
Validates that
holds empirically and that varies with m_try/p.
variance_decomposition_experiment( n_train = 500, n_test = 1000, p = 50, m_try_values = c(1, 2, 5, 10, 20, 50), n_trees = 500, n_replicates = 100, signal_strength = 2, noise_sd = 1 )variance_decomposition_experiment( n_train = 500, n_test = 1000, p = 50, m_try_values = c(1, 2, 5, 10, 20, 50), n_trees = 500, n_replicates = 100, signal_strength = 2, noise_sd = 1 )
n_train |
Training set size |
n_test |
Test set size |
p |
Number of features |
m_try_values |
Integer vector of |
n_trees |
Number of trees per forest |
n_replicates |
Number of Monte Carlo replicates |
signal_strength |
Signal multiplier for |
noise_sd |
Noise level for |
A data.frame with columns m_try, rep, rho, sigma2,
ensemble_var, pred_error, theoretical_var
Tests whether gamma-weak ant colonies converge to correct decisions with sufficient recruitment waves, as predicted by Theorem 4. Parameters are calibrated so that small gamma is genuinely hard (slow convergence) while large gamma converges quickly.
weak_learnability_experiment( gamma_values = c(0.05, 0.1, 0.2, 0.3), wave_counts = c(3, 5, 8, 12, 18, 25, 40, 60, 90, 130, 200, 300), n_replicates = 200, verbose = TRUE )weak_learnability_experiment( gamma_values = c(0.05, 0.1, 0.2, 0.3), wave_counts = c(3, 5, 8, 12, 18, 25, 40, 60, 90, 130, 200, 300), n_replicates = 200, verbose = TRUE )
gamma_values |
Numeric vector of weakness parameters. |
wave_counts |
Integer vector of wave counts to test. |
n_replicates |
Number of Monte Carlo replicates per combination. |
verbose |
Logical; if |
A data.frame with columns gamma, waves, rep,
and accuracy.
Measures the mean pairwise correlation between ants' preference vectors
over all candidate sites within a single colony. This is the correct
analogue of tree-tree correlation in a random forest: each ant's
preference vector over sites corresponds to a tree's prediction
vector over test points.
within_colony_correlation(ant_preferences)within_colony_correlation(ant_preferences)
ant_preferences |
An |
Mean pairwise correlation (scalar), or NA if fewer than
2 ants have visited at least 2 sites.
sim <- simulate_ant_colony(n_ants = 30, p_explore = 0.3) within_colony_correlation(sim$ant_preferences)sim <- simulate_ant_colony(n_ants = 30, p_explore = 0.3) within_colony_correlation(sim$ant_preferences)