From bea880f4b4260fd0ca0b1d6a627e2c0615c03f79 Mon Sep 17 00:00:00 2001 From: "Klein, Markus" Date: Tue, 15 Nov 2016 17:52:02 +0100 Subject: [PATCH] renamed Vector::mut_at -> at_mut --- src/cost.rs | 8 ++------ src/linear_algebra.rs | 8 ++++---- src/model.rs | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/cost.rs b/src/cost.rs index 63f916e..14dab73 100644 --- a/src/cost.rs +++ b/src/cost.rs @@ -26,11 +26,7 @@ pub struct LeastAbsoluteDeviation; impl Cost for LeastAbsoluteDeviation { fn outer_derivative(&self, prediction: &f64, truth: f64) -> f64 { let error = prediction - truth; - if error == 0.0 { - 0.0 - } else { - error.signum() - } + if error == 0.0 { 0.0 } else { error.signum() } } fn cost(&self, prediction: f64, truth: f64) -> f64 { (prediction - truth).abs() @@ -98,7 +94,7 @@ impl Cost for MaxLikelihood fn outer_derivative(&self, prediction: &V, truth: usize) -> V { let mut derivation = prediction.clone(); for i in 0..prediction.dimension() { - *derivation.mut_at(i) = self.outer_derivative(&prediction.at(i), truth == i); + *derivation.at_mut(i) = self.outer_derivative(&prediction.at(i), truth == i); } derivation } diff --git a/src/linear_algebra.rs b/src/linear_algebra.rs index b760365..e6b7e1c 100644 --- a/src/linear_algebra.rs +++ b/src/linear_algebra.rs @@ -9,12 +9,12 @@ pub trait Vector: Clone { /// Not every possible implementation knows its dimension at compiletime, therefore a size hint /// is necessary to allocate the correct number of elements fn zero(dimension: usize) -> Self; - /// Maximum allowed index for `at` and `mut_at` + /// Maximum allowed index for `at` and `at_mut` fn dimension(&self) -> usize; /// Length of projection along `i`-th base fn at(&self, i: usize) -> f64; /// Mutable access to length of projection along `i`-th base - fn mut_at(&mut self, i: usize) -> &mut f64; + fn at_mut(&mut self, i: usize) -> &mut f64; /// Scalar product /// /// Default implementation using `at` and `dimension` is provided @@ -40,7 +40,7 @@ impl Vector for f64 { assert!(i == 0); *self } - fn mut_at(&mut self, i: usize) -> &mut f64 { + fn at_mut(&mut self, i: usize) -> &mut f64 { assert!(i == 0); self } @@ -63,7 +63,7 @@ macro_rules! vec_impl_for_array { self[index] } - fn mut_at(&mut self, index: usize) -> &mut f64 { + fn at_mut(&mut self, index: usize) -> &mut f64 { &mut self[index] } } diff --git a/src/model.rs b/src/model.rs index e307252..a52e8b7 100644 --- a/src/model.rs +++ b/src/model.rs @@ -52,7 +52,7 @@ impl Model for Linear if coefficient == self.m.dimension() { &mut self.c } else { - self.m.mut_at(coefficient) + self.m.at_mut(coefficient) } } @@ -203,7 +203,7 @@ impl Model for OneVsRest let models = &self.0; let mut result = Self::Target::zero(models.length()); for i in 0..models.length() { - *result.mut_at(i) = models.at_ref(i).predict(input); + *result.at_mut(i) = models.at_ref(i).predict(input); } result } @@ -212,7 +212,7 @@ impl Model for OneVsRest let models = &self.0; let class = coefficient % models.length(); let mut result = Self::Target::zero(models.length()); - *result.mut_at(class) = models.at_ref(class).gradient(coefficient / models.length(), input); + *result.at_mut(class) = models.at_ref(class).gradient(coefficient / models.length(), input); result } }