Temporal-Compare 🕒
A high-performance Rust framework for benchmarking temporal prediction algorithms inspired by OpenAI's Time-R1 architecture.
🎯 What is Temporal-Compare?
Imagine trying to predict the next word you'll type, the next stock price movement, or the next frame in a video. These are temporal prediction tasks - predicting future states from historical sequences. Temporal-Compare provides a testing ground to compare different approaches to this fundamental problem.
This crate implements a clean, extensible framework for comparing:
- Baseline predictors (naive last-value)
- Neural networks (3 MLP variants: Simple, Optimized, Ultra-SIMD)
- RUV-FANN backend (Fast Artificial Neural Network library integration)
- SIMD acceleration (AVX2 intrinsics for 6x speedup)
🏗️ Architecture
┌─────────────────────────────────────────────────────────┐
│ Input Time Series │
│ [t-31, t-30, ..., t-1, t] │
└────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Feature Engineering │
│ • Window: 32 timesteps │
│ • Regime indicators │
│ • Temporal features (time-of-day) │
└────────────────┬────────────────────────────────────────┘
│
┌────────┴────────┬──────────┬──────────┬──────────┐
▼ ▼ ▼ ▼ ▼
┌──────────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Baseline │ │ MLP │ │ MLP-Opt │ │MLP-Ultra │ │ RUV-FANN │
│ Predictor │ │ Simple │ │ Adam │ │ SIMD │ │ Network │
│ │ │ │ │ │ │ │ │ │
│ Last value │ │ Basic │ │ Backprop │ │ AVX2 │ │ Rprop │
└──────┬───────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │ │ │
└───────────────┴──────────────┴──────────────┴──────────────┘
│
▼
┌─────────────────────┐
│ Outputs │
│ • Regression (MSE) │
│ • Classification │
│ (3-class: ↓/→/↑) │
└─────────────────────┘
✨ Features
- 🚀 Blazing Fast: Pure Rust with SIMD acceleration (6x speedup)
- 🧠 5 Backend Options: Baseline, MLP, MLP-Opt, MLP-Ultra, RUV-FANN
- ⚡ AVX2 SIMD: Hardware-accelerated matrix operations
- 🔥 Ultra Performance: 0.5s training for 10k samples (vs 3s baseline)
- 📊 Synthetic Data: Configurable time series with regime shifts and noise
- 🎯 Dual Tasks: Both regression (next value) and classification (trend direction)
- 🔧 CLI Interface: Full control via command-line arguments
- 📈 Built-in Metrics: MSE for regression, accuracy for classification
- 🦀 RUV-FANN Integration: Optional feature flag for FANN backend
🛠️ Technical Details
Data Generation
The synthetic time series follows an autoregressive process with complexity:
x(t) = 0.8 * x(t-1) + drift(regime) + N(0, 0.3) + impulse(t)
where:
- regime ∈ {0, 1} switches with P=0.02
- drift = 0.02 if regime=0, else -0.015
- impulse = +0.9 every 37 timesteps
Neural Network Architecture
- Input Layer: 32 temporal features + 2 engineered features
- Hidden Layer: 64 neurons with ReLU activation
- Output Layer: 1 neuron (regression) or 3 neurons (classification)
- Training: Simplified SGD with numerical gradients
- Initialization: Xavier/He weight initialization
Performance Characteristics (v0.2.0)
| Backend | MSE (Test) | Accuracy | Training Time (10k samples) |
|---|---|---|---|
| Baseline | 0.112 | 64.7% | N/A (no training) |
| MLP | 0.128 | 37.0% | 3.057s |
| MLP-Opt | 0.238 | 42.3% | 2.1s |
| MLP-Ultra | 0.108 | 45.0% | 0.500s (6.1x faster!) |
| RUV-FANN | 0.115 | 62.0% | 1.2s |
💡 Use Cases
- Algorithm Research: Test new temporal prediction methods
- Benchmark Suite: Compare performance across different approaches
- Educational Tool: Learn about time series prediction
- Integration Testing: Validate external ML libraries (ruv-fann)
- Hyperparameter Tuning: Find optimal settings for your domain
- Production Prototyping: Quick proof-of-concept for temporal models
📦 Installation
# Clone the repository
# Build with standard features
# Build with RUV-FANN backend support
# Build with SIMD optimizations (recommended)
RUSTFLAGS="-C target-cpu=native"
🚀 Usage
Basic Regression
# Baseline predictor
# Simple MLP
# Optimized MLP with Adam optimizer
# Ultra-fast SIMD MLP (recommended for performance)
RUSTFLAGS="-C target-cpu=native"
# RUV-FANN backend (requires feature flag)
Classification Task
# 3-class trend prediction (down/neutral/up)
# Compare against baseline
Advanced Options
# Custom window size and seed
# Full parameter control
Benchmarking All Backends
# Run complete comparison with timing
for; do
done
# With RUV-FANN included
for; do
done
📊 Benchmark Results (v0.2.0)
Regression Performance (10,000 samples, 20 epochs)
Backend MSE Training Time Speedup
─────────────────────────────────────────────────
Baseline 0.112 N/A -
MLP 0.128 3.057s 1.0x
MLP-Opt 0.238 2.100s 1.5x
MLP-Ultra 0.108 0.500s 6.1x ← Best!
RUV-FANN 0.115 1.200s 2.5x
Classification Accuracy
Backend Accuracy Notes
────────────────────────────────────
Baseline 64.7% Simple threshold-based
MLP 37.0% Limited by numerical gradients
MLP-Opt 42.3% Improved with backprop
MLP-Ultra 45.0% SIMD-accelerated
RUV-FANN 62.0% Close to baseline
Key Achievements in v0.2.0
- 6.1x speedup with Ultra-MLP (AVX2 SIMD)
- Best MSE: Ultra-MLP matches baseline (0.108)
- Parallel processing: Multi-threaded predictions
- Memory efficient: Cache-optimized layouts
🔬 What's New in v0.2.0
Major Features
- Ultra-MLP Backend: SIMD-accelerated neural network with AVX2
- Optimized-MLP: Full backpropagation with Adam/Momentum optimizers
- RUV-FANN Integration: Complete implementation with feature flag
- 6.1x Performance Boost: From 3s to 0.5s for 10k samples
- Parallel Processing: Multi-threaded batch predictions with Rayon
Technical Improvements
- AVX2 SIMD intrinsics for matrix operations
- Cache-friendly memory layout (row-major flat arrays)
- Vectorized ReLU activation
- Thread-local buffers for parallel execution
- Momentum and Adam optimizers
- Softmax + cross-entropy for classification
🔬 Future Directions
- Add LSTM/GRU: Temporal-specific architectures
- Attention Mechanisms: Transformer-based predictions
- Online Learning: Adaptive weight updates
- Ensemble Methods: Combine multiple predictors
- GPU Acceleration: CUDA/WebGPU backends
- AutoML: Hyperparameter optimization
🤝 Contributing
Contributions welcome! Areas of interest:
- Full backpropagation implementation
- Additional backend integrations
- More sophisticated data generators
- Visualization tools
- Performance optimizations
- Documentation improvements
📚 References
- Time-R1 Architecture - Temporal reasoning systems
- ruv-fann - Rust FANN neural network library
- ndarray - N-dimensional arrays for Rust
👏 Credits
Primary Developer
@ruvnet - Architecture, implementation, and optimization Pioneering work in temporal consciousness mathematics and sublinear algorithms
Acknowledgments
- OpenAI - Inspiration from Time-R1 temporal architectures
- Rust Community - Outstanding ecosystem and tools
- ndarray Contributors - Efficient numerical computing
- Claude/Anthropic - AI-assisted development and testing
Special Thanks
- The Sublinear Solver Project team for theoretical foundations
- Strange Loops framework for consciousness emergence insights
- Temporal Attractor Studio for visualization concepts
📄 License
MIT License - See LICENSE file for details
🔗 Links
- Repository: github.com/ruvnet/sublinear-time-solver
- Issues: GitHub Issues
- Documentation: docs.rs/temporal-compare
- Crates.io: crates.io/crates/temporal-compare