GUIBRUSHR.Retrieval.ExofastMCMC.map_optimizer module

MAP (Maximum A Posteriori) optimizer for DE-MCMC warm-start.

Runs a bounded global optimization of the negative log-posterior (likelihood + prior) produced by ModelData.lh_function_gib, then refines with a local polish. The optimum replaces bestpars_data.list_bestpars_initial_value so that DE-MCMC chains are initialized around the posterior mode instead of a user-provided guess. This mitigates the DE-MCMC feedback loop where unconstrained dimensions diffuse, (r1 - r2) grows unbounded, and joint proposal size blows up causing acceptance collapse.

Intended to be called from Retrieval.main exactly once, before run_mcmc_sampling, and only when the user enabled the GUI checkbox.

GUIBRUSHR.Retrieval.ExofastMCMC.map_optimizer.compute_hessian_at_map(model_obj, x_map: ndarray, bounds, n_workers: int = 1, h_rel: float = 0.01, eps_floor: float = 1e-10, max_ridge_iter: int = 20, full_matrix: bool = True)[source]

Compute the Hessian of -log_post at x_map via central FD.

When full_matrix=True the off-diagonal terms are computed too (1 + 2N + 4·C(N,2) evaluations); when False only the diagonal is populated (1 + 2N evaluations) - same finite-difference machinery, just skip the cross-term loop. This matches the user-facing init_mode=="diagonal" choice that explicitly opts out of off-diagonal information.

Returns:

H: regularized Hessian (PSD), shape (d, d). C: H^-1 (covariance approximation), shape (d, d). sigma_p: sqrt(diag(C)), capped at 0.5 * (range_max-range_min). L: Cholesky factor of C (lower triangular), shape (d, d) or None when full_matrix=False. Returns None on any non-recoverable failure (caller should fall back to the legacy isotropic init and emit a JSONL fallback event).

Return type:

(H, C, sigma_p, L) or None

GUIBRUSHR.Retrieval.ExofastMCMC.map_optimizer.find_map_start(model_obj, maxiter_global: int = 40, popsize: int = 10, tol_global: float = 0.01, maxiter_local: int = 150, seed: int | None = None, n_workers: int = 1, init_mode: str = 'isotropic') ndarray[source]

Find the MAP estimate and overwrite bestpars_data.list_bestpars_initial_value.

Uses scipy.optimize.differential_evolution for global exploration followed by a Nelder-Mead polish. Chain bounds and the current initial value are read from model_obj. On success, list_bestpars_initial_value is replaced in place with the MAP point so that subsequent DE-MCMC chain initialization uses the posterior mode as its center.

Parameters:
  • model_obj – Fully initialized ModelData object (bestpars_data, retrieval_data, param_handler available).

  • maxiter_global (int) – Maximum iterations for differential_evolution. Default 40.

  • popsize (int) – Population size multiplier for differential_evolution. Default 10.

  • tol_global (float) – Relative tolerance for differential_evolution convergence. Default 1e-2.

  • maxiter_local (int) – Maximum iterations for Nelder-Mead polish. Set to 0 to skip the polish stage entirely. Default 150.

  • seed (int or None) – RNG seed for reproducibility; None pulls from OS entropy.

  • n_workers (int) – Number of multiprocessing.Process workers used to evaluate the DE population in parallel. n_workers <= 1 keeps the historical serial path. With n_workers > 1 the function spawns a persistent pool mirroring ModelData.parallel_chain (mp.Process + child seeds from model_obj.random_obj.seed_seq). On any pool failure the function falls back to the serial path with the same init population.

Returns:

The MAP parameter vector (length nfit).

Return type:

numpy.ndarray