concision_core/loss/traits/
standard.rs1pub trait MeanAbsoluteError {
13    type Output;
14
15    fn mae(&self) -> Self::Output;
16}
17pub trait MeanSquaredError {
24    type Output;
25
26    fn mse(&self) -> Self::Output;
27}
28
29use ndarray::{ArrayBase, Data, Dimension, ScalarOperand};
34use num_traits::{Float, FromPrimitive};
35
36impl<A, S, D> MeanAbsoluteError for ArrayBase<S, D>
37where
38    A: Float + FromPrimitive + ScalarOperand,
39    D: Dimension,
40    S: Data<Elem = A>,
41{
42    type Output = A;
43
44    fn mae(&self) -> Self::Output {
45        self.abs().mean().unwrap()
46    }
47}
48
49impl<A, S, D> MeanSquaredError for ArrayBase<S, D>
50where
51    A: Float + FromPrimitive + ScalarOperand,
52    D: Dimension,
53    S: Data<Elem = A>,
54{
55    type Output = A;
56
57    fn mse(&self) -> Self::Output {
58        self.pow2().mean().unwrap()
59    }
60}