tracts.driver_utils.build_boundary_reoptimization_model#
- build_boundary_reoptimization_model(driver_spec, reload_context, boundary_fixed_param_values, genetic_model, optimal_params, remainder_params, alternate_implicit_population=None)#
Builds a genetic model and driver specification identical to the given ones, except with the sex-bias parameters in
boundary_fixed_param_valuesnow fixed by value, and (if given)alternate_implicit_populationas the implicit population instead of the current one. Fixed parameters and starting parameters are set up accordingly. Used to retry the optimization when one or more sex-bias parameters have an optimal value at a +-1 boundary.As with
_get_driver_for_reoptimization, all starting parameters are pinned to their previous optimal value (no resampling) and repetitions are set to 1: this re-optimization should resume from where the previous one left off, not restart from a fresh random point.- Parameters:
driver_spec (
InferenceConfig) – The original driver-file configuration.reload_context (
ModelReloadContext) – File-location and ancestry-proportion context needed to reload the demographic model from the model YAML file, used only whenalternate_implicit_populationis given.boundary_fixed_param_values (
dict[str,float]) – Directly-optimized sex-bias parameter names (and their boundary value) to fix by value, merged intodriver_spec.optim.fix_parameters_by_value.genetic_model (
GeneticModel) – The current genetic model. Whenalternate_implicit_populationis None, a deep copy of this genetic model is reused instead of reloading the demographic model from the model YAML file (its parameter names are derived directly fromgenetic_model.demographic_model, which is unchanged in that case). Whenalternate_implicit_populationis given, only itsphase_type_configis reused (the demographic model must be reloaded, since which population is implicit is baked into the founder events at YAML-parse time).optimal_params (
ndarray) – The current optimal parameters (physical units), before this re-optimization, in the order given bygenetic_model.demographic_model’s free base parameters. Used to pin the starting parameters of the re-optimization (see_get_driver_for_reoptimization).remainder_params (
dict[str,float]) – The remainder (derived) parameters computed from the previous optimization’s optimal parameters, as returned bycompute_remainder_params. Used, whenalternate_implicit_populationis given, to set a starting value for the rate, and fix by value the sex-bias parameter, of the population that was previously implicit and is now explicit (see_get_params_for_newly_explicit_population).alternate_implicit_population (
str|None) – The name of the population to use as the implicit population instead of the current one. If None, the current implicit population is kept. Defaults to None.
- Returns:
The new driver spec; the new genetic model built from it; the model, sex-bias, and non-sex-bias parameter names; and the physical starting parameters to optimize from.
- Return type:
tuple[InferenceConfig, GeneticModel, list[str], list[str], list[str], list[np.ndarray]]