nirs4all.optimization.n4m_engine module

Native (libn4m / n4m) hyperparameter finetuning engine.

A drop-in peer of OptunaManager that runs the native ask/tell optimizer shipped in nirs4all-methods instead of Optuna. Selected per model step via finetune_params={"engine": "n4m", ...}.

Why: the native engine (samplers random / sobol / lhs / ternary / ga / pso / cmaes / tpe / gp_ei and pruners median / asha / hyperband / racing) is a portable C-ABI core, so the same optimizer drives finetuning in Python, R, MATLAB/Octave and WASM — and at a fixed seed the trial sequence is identical across bindings. Optuna stays the default; nothing here removes it.

The search-space DSL is identical to the Optuna path (finetune_params ["model_params"] / ["train_params"] with tuple ranges, choice lists, dict specs and __-nested groups), compiled here into a native SearchSpace. The eval loop reuses the controller hooks (_get_model_instance /_prepare_data /_train_model /_evaluate_model /process_hyperparameters) exactly as the Optuna manager does, so the refit path is unchanged: it returns the same FinetuneResult objects.

class nirs4all.optimization.n4m_engine.N4MFinetuneManager[source]

Bases: object

Native-optimizer finetuning manager (mirrors OptunaManager.finetune).

finetune(dataset: Any, model_config: dict[str, Any], X_train: Any, y_train: Any, X_test: Any, y_test: Any, folds: list | None, finetune_params: dict[str, Any], context: Any, controller: Any) → FinetuneResult | list[FinetuneResult][source]