converge_analytics/packs/regression/
types.rs1use converge_pack::gate::GateResult as Result;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct RegressionInput {
6 pub records: Vec<Vec<f64>>,
7 pub weights: Vec<f64>,
8 pub bias: f64,
9}
10
11impl RegressionInput {
12 pub fn validate(&self) -> Result<()> {
13 if self.records.is_empty() {
14 return Err(converge_pack::GateError::invalid_input(
15 "At least one record required",
16 ));
17 }
18 let dim = self.weights.len();
19 if dim == 0 {
20 return Err(converge_pack::GateError::invalid_input(
21 "At least one weight (feature) required",
22 ));
23 }
24 for (i, record) in self.records.iter().enumerate() {
25 if record.len() != dim {
26 return Err(converge_pack::GateError::invalid_input(format!(
27 "Record {} has {} features, expected {}",
28 i,
29 record.len(),
30 dim
31 )));
32 }
33 }
34 Ok(())
35 }
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct PredictedValue {
40 pub index: usize,
41 pub value: f64,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct RegressionOutput {
46 pub predictions: Vec<PredictedValue>,
47 pub mean_prediction: f64,
48 pub std_prediction: f64,
49 pub total: usize,
50}
51
52impl RegressionOutput {
53 pub fn summary(&self) -> String {
54 format!(
55 "Predicted {} values (mean: {:.3}, std: {:.3})",
56 self.total, self.mean_prediction, self.std_prediction,
57 )
58 }
59}