nirs4all.synthesis.builder module

Fluent builder for synthetic NIRS dataset construction.

This module provides a builder pattern interface for creating synthetic NIRS datasets with fine-grained control over all generation parameters.

Example

>>> from nirs4all.synthesis import SyntheticDatasetBuilder
>>>
>>> dataset = (
...     SyntheticDatasetBuilder(n_samples=1000, random_state=42)
...     .with_features(complexity="realistic")
...     .with_targets(distribution="lognormal", range=(0, 100))
...     .with_partitions(train_ratio=0.8)
...     .build()
... )
class nirs4all.synthesis.builder.BuilderState(n_samples: int = 1000, random_state: int | None = None, name: str = 'synthetic_nirs', wavelength_start: float = 350.0, wavelength_end: float = 2500.0, wavelength_step: float = 2.0, custom_wavelengths: ndarray | None = None, instrument_wavelength_grid: str | None = None, complexity: Literal['simple', 'realistic', 'complex'] = 'simple', component_names: list[str] | None = None, component_library: ComponentLibrary | None = None, custom_params: dict[str, Any] | None = None, instrument: str | None = None, measurement_mode: str | None = None, environmental_config: Any = None, scattering_effects_config: Any = None, edge_artifacts_config: Any = None, concentration_method: Literal['dirichlet', 'uniform', 'lognormal', 'correlated'] = 'dirichlet', target_range: tuple[float, float] | None = None, target_component: str | int | list[int] | None = None, target_transform: Literal['log', 'sqrt'] | None = None, n_classes: int | None = None, class_separation: float = 1.5, class_weights: list[float] | None = None, class_separation_method: Literal['component', 'threshold', 'cluster'] = 'component', generate_sample_ids: bool = False, sample_id_prefix: str = 'sample', n_groups: int | None = None, n_repetitions: int | tuple[int, int] = 1, group_names: list[str] | None = None, sources: list[Any] | None = None, aggregate_name: str | None = None, aggregate_variability: bool = False, train_ratio: float = 0.8, stratify: bool = False, shuffle: bool = True, batch_effects_enabled: bool = False, n_batches: int = 3, batch_offset_std: float = 0.02, batch_gain_std: float = 0.03, as_dataset: bool = True, include_metadata: bool = False, nonlinear_interactions: Literal['none', 'polynomial', 'synergistic', 'antagonistic'] = 'none', interaction_strength: float = 0.5, hidden_factors: int = 0, polynomial_degree: int = 2, signal_to_confound_ratio: float = 1.0, n_confounders: int = 0, spectral_masking: float = 0.0, temporal_drift: bool = False, n_regimes: int = 1, regime_method: Literal['concentration', 'spectral', 'random'] = 'concentration', regime_overlap: float = 0.2, noise_heteroscedasticity: float = 0.0, _X: ndarray | None = None, _y: ndarray | None = None, _C: ndarray | None = None, _wavelengths: ndarray | None = None, _metadata: dict[str, Any] | None = None, _sample_metadata: MetadataGenerationResult | None = None)[source]

Bases: object

Internal state container for the builder.

This holds all configuration accumulated through the builder methods.

aggregate_name: str | None = None
aggregate_variability: bool = False
as_dataset: bool = True
batch_effects_enabled: bool = False
batch_gain_std: float = 0.03
batch_offset_std: float = 0.02
class_separation: float = 1.5
class_separation_method: Literal['component', 'threshold', 'cluster'] = 'component'
class_weights: list[float] | None = None
complexity: Literal['simple', 'realistic', 'complex'] = 'simple'
component_library: ComponentLibrary | None = None
component_names: list[str] | None = None
concentration_method: Literal['dirichlet', 'uniform', 'lognormal', 'correlated'] = 'dirichlet'
custom_params: dict[str, Any] | None = None
custom_wavelengths: ndarray | None = None
edge_artifacts_config: Any = None
environmental_config: Any = None
generate_sample_ids: bool = False
group_names: list[str] | None = None
hidden_factors: int = 0
include_metadata: bool = False
instrument: str | None = None
instrument_wavelength_grid: str | None = None
interaction_strength: float = 0.5
measurement_mode: str | None = None
n_batches: int = 3
n_classes: int | None = None
n_confounders: int = 0
n_groups: int | None = None
n_regimes: int = 1
n_repetitions: int | tuple[int, int] = 1
n_samples: int = 1000
name: str = 'synthetic_nirs'
noise_heteroscedasticity: float = 0.0
nonlinear_interactions: Literal['none', 'polynomial', 'synergistic', 'antagonistic'] = 'none'
polynomial_degree: int = 2
random_state: int | None = None
regime_method: Literal['concentration', 'spectral', 'random'] = 'concentration'
regime_overlap: float = 0.2
sample_id_prefix: str = 'sample'
scattering_effects_config: Any = None
shuffle: bool = True
signal_to_confound_ratio: float = 1.0
sources: list[Any] | None = None
spectral_masking: float = 0.0
stratify: bool = False
target_component: str | int | list[int] | None = None
target_range: tuple[float, float] | None = None
target_transform: Literal['log', 'sqrt'] | None = None
temporal_drift: bool = False
train_ratio: float = 0.8
wavelength_end: float = 2500.0
wavelength_start: float = 350.0
wavelength_step: float = 2.0