tracts.demography.parametrized_demography

Classes

ContinuousEvent(start_parameter, ...)

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

A class representing a demographic history for multiple populations of interest, with parametrized migrations from other populations.

PulseEvent(rate_parameter, time_parameter, ...)

class tracts.demography.parametrized_demography.ContinuousEvent(start_parameter, end_parameter, rate_parameter, source_population)

Bases: BaseMigrationEvent

__init__(start_parameter, end_parameter, rate_parameter, source_population)
execute(parametrized_demography, migration_matrix, params)
class tracts.demography.parametrized_demography.ParametrizedDemography(name='', min_time=2, max_time=inf)

Bases: BaseParametrizedDemography

A class representing a demographic history for multiple populations of interest, with parametrized migrations from other populations.

__init__(name='', min_time=2, max_time=inf)
add_continuous_migration(dest_population, source_population, rate_param, start_param, end_param)

Adds a continuous migration from source population A, parametrized by start_time, end_time, and magnitude.

add_dependent_parameter(param_name, expression, param_type=ParamType.UNTYPED, bounds=None)
add_founder_event(dest_population, source_populations, remainder_population, found_time, end_time=None)

Adds a founder event. A parametrized demography must have exactly one founder event. source_populations is a dict where each key is a population and each value is the name of the parameter defining the migration ratio of each population remainder_population is the source of the remaining migrants, such that the total migration ratio adds up to 1. found_time is the name of the parameter defining the time of migration.

Return type:

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.

add_pulse_migration(dest_population, source_population, rate_param, time_param)

Adds a pulse migration from source population A, parametrized by time and rate.

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.

events: dict[str:list[BaseMigrationEvent]]
execute_migration_events(migration_matrices, params)
finalize()
founder_events: dict[str, FounderEvent]
free_params: dict[str, Parameter]
get_founding_time(population)
get_index(time_param_name, population_name, params)

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

get_migration_matrices(params, solve_using_known_proportions=None)

Takes in a list of params equal to the length of free_params and returns a pg migration matrix for each population of interest where p is the number of incoming populations and g is the number of generations. If one of the parameters (time or migration) is incorrect, returns an empty matrix.

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.

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()
static load_from_YAML(source)

Creates an instance of ParametrizedDemography from a YAML file.

Return type:

ParametrizedDemography

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.parametrized_demography.PulseEvent(rate_parameter, time_parameter, source_population)

Bases: BaseMigrationEvent

__init__(rate_parameter, time_parameter, source_population)
execute(parametrized_demography, migration_matrix, params)