tracts.genetic_model.GeneticModel#
- class GeneticModel(demographic_model, phase_type_config=None, **phase_type_kwargs)#
Bases:
objectBundles 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.
- phase_type_config#
The admixture and phase-type model configuration used to compute the likelihood of
demographic_model’s migration matrices.- Type:
- __init__(demographic_model, phase_type_config=None, **phase_type_kwargs)#
- Parameters:
demographic_model (
ParametrizedDemography|ParametrizedDemographySexBiased) – The demographic model whose parameters are being fit.phase_type_config (
PhaseTypeModelConfig|None) – The admixture and phase-type model configuration. If None, a newPhaseTypeModelConfigis constructed fromphase_type_kwargs.**phase_type_kwargs – Keyword arguments forwarded to
PhaseTypeModelConfigwhenphase_type_configis None (e.g.ad_model_autosomes='DC'). Ignored ifphase_type_configis provided.
- 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
FixedParametersHandlermutated during optimization) without affecting the original.- Return type:
- get_migration_matrices(params)#
Computes the migration matrices for
paramsviademographic_model.get_migration_matrices.
- property is_sex_biased: bool#
Whether
demographic_modelis aParametrizedDemographySexBiasedinstance.
- loglik(male_matrix, female_matrix, tracts_data, likelihood_options)#
Computes the log-likelihood of
tracts_datagiven the migration matricesmale_matrix/female_matrix, dispatching to the phase-type or hybrid-pedigree admixture model selected byself.phase_type_config(ad_model_autosomesfor the autosomal component,ad_model_allosomesfor 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 asmale_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 whenlikelihood_options.include_allosomes=True.likelihood_options (
LikelihoodOptions) – Itsinclude_autosomes/include_allosomesflags determine which log-likelihood components are computed.verbose_log/verbose_screenare not used here.
- Returns:
The log-likelihood contributions for each requested component. Use
.totalfor the combined log-likelihood.- Return type:
Notes
Does not catch exceptions: constructing a phase-type model can raise
np.linalg.LinAlgErrororValueErrorfor infeasible migration matrices (e.g. singular matrices); callers should catch these the same way they already do around obtainingmale_matrix/female_matrixin 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
paramsto physical parameters viademographic_model.parameter_handlerand returns the resulting migration matrices. Equivalent to the function previously returned byget_time_scaled_model_func(), but always bound to this instance’sdemographic_model— including aftercopy(), unlike a stored closure over the original model.
- outofbounds_fun(params, verbose=False)#
Converts optimizer-space
paramsto physical parameters viademographic_model.parameter_handlerand returns the resulting violation score. Equivalent to the function previously returned byget_time_scaled_model_bounds(), but always bound to this instance’sdemographic_model— including aftercopy(), unlike a stored closure over the original model.
- property parameter_handler#
The demographic model’s
FixedParametersHandler(seeBaseParametrizedDemography.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(seeBaseParametrizedDemography.set_up_fixed_parameters).Provided as a GeneticModel method — rather than requiring callers to reach into
genetic_model.demographic_modelthemselves — so that fixing parameters through a GeneticModel always mutates the exact demographic_model that GeneticModel’s ownparameter_handler/model_func/outofbounds_fun/loglikread 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 fromproportions. Defaults to none.proportions (
dict|None) – Ancestry proportions used to fixparams_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