tracts.driver.run_model#

run_model(model_func, bound_func, population, population_labels, startparams, population_dict, parameter_handler=None, max_iter=None, exclude_tracts_below_cM=0, ad_model_autosomes='DC', ad_model_allosomes='DC', npts=0, verbose_log=0, verbose_screen=0, two_steps_optimization=True, run_optimize_cob=False)#

Runs the optimization for any demographic model, including sex-biased models. This function allows to run the old optimization function optimize_cob.

Parameters:
  • model_func (callable) – A function that takes a parameter array and returns a dictionary of migration matrices for each population.

  • bound_func (callable) – A function that takes a parameter array and returns a violation score indicating how much the parameters violate the bounds.

  • population (Population) – A Population object containing the data to fit.

  • population_labels (list[str]) – A list of labels corresponding to the populations.

  • startparams (list) – An array of initial parameters to start the optimization.

  • population_dict (dict) – A dictionary mapping population labels to their corresponding indices in the model.

  • parameter_handler (ParameterHandler, optional) – An object that handles parameter transformations and fixed parameters. Default is None.

  • max_iter (int | None) – Maximum number of iterations for the optimization algorithm. Default is None, which means no limit.

  • exclude_tracts_below_cM (float) – Minimum tract length in centimorgans to exclude from analysis. Default is 0.

  • ad_model_autosomes (str) – The model to use for autosomal admixture. Must be one of ‘DC’, ‘DF’, ‘M’, ‘H-DC’ or ‘H-DF’. Default is ‘DC’.

  • ad_model_allosomes (str) – The model to use for allosomal admixture. Must be one of ‘DC’, ‘DF’, ‘H-DC’ or ‘H-DF’. Default is ‘DC’. If None, allosomal admixture will not be modeled.

  • npts (int) – Number of bins for the tract length histogram. Default is 50.

  • verbose_log (int) – Verbosity level for logging. Default is 0 (no verbose output). If greater than 0, iterations are logged every verbose_log steps.

  • verbose_screen (int) – Verbosity level for screen prints. Default is 0 (no verbose output). If greater than 0, iterations are printed every verbose_screen steps.

  • two_steps_optimization (bool) – Whether to use a two-step optimization procedure for sex-biased models. If True, the optimization will first be run on non-sex bias parameters using only autosomal data. Then, a second optimization will be run with sex-bias parameters using both autosomal and allosomal data, starting from the results of the first optimization. Default is True.

  • run_optimize_cob (bool) – Whether to run the optimize_cob function. Default is False.

Returns:

  • tuple [np.ndarray, float] – A tuple containing the optimal parameters found and the corresponding likelihood.

  • Details

  • ——-

  • The optimize_cob function implements the PhTMonoecious model on autosomal data. Corresponds to the previous version of tracts.