From e42332d31d6d6aced0c4887d33a0264c0337ca5f Mon Sep 17 00:00:00 2001 From: Luis Moreno Date: Mon, 25 Nov 2024 09:39:27 -0400 Subject: [PATCH] chore: more doc updates --- src/algorithm/neighbour/fastpair.rs | 6 ------ src/linalg/basic/arrays.rs | 6 +++--- src/linalg/traits/svd.rs | 2 +- src/linear/lasso_optimizer.rs | 7 +++---- src/linear/logistic_regression.rs | 3 --- src/optimization/first_order/gradient_descent.rs | 2 +- src/optimization/first_order/lbfgs.rs | 2 +- src/optimization/first_order/mod.rs | 4 ++-- src/optimization/line_search.rs | 11 +++++------ src/optimization/mod.rs | 6 +++--- 10 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/algorithm/neighbour/fastpair.rs b/src/algorithm/neighbour/fastpair.rs index ebd57b42..9f663f67 100644 --- a/src/algorithm/neighbour/fastpair.rs +++ b/src/algorithm/neighbour/fastpair.rs @@ -52,10 +52,8 @@ pub struct FastPair<'a, T: RealNumber + FloatNumber, M: Array2> { } impl<'a, T: RealNumber + FloatNumber, M: Array2> FastPair<'a, T, M> { - /// /// Constructor /// Instantiate and initialize the algorithm - /// pub fn new(m: &'a M) -> Result { if m.shape().0 < 3 { return Err(Failed::because( @@ -156,9 +154,7 @@ impl<'a, T: RealNumber + FloatNumber, M: Array2> FastPair<'a, T, M> { self.neighbours = neighbours; } - /// /// Find closest pair by scanning list of nearest neighbors. - /// #[allow(dead_code)] pub fn closest_pair(&self) -> PairwiseDistance { let mut a = self.neighbours[0]; // Start with first point @@ -215,9 +211,7 @@ mod tests_fastpair { use super::*; use crate::linalg::basic::{arrays::Array, matrix::DenseMatrix}; - /// /// Brute force algorithm, used only for comparison and testing - /// pub fn closest_pair_brute(fastpair: &FastPair>) -> PairwiseDistance { use itertools::Itertools; let m = fastpair.samples.shape().0; diff --git a/src/linalg/basic/arrays.rs b/src/linalg/basic/arrays.rs index 9eb5739a..3c889722 100644 --- a/src/linalg/basic/arrays.rs +++ b/src/linalg/basic/arrays.rs @@ -973,7 +973,7 @@ pub trait Array1: MutArrayView1 + Sized + result.softmax_mut(); result } - /// + /// multiply array by matrix fn xa(&self, a_transpose: bool, a: &dyn ArrayView2) -> Self where T: Number, @@ -1136,7 +1136,7 @@ pub trait Array2: MutArrayView2 + Sized + result } - /// + /// matrix multiplication fn ab(&self, a_transpose: bool, b: &dyn ArrayView2, b_transpose: bool) -> Self where T: Number, @@ -1171,7 +1171,7 @@ pub trait Array2: MutArrayView2 + Sized + result } } - /// + /// matrix vector multiplication fn ax(&self, a_transpose: bool, x: &dyn ArrayView1) -> Self where T: Number, diff --git a/src/linalg/traits/svd.rs b/src/linalg/traits/svd.rs index 75c303ae..8c807714 100644 --- a/src/linalg/traits/svd.rs +++ b/src/linalg/traits/svd.rs @@ -52,7 +52,7 @@ pub struct SVD> { m: usize, /// n: usize, - /// + /// Tolerance tol: T, } diff --git a/src/linear/lasso_optimizer.rs b/src/linear/lasso_optimizer.rs index 583354e6..22119160 100644 --- a/src/linear/lasso_optimizer.rs +++ b/src/linear/lasso_optimizer.rs @@ -16,7 +16,7 @@ use crate::linalg::basic::arrays::{Array1, Array2, ArrayView1, MutArray, MutArra use crate::linear::bg_solver::BiconjugateGradientSolver; use crate::numbers::floatnum::FloatNumber; -/// +/// Interior Point Optimizer pub struct InteriorPointOptimizer> { ata: X, d1: Vec, @@ -25,9 +25,8 @@ pub struct InteriorPointOptimizer> { prs: Vec, } -/// impl> InteriorPointOptimizer { - /// + /// Initialize a new Interior Point Optimizer pub fn new(a: &X, n: usize) -> InteriorPointOptimizer { InteriorPointOptimizer { ata: a.ab(true, a, false), @@ -38,7 +37,7 @@ impl> InteriorPointOptimizer { } } - /// + /// Run the optimization pub fn optimize( &mut self, x: &X, diff --git a/src/linear/logistic_regression.rs b/src/linear/logistic_regression.rs index e6500b6e..7e934288 100644 --- a/src/linear/logistic_regression.rs +++ b/src/linear/logistic_regression.rs @@ -183,14 +183,11 @@ pub struct LogisticRegression< } trait ObjectiveFunction> { - /// fn f(&self, w_bias: &[T]) -> T; - /// #[allow(clippy::ptr_arg)] fn df(&self, g: &mut Vec, w_bias: &Vec); - /// #[allow(clippy::ptr_arg)] fn partial_dot(w: &[T], x: &X, v_col: usize, m_row: usize) -> T { let mut sum = T::zero(); diff --git a/src/optimization/first_order/gradient_descent.rs b/src/optimization/first_order/gradient_descent.rs index 60aeb0b1..e9d625ce 100644 --- a/src/optimization/first_order/gradient_descent.rs +++ b/src/optimization/first_order/gradient_descent.rs @@ -8,7 +8,7 @@ use crate::optimization::{DF, F}; /// pub struct GradientDescent { - /// + /// Maximum number of iterations pub max_iter: usize, /// pub g_rtol: f64, diff --git a/src/optimization/first_order/lbfgs.rs b/src/optimization/first_order/lbfgs.rs index f97f2f4e..6466007a 100644 --- a/src/optimization/first_order/lbfgs.rs +++ b/src/optimization/first_order/lbfgs.rs @@ -13,7 +13,7 @@ use crate::optimization::{DF, F}; /// pub struct LBFGS { - /// + /// Maximum number of iterations pub max_iter: usize, /// pub g_rtol: f64, diff --git a/src/optimization/first_order/mod.rs b/src/optimization/first_order/mod.rs index 1bddda94..bbaeea62 100644 --- a/src/optimization/first_order/mod.rs +++ b/src/optimization/first_order/mod.rs @@ -26,9 +26,9 @@ pub trait FirstOrderOptimizer { /// Result of optimization #[derive(Debug, Clone)] pub struct OptimizerResult> { - /// + /// Solution pub x: X, - /// + /// f(x) value pub f_x: T, /// number of iterations pub iterations: usize, diff --git a/src/optimization/line_search.rs b/src/optimization/line_search.rs index d9511fc8..6ae6ab3f 100644 --- a/src/optimization/line_search.rs +++ b/src/optimization/line_search.rs @@ -1,9 +1,9 @@ use crate::optimization::FunctionOrder; use num_traits::Float; -/// Line search method is an iterative approach to find a local minimum of a multidimensional nonlinear function using the function's gradients +/// Line search optimization. pub trait LineSearchMethod { - /// + /// Find alpha that satisfies strong Wolfe conditions. fn search( &self, f: &(dyn Fn(T) -> T), @@ -17,7 +17,7 @@ pub trait LineSearchMethod { /// Line search result #[derive(Debug, Clone)] pub struct LineSearchResult { - /// + /// Alpha pub alpha: T, /// pub f_x: T, @@ -27,7 +27,7 @@ pub struct LineSearchResult { pub struct Backtracking { /// pub c1: T, - /// + /// Maximum number of iterations for Backtracking single run pub max_iterations: usize, /// pub max_infinity_iterations: usize, @@ -35,11 +35,10 @@ pub struct Backtracking { pub phi: T, /// pub plo: T, - /// + /// function order pub order: FunctionOrder, } -/// impl Default for Backtracking { fn default() -> Self { Backtracking { diff --git a/src/optimization/mod.rs b/src/optimization/mod.rs index 1ec2cbf2..6a9fa332 100644 --- a/src/optimization/mod.rs +++ b/src/optimization/mod.rs @@ -8,12 +8,12 @@ pub type F<'a, T, X> = dyn for<'b> Fn(&'b X) -> T + 'a; /// pub type DF<'a, X> = dyn for<'b> Fn(&'b mut X, &'b X) + 'a; -/// +/// Function order #[allow(clippy::upper_case_acronyms)] #[derive(Debug, PartialEq, Eq)] pub enum FunctionOrder { - /// + /// Second order SECOND, - /// + /// Third order THIRD, }