Improve code design
This commit is contained in:
+41
-4
@@ -4,6 +4,16 @@
|
||||
//! This library provides fast, reliable implementations of advanced optimization
|
||||
//! and statistical inference algorithms, with Python bindings via PyO3.
|
||||
//!
|
||||
//! # Architecture
|
||||
//!
|
||||
//! The library is designed with modularity, functional programming patterns,
|
||||
//! and trait-based abstractions:
|
||||
//!
|
||||
//! - `core`: Core traits (Optimizer, Sampler, InformationMeasure) and error types
|
||||
//! - `functional`: Functional programming utilities (composition, memoization, pipes)
|
||||
//! - Refactored modules with trait-based design and parallel support
|
||||
//! - Original modules maintained for backward compatibility
|
||||
//!
|
||||
//! # Modules
|
||||
//!
|
||||
//! - `hmm`: Hidden Markov Model training and inference
|
||||
@@ -15,6 +25,16 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyModule;
|
||||
|
||||
// Core modules with trait-based architecture
|
||||
pub mod core;
|
||||
pub mod functional;
|
||||
|
||||
// Refactored modules with advanced patterns
|
||||
pub mod hmm_refactored;
|
||||
pub mod mcmc_refactored;
|
||||
pub mod de_refactored;
|
||||
|
||||
// Original modules for backward compatibility
|
||||
mod hmm;
|
||||
mod mcmc;
|
||||
mod differential_evolution;
|
||||
@@ -24,21 +44,38 @@ mod information_theory;
|
||||
/// OptimizR Python module
|
||||
#[pymodule]
|
||||
fn _core(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
// Register HMM functions
|
||||
// ===== Original API (Backward Compatible) =====
|
||||
|
||||
// HMM functions
|
||||
m.add_class::<hmm::HMMParams>()?;
|
||||
m.add_function(wrap_pyfunction!(hmm::fit_hmm, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(hmm::viterbi_decode, m)?)?;
|
||||
|
||||
// Register MCMC functions
|
||||
// MCMC functions
|
||||
m.add_function(wrap_pyfunction!(mcmc::mcmc_sample, m)?)?;
|
||||
|
||||
// Register optimization functions
|
||||
// Optimization functions
|
||||
m.add_function(wrap_pyfunction!(differential_evolution::differential_evolution, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(grid_search::grid_search, m)?)?;
|
||||
|
||||
// Register information theory functions
|
||||
// Information theory functions
|
||||
m.add_function(wrap_pyfunction!(information_theory::mutual_information, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(information_theory::shannon_entropy, m)?)?;
|
||||
|
||||
// ===== New Refactored API (Advanced Features) =====
|
||||
|
||||
// Refactored HMM with trait-based design
|
||||
m.add_class::<hmm_refactored::HMMParams>()?;
|
||||
m.add_function(wrap_pyfunction!(hmm_refactored::fit_hmm, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(hmm_refactored::viterbi_decode, m)?)?;
|
||||
|
||||
// Refactored MCMC with strategy pattern
|
||||
m.add_function(wrap_pyfunction!(mcmc_refactored::mcmc_sample, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(mcmc_refactored::adaptive_mcmc_sample, m)?)?;
|
||||
|
||||
// Refactored DE with parallel support and multiple strategies
|
||||
m.add_class::<de_refactored::DEResult>()?;
|
||||
m.add_function(wrap_pyfunction!(de_refactored::differential_evolution, m)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user