tracts.demography.base_parametrized_demography

Classes

BaseFounderEvent(found_time, ...[, end_time])

BaseMigrationEvent(rate_parameter, ...)

BaseParametrizedDemography([name, min_time, ...])

FixedParametersHandler(logger)

FounderEvent(found_time, source_populations, ...)

class tracts.demography.base_parametrized_demography.BaseFounderEvent(found_time, source_populations, remainder_population, end_time=None)

Bases: ABC

__init__(found_time, source_populations, remainder_population, end_time=None)
abstractmethod execute(parametrized_demography, params)
class tracts.demography.base_parametrized_demography.BaseMigrationEvent(rate_parameter, source_population)

Bases: ABC

__init__(rate_parameter, source_population)
abstractmethod execute(parametrized_demography, migration_matrix, params)
class tracts.demography.base_parametrized_demography.BaseParametrizedDemography(name='', min_time=2, max_time=inf)

Bases: ABC

__init__(name='', min_time=2, max_time=inf)
abstractmethod add_continuous_migration(source_population, rate_param, start_param, end_param)
add_dependent_parameter(param_name, expression, param_type=ParamType.UNTYPED, bounds=None)
add_parameter(param_name, param_type=ParamType.UNTYPED, bounds=None)

Adds the given parameter name to the parameters of the model.

add_population(population_name)

Adds the given population name to the populations of the model.

abstractmethod add_pulse_migration(source_population, rate_param, time_param)
check_bounds(params)

Checks the bounds on parameters. Bounds should be absolute restrictions on possible parameter values, whereas constraints should be restrictions on parameter values relative to each other.

check_constraints(params)

Constraints take the form of a dict {'param_subset':Tuple[String], 'expression': lambda (param_subset)}. The violation score is the largest negative value from all the constraints.

execute_migration_events(migration_matrix, params)
finalize()
get_index(time_param_name, population_name, params)

Returns the matrix index as a tuple from the position and time. Reduces repetitive code.

abstractmethod get_migration_matrices(params, solve_using_known_proportions=None)
Return type:

dict[str, ndarray]

get_param_value(param_name, params)

Gets the correct value from the name of the parameter and the list of passed params. If param_name is a number instead, uses the number directly.

abstractmethod get_random_parameters()
get_violation_score(params)

Takes in a list of params equal to the length of free_params and returns a negative violation score if the resulting matrix would be or is invalid.

property has_been_fixed
insert_params(params, params_from_proportions)

Used for merging the parameters solved by the primary optimizer with the parameters found from the known ancestry proportions into a single list of parameters in the correct order for the model.

is_time_param()
list_parameters()
logger = <Logger tracts.demography.base_parametrized_demography (WARNING)>
property parameter_bounds
property params_fixed_by_ancestry
static parse_proportions(ancestor_names, proportions)

Parses the ancestry proportions used in a founding event into a dict of parametrized source populations and a remainder population.

Return type:

tuple[dict[slice(<class ‘str’>, <class ‘str’>, None)], str]

proportions_from_matrices(migration_matrices)
proportions_from_matrices_return_keys()

This method returns the expected keys from self.proportions_from_matrices(). It is used by FixedProportionsHandler to validate that the fixed parameter will be solvable from the given data.

static proportions_from_matrix(migration_matrix)
set_up_fixed_ancestry_proportions(params_to_fix, proportions)
class tracts.demography.base_parametrized_demography.FixedParametersHandler(logger)

Bases: object

__init__(logger)
check_for_improper_constraint(demography)

Checks that the choice of parameters to fix does not underconstrain or overconstrain any of the matrices.

check_for_unsolvable_proportions(demography)

Checks that the demography has an assignment of (full) parameters that results in the chosen proportions.

compute_dependent_params(demography, params, known_ancestry_proportions=None)
property has_been_fixed
insert_params(free_params, params, params_from_proportions)

Used for merging the parameters solved by the primary optimizer with the parameters found from the known ancestry proportions into a single list of parameters in the correct order for the model.

set_up_fixed_ancestry_proportions(demography, params_to_fix, proportions)

Tells the model to calculate certain rate parameters based on the known ancestry proportions of the sample populations. Proportions are given as a dict with keys corresponding to the sample populations.

class tracts.demography.base_parametrized_demography.FounderEvent(found_time, source_populations, remainder_population, end_time=None)

Bases: BaseFounderEvent

__init__(found_time, source_populations, remainder_population, end_time=None)
execute(parametrized_demography, params)