Skip to content

Commit

Permalink
replace map with mapv_into again
Browse files Browse the repository at this point in the history
  • Loading branch information
cospectrum committed May 10, 2024
1 parent 4df156f commit f2bcde7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/metrics_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait SingleTargetRegression<F: Float, T: AsSingleTargets<Elem = F>>:
let mut abs_error = self
.as_single_targets()
.sub(&compare_to.as_single_targets())
.mapv(|x| x.abs())
.mapv_into(|x| x.abs())
.to_vec();
abs_error.sort_by(|a, b| a.partial_cmp(b).unwrap());
let mid = abs_error.len() / 2;
Expand All @@ -74,8 +74,8 @@ pub trait SingleTargetRegression<F: Float, T: AsSingleTargets<Elem = F>>:
fn mean_absolute_percentage_error(&self, compare_to: &T) -> Result<F> {
self.as_single_targets()
.sub(&compare_to.as_single_targets())
.div(&self.as_single_targets())
.mapv(|x| x.abs())
.div(self.as_single_targets())
.mapv_into(|x| x.abs())
.mean()
.ok_or(Error::NotEnoughSamples)
}
Expand All @@ -95,7 +95,7 @@ pub trait SingleTargetRegression<F: Float, T: AsSingleTargets<Elem = F>>:
- self
.as_single_targets()
.sub(&single_target_compare_to)
.mapv(|x| x * x)
.mapv_into(|x| x * x)
.sum()
/ (single_target_compare_to
.mapv(|x| (x - mean) * (x - mean))
Expand All @@ -114,7 +114,7 @@ pub trait SingleTargetRegression<F: Float, T: AsSingleTargets<Elem = F>>:
let mean_error = diff.mean().ok_or(Error::NotEnoughSamples)?;

Ok(F::one()
- (diff.mapv(|x| x * x).sum() - mean_error)
- (diff.mapv_into(|x| x * x).sum() - mean_error)
/ (single_target_compare_to
.mapv(|x| (x - mean) * (x - mean))
.sum()
Expand Down

0 comments on commit f2bcde7

Please sign in to comment.