Commit f7609be
committed
feat(training): add comprehensive training infrastructure
Implement complete training pipeline for MLP router and reservoir:
**Training Module** (`src/training.rs`):
- `RouterTrainingData`: Training data collection and management
* add_example(): Add labeled examples
* train_test_split(): 80/20 split with shuffling
* Support for Local/Remote/Hybrid routing decisions
- `MLPTrainer`: Trainer for router MLP
* Mini-batch training with configurable batch size
* Early stopping with patience parameter
* L2 regularization support
* Training metrics tracking (loss, accuracy)
* Confusion matrix generation
* K-fold cross-validation
- `ReservoirTrainer`: Trainer for ESN
* Ridge regression for output weights
* MSE computation for evaluation
- `collect_training_data_from_feedback()`: Extract training data from conversation history (with persistence)
**MLP Enhancements** (`src/mlp.rs`):
- `backward()`: Full backpropagation implementation
* Forward pass with activation tracking
* Cross-entropy loss computation
* Gradient computation via chain rule
* ReLU derivative handling
* Returns (loss, weight_gradients)
- `update()`: Weight update from gradients
* SGD-based update rule
* Learning rate parameter
**Configuration**:
- `MLPTrainingConfig`: Hyperparameter configuration
* learning_rate: 0.01 (default)
* epochs: 100 (default)
* batch_size: 32 (default)
* patience: 10 (early stopping)
* l2_reg: 0.001 (regularization)
**Tests** (5 tests, all passing):
- test_training_data_creation: Data structure
- test_train_test_split: Data splitting
- test_one_hot_encoding: Label encoding
- test_mlp_training: End-to-end MLP training
- test_reservoir_training: ESN training on temporal data
**Integration**:
- Router's extract_features() now public for training use
- Persistence integration for loading historical data
- Cross-validation support for model evaluation
**Stats**:
- 535 lines of training infrastructure
- 103 lines of backprop implementation
- 5 comprehensive tests
- All tests passing
This enables production ML workflows: collect feedback → train models → deploy → iterate1 parent a46276b commit f7609be
4 files changed
Lines changed: 636 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
192 | 297 | | |
193 | 298 | | |
194 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
0 commit comments