lbfgsbrs 0.1.2

Rust port of L-BFGS-B-C
Documentation
//pub type integer = i32;
//pub type logical = i32;

/// Represents the current state of the L-BFGS-B optimization algorithm
#[derive(Debug, Clone, PartialEq)]
pub enum Task {
    /// Starting the optimization process
    Start,
    /// A new point in the optimization process
    NewX,
    /// Function and gradient evaluation at the current point
    FunctionGradientEval,
    /// Line search in progress
    LineSearch,
    /// Convergence achieved based on gradient norm
    ConvergedGradient,
    /// Convergence achieved based on function value
    ConvergedFunction,
    /// Algorithm stopped due to CPU time limit
    StoppedCpuTime,
    /// Algorithm stopped due to other reasons
    Stopped,
    /// Algorithm needs to restart
    Restart,
    /// Abnormal termination
    Abnormal,
}

/// Represents possible errors in the L-BFGS-B algorithm
#[derive(Debug, Clone, PartialEq)]
pub enum LbfgsbError {
    /// Invalid input parameters
    InvalidInput(String),
    /// Singular triangular system detected
    SingularSystem,
    /// Non-positive definiteness in Cholesky factorization
    NonPositiveDefinite,
    /// Bad direction in line search
    BadDirection,
    /// Line search cannot make further progress
    LineSearchFailed,
    /// Maximum number of iterations reached
    MaxIterations,
    /// Other errors
    Other(String),
}

/// Result of an optimization step
#[derive(Debug, Clone)]
pub struct OptimizationState {
    /// Current task/state of the algorithm
    pub task: Task,
    /// Current function value
    pub function_value: f64,
    /// Current iterate
    pub x: Vec<f64>,
    /// Current gradient
    pub gradient: Vec<f64>,
    /// Projected gradient norm
    pub gradient_norm: f64,
    /// Number of iterations
    pub iterations: i32,
    /// Number of function evaluations
    pub function_evals: i32,
}

/// Result type for L-BFGS-B operations
pub type LbfgsbResult<T> = Result<T, LbfgsbError>;