tracts.core._compute_objective#

_compute_objective(parameters, *, best_state, local_genetic_model, tracts_data, likelihood_options)#

Evaluate the optimization objective (negative log-likelihood) for a given parameter vector.

This is the shared implementation called by both optimize_cob_sex_biased_single_step() and optimize_cob_sex_biased_two_steps() via their thin objective_function wrappers. It increments the global iteration counter, logs/prints the current iterate, handles out-of-bounds and singular-matrix penalties, computes the autosomal and/or allosomal log-likelihoods, and updates best_state whenever a new best finite objective is found.

Parameters:
  • parameters (np.ndarray) – Full parameter vector in optimizer space.

  • best_state (dict) – Mutable dict with keys 'objective' (float, lowest objective seen so far, initialised to np.inf) and 'params' (np.ndarray or None, the corresponding parameter vector). Updated in place whenever a new best finite objective is found.

  • local_genetic_model (GeneticModel) – Deep copy of the original genetic model (demographic model + admixture/ phase-type configuration), local to this optimization run. Its parameter_handler is used to convert optimizer-space parameters to physical parameters for logging, its model_func/outofbounds_fun methods compute the migration matrices and violation score for parameters, and its phase_type_config supplies the admixture models and recombination/pedigree settings used to compute the likelihood.

  • tracts_data (TractsData) – The population and mapped autosomal/allosomal tract-length histogram data used to compute the likelihood. Its allosome-related fields (allosome_bins, allosome_length, female_data_mapped, male_data_mapped, num_females, num_males) are required when likelihood_options.include_allosomes=True.

  • likelihood_options (LikelihoodOptions) – Logging verbosity (verbose_log, verbose_screen) and autosome/allosome inclusion flags (include_autosomes, include_allosomes) for this evaluation.

Returns:

The objective value (negative total log-likelihood), or a large positive penalty when parameters are out of bounds or produce a singular matrix.

Return type:

float