Initial commit

This commit is contained in:
redclawsystems
2026-03-04 00:08:42 +00:00
commit 4d88dc0584
4449 changed files with 1556714 additions and 0 deletions
@@ -0,0 +1,86 @@
//! Inverse solutions for MEG/EEG source localization.
//!
//! This crate provides algorithms to estimate brain source activity from
//! MEG/EEG sensor measurements.
//!
//! ## Available Methods
//!
//! - **MNE** (Minimum Norm Estimate): Basic L2-regularized inverse
//! - **dSPM** (Dynamic Statistical Parametric Mapping): Noise-normalized MNE
//! - **sLORETA** (Standardized LORETA): Resolution-matrix normalized
//! - **eLORETA** (Exact LORETA): Zero localization error inverse
//! - **LCMV** (Linearly Constrained Minimum Variance): Beamformer approach
//! - **DICS** (Dynamic Imaging of Coherent Sources): Frequency-domain beamformer
//! - **Dipole Fitting**: Equivalent current dipole fitting with optimization
//!
//! ## Usage
//!
//! ```rust,ignore
//! use rtx_neuro_inverse::{MneInverse, InverseMethod, Covariance};
//!
//! // Compute inverse operator
//! let inverse = MneInverse::make_inverse(
//! &forward,
//! &noise_cov,
//! InverseMethod::Dspm,
//! 0.1, // loose
//! 0.8, // depth
//! )?;
//!
//! // Apply to evoked data
//! let stc = inverse.apply(&evoked, 1.0 / 9.0)?; // lambda^2 = 1/SNR^2
//! ```
#![warn(missing_docs)]
pub mod beamformer;
pub mod covariance;
pub mod dipole;
pub mod loreta;
pub mod mne;
pub mod source_estimate;
pub use beamformer::{
CrossSpectralDensity, DicsBeamformer, DicsConfig, LcmvBeamformer, PickOrientation,
};
pub use covariance::{Covariance, CovarianceType};
pub use dipole::{DipoleConfig, DipoleFit, DipoleFitSequence, DipoleFitter};
pub use loreta::{EloretaConfig, EloretaInverse};
pub use mne::{InverseMethod, MneInverse};
pub use source_estimate::SourceEstimate;
/// Errors in inverse modeling
#[derive(Debug, thiserror::Error)]
pub enum InverseError {
/// Invalid parameters
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
/// Dimension mismatch
#[error("Dimension mismatch: {0}")]
DimensionMismatch(String),
/// Computation error (e.g., singular matrix)
#[error("Computation error: {0}")]
ComputationError(String),
/// Forward model error
#[error("Forward model error: {0}")]
ForwardError(#[from] rtx_neuro_forward::ForwardError),
/// No inverse operator computed
#[error("Inverse operator not computed: {0}")]
NoInverse(String),
}
/// Result type for inverse operations
pub type InverseResult<T> = Result<T, InverseError>;
#[cfg(test)]
mod tests {
#[test]
fn test_error_display() {
let err = super::InverseError::InvalidParameter("test".to_string());
assert!(err.to_string().contains("test"));
}
}