diff --git a/src/metric.rs b/src/metric.rs index 1bb5c17..4fe4d02 100644 --- a/src/metric.rs +++ b/src/metric.rs @@ -442,7 +442,7 @@ where self.metric.replace(IntMut { mu: mu.to_vec(), - metric: metric, + metric, derivative: dmetric.clone(), }); // self.metric.replace(IntMut { diff --git a/src/optimize.rs b/src/optimize.rs index 8354070..f5ac083 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -379,6 +379,20 @@ mod tests { #[test] fn test_lbfgs_quadratic_with_minimum() { + struct QuadraticWithMinimum; + + impl ObjectiveFunction for QuadraticWithMinimum { + fn evaluate(&self, point: &[f64]) -> f64 { + let x = point[0]; + (x - 2.0).powi(2) + } + + fn gradient(&self, point: &[f64]) -> Option> { + let x = point[0]; + Some(vec![2.0 * (x - 2.0)]) + } + } + let f = QuadraticWithMinimum; let initial_point = vec![0.0]; let config = OptimizationConfig { @@ -412,17 +426,3 @@ mod tests { } } } - -struct QuadraticWithMinimum; - -impl ObjectiveFunction for QuadraticWithMinimum { - fn evaluate(&self, point: &[f64]) -> f64 { - let x = point[0]; - (x - 2.0).powi(2) - } - - fn gradient(&self, point: &[f64]) -> Option> { - let x = point[0]; - Some(vec![2.0 * (x - 2.0)]) - } -} diff --git a/src/register.rs b/src/register.rs index f714ba7..630a613 100644 --- a/src/register.rs +++ b/src/register.rs @@ -10,18 +10,15 @@ use std::marker::PhantomData; /// Optimizer type for registration #[derive(Clone, Debug, PartialEq)] +#[derive(Default)] pub enum Optimizer { /// L-BFGS optimizer (fast, requires consistent gradients) + #[default] LBFGS, /// Adaptive Stochastic Gradient Descent (robust, handles noisy gradients) ASGD, } -impl Default for Optimizer { - fn default() -> Self { - Self::LBFGS - } -} #[derive(Clone, Debug)] pub struct RegistrationStep { @@ -358,11 +355,10 @@ impl Registration { &scales, ); - if let Some(result) = optimization_result { - if result.optimal_point.iter().all(|i| i.is_finite()) { + if let Some(result) = optimization_result + && result.optimal_point.iter().all(|i| i.is_finite()) { p = self.fixed_mu.combine(&result.optimal_point); } - } } Ok(Transform::::new(p, fixed.shape().to_vec())) }