From 58964ceb414c1169e82314fe3eac4b68b555aa5e Mon Sep 17 00:00:00 2001 From: lluni Date: Sun, 15 Jan 2023 23:54:16 +0100 Subject: [PATCH] Optimized MSE --- src/functions/loss_functions.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/functions/loss_functions.rs b/src/functions/loss_functions.rs index 40cbc8d..5f15e6e 100644 --- a/src/functions/loss_functions.rs +++ b/src/functions/loss_functions.rs @@ -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, ArrayView1) -> f64, fn(A pub fn mse(y_true: ArrayView1, y_pred: ArrayView1) -> 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();