| 117 | } |
| 118 | |
| 119 | pub fn aggregate_regression_mean(per_model_predictions: &[Vec<f64>]) -> Result<Vec<f64>, String> { |
| 120 | if per_model_predictions.is_empty() { |
| 121 | return Err("per_model_predictions cannot be empty".to_string()); |
| 122 | } |
| 123 | let n = per_model_predictions[0].len(); |
| 124 | if n == 0 { |
| 125 | return Err("prediction rows cannot be empty".to_string()); |
| 126 | } |
| 127 | if per_model_predictions.iter().any(|row| row.len() != n) { |
| 128 | return Err("prediction length mismatch".to_string()); |
| 129 | } |
| 130 | |
| 131 | let mut out = vec![0.0; n]; |
| 132 | for row in per_model_predictions { |
| 133 | for (i, v) in row.iter().enumerate() { |
| 134 | out[i] += *v; |
| 135 | } |
| 136 | } |
| 137 | let denom = per_model_predictions.len() as f64; |
| 138 | for v in &mut out { |
| 139 | *v /= denom; |
| 140 | } |
| 141 | Ok(out) |
| 142 | } |
| 143 | |
| 144 | pub fn aggregate_classification_vote(per_model_predictions: &[Vec<u8>]) -> Result<Vec<u8>, String> { |
| 145 | if per_model_predictions.is_empty() { |