fix: renames FloatExt to RealNumber
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
use std::default::Default;
|
||||
|
||||
use crate::linalg::Matrix;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
use crate::optimization::first_order::{FirstOrderOptimizer, OptimizerResult};
|
||||
use crate::optimization::line_search::LineSearchMethod;
|
||||
use crate::optimization::{DF, F};
|
||||
|
||||
pub struct GradientDescent<T: FloatExt> {
|
||||
pub struct GradientDescent<T: RealNumber> {
|
||||
pub max_iter: usize,
|
||||
pub g_rtol: T,
|
||||
pub g_atol: T,
|
||||
}
|
||||
|
||||
impl<T: FloatExt> Default for GradientDescent<T> {
|
||||
impl<T: RealNumber> Default for GradientDescent<T> {
|
||||
fn default() -> Self {
|
||||
GradientDescent {
|
||||
max_iter: 10000,
|
||||
@@ -22,7 +22,7 @@ impl<T: FloatExt> Default for GradientDescent<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt> FirstOrderOptimizer<T> for GradientDescent<T> {
|
||||
impl<T: RealNumber> FirstOrderOptimizer<T> for GradientDescent<T> {
|
||||
fn optimize<'a, X: Matrix<T>, LS: LineSearchMethod<T>>(
|
||||
&self,
|
||||
f: &'a F<T, X>,
|
||||
|
||||
@@ -2,12 +2,12 @@ use std::default::Default;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::linalg::Matrix;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
use crate::optimization::first_order::{FirstOrderOptimizer, OptimizerResult};
|
||||
use crate::optimization::line_search::LineSearchMethod;
|
||||
use crate::optimization::{DF, F};
|
||||
|
||||
pub struct LBFGS<T: FloatExt> {
|
||||
pub struct LBFGS<T: RealNumber> {
|
||||
pub max_iter: usize,
|
||||
pub g_rtol: T,
|
||||
pub g_atol: T,
|
||||
@@ -19,7 +19,7 @@ pub struct LBFGS<T: FloatExt> {
|
||||
pub m: usize,
|
||||
}
|
||||
|
||||
impl<T: FloatExt> Default for LBFGS<T> {
|
||||
impl<T: RealNumber> Default for LBFGS<T> {
|
||||
fn default() -> Self {
|
||||
LBFGS {
|
||||
max_iter: 1000,
|
||||
@@ -35,7 +35,7 @@ impl<T: FloatExt> Default for LBFGS<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FloatExt> LBFGS<T> {
|
||||
impl<T: RealNumber> LBFGS<T> {
|
||||
fn two_loops<X: Matrix<T>>(&self, state: &mut LBFGSState<T, X>) {
|
||||
let lower = state.iteration.max(self.m) - self.m;
|
||||
let upper = state.iteration;
|
||||
@@ -175,7 +175,7 @@ impl<T: FloatExt> LBFGS<T> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct LBFGSState<T: FloatExt, X: Matrix<T>> {
|
||||
struct LBFGSState<T: RealNumber, X: Matrix<T>> {
|
||||
x: X,
|
||||
x_prev: X,
|
||||
x_f: T,
|
||||
@@ -195,7 +195,7 @@ struct LBFGSState<T: FloatExt, X: Matrix<T>> {
|
||||
alpha: T,
|
||||
}
|
||||
|
||||
impl<T: FloatExt> FirstOrderOptimizer<T> for LBFGS<T> {
|
||||
impl<T: RealNumber> FirstOrderOptimizer<T> for LBFGS<T> {
|
||||
fn optimize<'a, X: Matrix<T>, LS: LineSearchMethod<T>>(
|
||||
&self,
|
||||
f: &F<T, X>,
|
||||
|
||||
@@ -5,11 +5,11 @@ use std::clone::Clone;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::linalg::Matrix;
|
||||
use crate::math::num::FloatExt;
|
||||
use crate::math::num::RealNumber;
|
||||
use crate::optimization::line_search::LineSearchMethod;
|
||||
use crate::optimization::{DF, F};
|
||||
|
||||
pub trait FirstOrderOptimizer<T: FloatExt> {
|
||||
pub trait FirstOrderOptimizer<T: RealNumber> {
|
||||
fn optimize<'a, X: Matrix<T>, LS: LineSearchMethod<T>>(
|
||||
&self,
|
||||
f: &F<T, X>,
|
||||
@@ -20,7 +20,7 @@ pub trait FirstOrderOptimizer<T: FloatExt> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OptimizerResult<T: FloatExt, X: Matrix<T>> {
|
||||
pub struct OptimizerResult<T: RealNumber, X: Matrix<T>> {
|
||||
pub x: X,
|
||||
pub f_x: T,
|
||||
pub iterations: usize,
|
||||
|
||||
Reference in New Issue
Block a user