tracts.core.compute_objective#
- compute_objective(parameters, *, best_state, local_genetic_model, tracts_data, likelihood_options, count_iteration=True)#
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()andoptimize_cob_sex_biased_two_steps()via their thinobjective_functionwrappers. 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 updatesbest_statewhenever 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 tonp.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. Itsparameter_handleris used to convert optimizer-space parameters to physical parameters for logging, itsmodel_func/outofbounds_funmethods compute the migration matrices and violation score forparameters, and itsphase_type_configsupplies 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 whenlikelihood_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.count_iteration (
bool) – Whether this evaluation counts as an optimizer iteration: increments the global iteration counter and is eligible for log/screen printing. Set to False for diagnostic re-evaluations (e.g. recomputing the full-data likelihood for reporting after optimization has already finished) so they don’t appear as phantom iterations.
- 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