Optimized MSE

This commit is contained in:
lluni 2023-01-15 23:54:16 +01:00
parent cd47bd7d12
commit 58964ceb41
Signed by: lluni
GPG key ID: ACEEB468BC325D35

View file

@ -1,5 +1,3 @@
use std::ops::MulAssign;
use ndarray::{Array1, ArrayView1};
pub enum Type {
@ -16,7 +14,7 @@ pub fn parse_type(t: Type) -> (fn(ArrayView1<f64>, ArrayView1<f64>) -> f64, fn(A
pub fn mse(y_true: ArrayView1<f64>, y_pred: ArrayView1<f64>) -> f64 {
let mut temp = &y_true - &y_pred;
temp.mul_assign(&temp.clone());
temp.mapv_inplace(|x| x * x);
let mut sum = 0.0;
for i in 0..temp.len() {
sum += temp.get(i).unwrap();