1pub(crate) mod huber;
7pub(crate) mod log_loss;
8pub(crate) mod squared;
9
10pub use huber::HuberLoss;
11pub use log_loss::BinaryLogLoss;
12pub use squared::SquaredError;
13
14#[derive(Debug, Clone, Default)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20#[non_exhaustive]
21pub enum RegressionLoss {
22 #[default]
24 SquaredError,
25 Huber(HuberLoss),
27}
28
29impl RegressionLoss {
30 pub fn loss(&self, prediction: f64, target: f64) -> f64 {
32 match self {
33 RegressionLoss::SquaredError => SquaredError::loss(prediction, target),
34 RegressionLoss::Huber(h) => h.loss(prediction, target),
35 }
36 }
37
38 pub fn gradient(&self, prediction: f64, target: f64) -> f64 {
40 match self {
41 RegressionLoss::SquaredError => SquaredError::gradient(prediction, target),
42 RegressionLoss::Huber(h) => h.gradient(prediction, target),
43 }
44 }
45}