tracts.genetic_model.GeneticModel#

class GeneticModel(demographic_model, phase_type_config=None, **phase_type_kwargs)#

Bases: object

Bundles a demographic model with the admixture and phase-type model configuration used to evaluate its likelihood against tract-length data.

demographic_model#

The demographic model whose parameters are being fit.

Type:

ParametrizedDemography | ParametrizedDemographySexBiased

phase_type_config#

The admixture and phase-type model configuration used to compute the likelihood of demographic_model’s migration matrices.

Type:

PhaseTypeModelConfig

__init__(demographic_model, phase_type_config=None, **phase_type_kwargs)#
Parameters:
copy()#

Returns a deep copy of this GeneticModel, including its demographic model and phase-type configuration. Useful for optimization routines that need their own local copy of the demographic model’s fixed-parameter state (e.g. a FixedParametersHandler mutated during optimization) without affecting the original.

Return type:

GeneticModel

get_migration_matrices(params)#

Computes the migration matrices for params via demographic_model.get_migration_matrices.

property is_sex_biased: bool#

Whether demographic_model is a ParametrizedDemographySexBiased instance.

loglik(male_matrix, female_matrix, tracts_data, likelihood_options)#

Computes the log-likelihood of tracts_data given the migration matrices male_matrix/female_matrix, dispatching to the phase-type or hybrid-pedigree admixture model selected by self.phase_type_config (ad_model_autosomes for the autosomal component, ad_model_allosomes for the allosomal components) so that callers do not need to branch on the admixture model choice themselves.

Parameters:
  • male_matrix (ndarray) – The male migration matrix.

  • female_matrix (ndarray) – The female migration matrix. For autosome-only (non sex-biased) evaluations, pass the same (averaged) matrix as male_matrix.

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

  • likelihood_options (LikelihoodOptions) – Its include_autosomes/include_allosomes flags determine which log-likelihood components are computed. verbose_log/verbose_screen are not used here.

Returns:

The log-likelihood contributions for each requested component. Use .total for the combined log-likelihood.

Return type:

LoglikBreakdown

Notes

Does not catch exceptions: constructing a phase-type model can raise np.linalg.LinAlgError or ValueError for infeasible migration matrices (e.g. singular matrices); callers should catch these the same way they already do around obtaining male_matrix/female_matrix in the first place (see _compute_objective()).

property model_base_params#

The demographic model’s free base parameters (see BaseParametrizedDemography.model_base_params).

model_func(params)#

Converts optimizer-space params to physical parameters via demographic_model.parameter_handler and returns the resulting migration matrices. Equivalent to the function previously returned by get_time_scaled_model_func(), but always bound to this instance’s demographic_model — including after copy(), unlike a stored closure over the original model.

outofbounds_fun(params, verbose=False)#

Converts optimizer-space params to physical parameters via demographic_model.parameter_handler and returns the resulting violation score. Equivalent to the function previously returned by get_time_scaled_model_bounds(), but always bound to this instance’s demographic_model — including after copy(), unlike a stored closure over the original model.

property parameter_handler#

The demographic model’s FixedParametersHandler (see BaseParametrizedDemography.parameter_handler).

property population_indices#

The demographic model’s population-name-to-index mapping.

set_up_fixed_parameters(params_to_fix_by_ancestry=None, proportions=None, user_params_to_fix_by_value=None)#

Sets up fixed parameters (by ancestry proportions and/or by user-provided value) on this instance’s demographic_model (see BaseParametrizedDemography.set_up_fixed_parameters).

Provided as a GeneticModel method — rather than requiring callers to reach into genetic_model.demographic_model themselves — so that fixing parameters through a GeneticModel always mutates the exact demographic_model that GeneticModel’s own parameter_handler/model_func/outofbounds_fun/loglik read from, and the change is guaranteed visible on any later use of this same GeneticModel instance.

Parameters:
  • params_to_fix_by_ancestry (list | None) – Names of parameters to fix from proportions. Defaults to none.

  • proportions (dict | None) – Ancestry proportions used to fix params_to_fix_by_ancestry. Defaults to none.

  • user_params_to_fix_by_value (dict | None) – A dict mapping parameter names to the values they should be fixed at. Defaults to none.

Return type:

None