stochasta
Version, currently 0.1.24 versions
- 0.2.0latestJul 3, 2026
- 0.1.2not indexedJul 3, 2026
- 0.1.1not indexedJul 3, 2026
- 0.1.0not indexedJul 3, 2026
github.com/eltony81/stochasta
A fast, lightweight, and dependency-free library for stochastic simulations, metaheuristic global optimization (Genetic Algorithms, PSO, Differential Evolution, ABC, ACO, Simulated Annealing), Bayesian analysis, and unsupervised learning clustering/dimensionality reduction (K-Means, DBSCAN, K-Medoids, Mean Shift, PCA, Hierarchical clustering, Apriori) in pure Crystal.
Nothing has been indexed for 0.1.2 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
stochasta:
github: eltony81/stochasta
version: ~> 0.1.2Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.2. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
Stochasta
Stochasta is a fast, lightweight, and dependency-free Crystal shard providing modular implementations of stochastic, optimization, and unsupervised learning algorithms.
What Stochasta Offers
Stochasta brings powerful stochastic models, nature-inspired search metaheuristics, and unsupervised data science algorithms to the Crystal ecosystem. It offers:
- Metaheuristic Global Optimization: Find global extrema for complex continuous or discrete functions where traditional mathematical optimization fails, using Genetic Algorithms, PSO, Differential Evolution, Artificial Bee Colony, and Simulated Annealing.
- Combinatorial Optimization: Solve routing and sequence-based discrete problems like the Traveling Salesperson Problem (TSP) using Ant Colony Optimization.
- Advanced Clustering Suite: Group data structures using diverse paradigms—centroid partition (K-Means), density reachability (DBSCAN, Mean Shift), representative cluster medoids (K-Medoids), or bottom-up merge trees (Hierarchical Agglomerative Clustering).
- Probabilistic & Bayesian Reasoning: Evaluate Bayes' theorem posterior probability updates and classify multi-class categorical texts using Laplace-smoothed Naive Bayes.
- Dimensionality Reduction: Project complex multi-dimensional datasets to lower dimensions (e.g. for visualization or preprocessing) via Principal Component Analysis (PCA) using a built-in Jacobi eigenvalue decomposition.
- Association Mining: Discover hidden relationships in transactional/shopping databases with the Apriori association rule mining algorithm.
- Stochastic Simulations: Run Monte Carlo sample simulations and numerical multi-dimensional integration.
- Quantitative Finance Suite: Optimize asset weights for minimum variance or maximum Sharpe ratio (solved via built-in PSO), estimate returns with Black-Litterman, measure VaR/CVaR risk, and simulate asset prices using Geometric Brownian Motion.
Features
- Genetic Algorithms (
Stochasta::Genetic): Flexible evolutionary engine with customizable selection (tournament), crossover, mutation, and support for elitism. - Monte Carlo Simulation (
Stochasta::MonteCarlo): Stochastic simulation trials, 1D and multi-dimensional numerical integration. - Particle Swarm Optimization (PSO) (
Stochasta::PSO): Continuous optimization in bounded spaces. - Bayesian Statistics (
Stochasta::Bayes): Categorical Naive Bayes classifiers with Laplace smoothing and Bayesian updating calculators. - K-Means Clustering (
Stochasta::KMeans): Standard iterative K-Means clustering algorithm. - Gaussian Mixture Models (GMM) (
Stochasta::GMM): Soft probability-based clustering trained via Expectation-Maximization. - Hierarchical Clustering (
Stochasta::Hierarchical): Agglomerative clustering supporting Single, Complete, and Average linkages. - K-Medoids (PAM) (
Stochasta::KMedoids): Partitioning Around Medoids using actual dataset points as centroids. - Mean Shift (
Stochasta::MeanShift): Density-based clustering to automatically discover cluster centers. - DBSCAN Clustering (
Stochasta::DBSCAN): Density-based spatial clustering for arbitrary shapes and noise extraction. - Principal Component Analysis (PCA) (
Stochasta::PCA): Unsupervised dimensionality reduction powered by a pure Crystal symmetric Jacobi eigenvalue solver. - Apriori Algorithm (
Stochasta::Apriori): Association rule mining and frequent itemsets locator. - Differential Evolution (DE) (
Stochasta::DifferentialEvolution): Global vector population optimizer for continuous spaces. - Ant Colony Optimization (ACO) (
Stochasta::AntColony): Combinatorial Traveling Salesperson Problem (TSP) solver. - Artificial Bee Colony (ABC) (
Stochasta::ArtificialBeeColony): Swarm-based global optimizer modeled after honey bee foraging. - Simulated Annealing (
Stochasta::SimulatedAnnealing): Probabilistic optimization technique for finding global extrema. - Portfolio Optimization & Quant Finance (
Stochasta::Portfolio): Minimum variance/maximum Sharpe allocation (utilizing built-in PSO), Black-Litterman returns updating, VaR & CVaR risk estimators, and Geometric Brownian Motion path generators.
Installation
-
Add the dependency to your
shard.yml:dependencies: stochasta: github: eltony81/stochasta -
Run
shards install
Usage Examples
Complete, well-commented execution files are available in the examples/ directory:
- genetic_example.cr: Solve a OneMax bitstring optimization problem using Genetic Algorithms.
- monte_carlo_example.cr: Estimate Pi and run 1D/2D numerical integrals.
- pso_example.cr: Find the global minimum of the Rosenbrock function.
- de_example.cr: Optimize continuous dimensions using Differential Evolution.
- aco_example.cr: Solve the Traveling Salesperson Problem (TSP) using Ant Colony System.
- abc_example.cr: Find global minimums using Artificial Bee Colony.
- bayes_example.cr: Run Bayesian inference and classify spam/ham messages.
- clustering_example.cr: Combine PCA dimension reduction, K-Means partitioning, and DBSCAN noise detection.
- gmm_example.cr: Run soft probabilistic clustering with Gaussian Mixture Models.
- hierarchical_example.cr: Cluster data using bottom-up Hierarchical Agglomerative Clustering.
- kmedoids_example.cr: Partition data around medoids chosen from actual points.
- mean_shift_example.cr: Run density-based cluster centroid discovery.
- apriori_example.cr: Mine shopping transaction databases for association rules (Support, Confidence, Lift).
- annealing_example.cr: Probabilistic optimization on continuous mathematical functions.
- portfolio_optimization_example.cr: Perform Markowitz portfolio optimization using PSO.
- black_litterman_example.cr: Estimate adjusted asset returns using the Black-Litterman model.
- risk_metrics_example.cr: Calculate Value at Risk (VaR) and Conditional Value at Risk (CVaR).
- gbm_example.cr: Simulate future stock price paths using Geometric Brownian Motion.
Quick Sample: Naive Bayes Classification
require "stochasta"
# Initialize a Naive Bayes classifier
classifier = Stochasta::Bayes::NaiveClassifier(String, String).new
# Train the model
classifier.train(["buy", "cheap", "deal"], "spam")
classifier.train(["meeting", "project", "deadline"], "ham")
# Predict on new unseen features
label = classifier.predict(["cheap", "deadline"])
puts "Classified as: #{label}"
Running Tests
Stochasta has a comprehensive spec suite. To run the tests, execute:
crystal spec
Contributors
- tony - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.2- Tagged
- Jul 3, 2026
- Commit
c4db3182abec- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/eltony81/stochasta
Metadata
- Created
- Aug 14, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 4