population_config Module
Population configuration and initialization.
Overview
The population_config module handles population configuration, including survival schedules, fecundity rates, and initial population setup.
Complete Module Reference
natal.population_config
Population configuration container and related utilities.
This module defines the immutable configuration structure PopulationConfig,
functions to build, convert, and inspect configuration objects, as well as
helpers to initialise genotype/gamete mapping arrays.
The configuration is designed to be passed into simulation kernels and remains
compatible with Numba. Scalar fields are immutable (rebuild with _replace),
while NumPy arrays can be mutated in place.
PopulationConfig
Bases: NamedTuple
Primary immutable configuration container.
Scalar fields are immutable (rebuild with _replace). NumPy arrays are
mutable in-place.
Attributes:
| Name | Type | Description |
|---|---|---|
is_stochastic |
bool
|
Whether demographic events are stochastic. |
use_continuous_sampling |
bool
|
If True, use Dirichlet sampling for gamete proportions; otherwise use multinomial sampling. |
n_sexes |
int
|
Number of sexes (usually 2). |
n_ages |
int
|
Number of age classes. |
n_genotypes |
int
|
Number of diploid genotype types. |
n_haploid_genotypes |
int
|
Number of haploid genotype types. |
n_glabs |
int
|
Number of gamete‑label variants per haplotype. |
age_based_mating_rates |
NDArray[float64]
|
Shape (n_sexes, n_ages) – mating rates per sex/age. |
age_based_reproduction_rates |
NDArray[float64]
|
Shape (n_ages,) – female reproduction participation rates per age. |
age_based_survival_rates |
NDArray[float64]
|
Shape (n_sexes, n_ages) – survival probabilities. |
female_age_based_relative_fertility |
NDArray[float64]
|
Shape (n_ages,) – relative fertility of females at each age. |
viability_fitness |
NDArray[float64]
|
Shape (n_sexes, n_ages, n_genotypes) – viability fitness coefficients. |
fecundity_fitness |
NDArray[float64]
|
Shape (n_sexes, n_genotypes) – fecundity fitness coefficients. |
sexual_selection_fitness |
NDArray[float64]
|
Shape (n_genotypes, n_genotypes) – sexual selection coefficients (female genotype × male genotype). |
zygote_viability_fitness |
NDArray[float64]
|
Shape (n_sexes, n_genotypes) – zygote fitness coefficients applied during reproduction stage before survival. Represents the probability that a zygote survives to become an individual, applied before competition and viability selection. |
age_based_relative_competition_strength |
NDArray[float64]
|
Shape (n_ages,) – relative contribution to competition for each age. |
sperm_displacement_rate |
float
|
Probability that a new mating displaces stored sperm. |
expected_eggs_per_female |
float
|
Expected number of eggs per female per tick. |
use_fixed_egg_count |
bool
|
If True, use the deterministic expected egg count; otherwise sample from a Poisson distribution. |
carrying_capacity |
float
|
Current carrying capacity (scaled by population_scale). |
sex_ratio |
float
|
Proportion of newborns that are female. |
low_density_growth_rate |
float
|
Intrinsic growth rate at low density. |
juvenile_growth_mode |
int
|
Growth mode for juveniles (see constants). |
expected_competition_strength |
float
|
Pre‑computed equilibrium competition strength. |
expected_survival_rate |
float
|
Pre‑computed equilibrium survival rate. |
generation_time |
float
|
Pre‑computed mean generation time. |
new_adult_age |
int
|
Age at which individuals become adults. |
hook_slot |
int
|
Slot index for hook functions (reserved). |
has_sex_chromosomes |
bool
|
Whether the species has sex-chromosome constraints (e.g., XY or ZW systems). Used to determine if offspring sex is genotype-determined (True) or ratio-determined (False). This flag is independent of gamete modifier effects or temporary lethality. |
female_genotype_compatibility |
NDArray[float64]
|
Shape (n_genotypes,) – female-side compatibility weight per genotype. |
male_genotype_compatibility |
NDArray[float64]
|
Shape (n_genotypes,) – male-side compatibility weight per genotype. |
female_only_by_sex_chrom |
NDArray[bool_]
|
Shape (n_genotypes,) – True where genotype is female-only under sex-chromosome constraints. |
male_only_by_sex_chrom |
NDArray[bool_]
|
Shape (n_genotypes,) – True where genotype is male-only under sex-chromosome constraints. |
adult_ages |
NDArray[int64]
|
1D array of age indices that are considered adult. |
genotype_to_gametes_map |
NDArray[float64]
|
Shape (n_sexes, n_genotypes, n_hg*n_glabs) – probability of producing each (haplotype, glab) combination. |
gametes_to_zygote_map |
NDArray[float64]
|
Shape (n_hgn_glabs, n_hgn_glabs, n_genotypes) – probability of forming a given diploid genotype from two gametes. |
initial_individual_count |
NDArray[float64]
|
Shape (n_sexes, n_ages, n_genotypes) – initial population distribution. |
initial_sperm_storage |
NDArray[float64]
|
Shape (n_ages, n_genotypes, n_genotypes) – initial stored sperm counts. |
population_scale |
float
|
Scaling factor applied to carrying capacity and expected adult females. |
base_carrying_capacity |
float
|
Unscaled carrying capacity. |
base_expected_num_adult_females |
float
|
Unscaled expected number of adult females. |
set_viability_fitness
Set viability fitness for a specific (sex, genotype, age) combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sex
|
int
|
Sex index. |
required |
genotype_idx
|
int
|
Diploid genotype index. |
required |
value
|
float
|
Fitness value. |
required |
age
|
int
|
Age class; if negative, defaults to new_adult_age - 1. |
-1
|
Source code in src/natal/population_config.py
set_fecundity_fitness
Set fecundity fitness for a specific (sex, genotype).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sex
|
int
|
Sex index. |
required |
genotype_idx
|
int
|
Diploid genotype index. |
required |
value
|
float
|
Fitness value. |
required |
Source code in src/natal/population_config.py
set_sexual_selection_fitness
Set sexual selection fitness for a female‑male genotype pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
female_geno_idx
|
int
|
Female genotype index. |
required |
male_geno_idx
|
int
|
Male genotype index. |
required |
value
|
float
|
Fitness value. |
required |
Source code in src/natal/population_config.py
set_zygote_viability_fitness
Set zygote fitness for a specific (sex, genotype) combination.
Zygote fitness represents the probability that a zygote survives to become an individual, applied during reproduction stage before survival and competition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sex
|
int
|
Sex index. |
required |
genotype_idx
|
int
|
Diploid genotype index. |
required |
value
|
float
|
Fitness value (0.0 to 1.0). |
required |
Source code in src/natal/population_config.py
set_population_scale
Return a new config with the population scale factor updated.
The carrying capacity is automatically scaled accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
New population scale factor. |
required |
Returns:
| Type | Description |
|---|---|
PopulationConfig
|
A new PopulationConfig instance with updated scale and carrying capacity. |
Source code in src/natal/population_config.py
get_effective_carrying_capacity
Return the carrying capacity after applying population_scale.
Returns:
| Type | Description |
|---|---|
float
|
Scaled carrying capacity. |
Source code in src/natal/population_config.py
get_effective_expected_adult_females
Return the expected number of adult females after applying population_scale.
Returns:
| Type | Description |
|---|---|
float
|
Scaled expected adult female count. |
Source code in src/natal/population_config.py
get_scaled_initial_individual_count
Return the initial individual counts scaled by population_scale.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of shape (n_sexes, n_ages, n_genotypes) with scaled counts. |
Source code in src/natal/population_config.py
get_scaled_initial_sperm_storage
Return the initial sperm storage counts scaled by population_scale.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of shape (n_ages, n_genotypes, n_genotypes) with scaled counts. |
Source code in src/natal/population_config.py
compute_generation_time
Compute the mean generation time from the current configuration.
Uses the age‑based survival and mating rates to calculate the average age of reproduction.
Returns:
| Type | Description |
|---|---|
float
|
Mean generation time (float). |
Source code in src/natal/population_config.py
to_plain_population_config
Convert config object to a plain (copied) PopulationConfig.
If copy is True, all arrays are deep‑copied; otherwise they are referenced
directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PopulationConfig
|
Input PopulationConfig instance. |
required |
copy
|
bool
|
Whether to copy the arrays. |
True
|
Returns:
| Type | Description |
|---|---|
PopulationConfig
|
A new PopulationConfig instance (with the same scalar values). |
Source code in src/natal/population_config.py
from_plain_population_config
Compatibility adapter: returns a copied PopulationConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plain
|
PopulationConfig
|
Input PopulationConfig. |
required |
Returns:
| Type | Description |
|---|---|
PopulationConfig
|
A copied PopulationConfig (arrays are deep‑copied). |
Source code in src/natal/population_config.py
build_population_config
build_population_config(n_genotypes: int = 0, n_haploid_genotypes: int = 0, n_sexes: Optional[int] = None, n_ages: int = 2, n_glabs: int = 1, is_stochastic: bool = True, use_continuous_sampling: bool = False, age_based_mating_rates: Optional[NDArray[float64]] = None, age_based_reproduction_rates: Optional[NDArray[float64]] = None, age_based_survival_rates: Optional[NDArray[float64]] = None, female_age_based_relative_fertility: Optional[NDArray[float64]] = None, viability_fitness: Optional[NDArray[float64]] = None, fecundity_fitness: Optional[NDArray[float64]] = None, sexual_selection_fitness: Optional[NDArray[float64]] = None, zygote_viability_fitness: Optional[NDArray[float64]] = None, age_based_relative_competition_strength: Optional[NDArray[float64]] = None, new_adult_age: int = 2, sperm_displacement_rate: float = 0.05, expected_eggs_per_female: float = 100.0, use_fixed_egg_count: bool = False, carrying_capacity: Optional[float] = None, sex_ratio: float = 0.5, low_density_growth_rate: float = 6.0, juvenile_growth_mode: int = LOGISTIC, generation_time: Optional[float] = None, hook_slot: int = 0, has_sex_chromosomes: bool = False, genotype_to_gametes_map: Optional[NDArray[float64]] = None, gametes_to_zygote_map: Optional[NDArray[float64]] = None, initial_individual_count: Optional[NDArray[float64]] = None, initial_sperm_storage: Optional[NDArray[float64]] = None, population_scale: float = 1.0, age_1_carrying_capacity: Optional[float] = None, old_juvenile_carrying_capacity: Optional[float] = None, expected_num_adult_females: Optional[float] = None, infer_capacity_from_initial_state: bool = True, equilibrium_individual_distribution: Optional[NDArray[float64]] = None, external_expected_eggs: Optional[float] = None) -> PopulationConfig
Build an immutable PopulationConfig directly (legacy‑free path).
This function constructs a complete configuration, filling missing arrays with sensible defaults and computing derived values such as equilibrium metrics and generation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_genotypes
|
int
|
Number of diploid genotype types. |
0
|
n_haploid_genotypes
|
int
|
Number of haploid genotype types. |
0
|
n_sexes
|
Optional[int]
|
Number of sexes (default 2). |
None
|
n_ages
|
int
|
Number of age classes (default 2). |
2
|
n_glabs
|
int
|
Number of gamete‑label variants per haplotype (default 1). |
1
|
is_stochastic
|
bool
|
Whether to use stochastic demography. |
True
|
use_continuous_sampling
|
bool
|
Use Dirichlet sampling for gamete proportions. |
False
|
age_based_mating_rates
|
Optional[NDArray[float64]]
|
Array (n_sexes, n_ages) – mating rates. |
None
|
age_based_reproduction_rates
|
Optional[NDArray[float64]]
|
Array (n_ages,) – female reproduction participation rates. |
None
|
age_based_survival_rates
|
Optional[NDArray[float64]]
|
Array (n_sexes, n_ages) – survival probabilities. |
None
|
female_age_based_relative_fertility
|
Optional[NDArray[float64]]
|
Array (n_ages,) – relative female fertility per age. |
None
|
viability_fitness
|
Optional[NDArray[float64]]
|
Array (n_sexes, n_ages, n_genotypes) – viability fitness. |
None
|
fecundity_fitness
|
Optional[NDArray[float64]]
|
Array (n_sexes, n_genotypes) – fecundity fitness. |
None
|
sexual_selection_fitness
|
Optional[NDArray[float64]]
|
Array (n_genotypes, n_genotypes) – sexual selection coefficients. |
None
|
age_based_relative_competition_strength
|
Optional[NDArray[float64]]
|
Array (n_ages,) – competition weight per age. |
None
|
new_adult_age
|
int
|
Age at which individuals become adults (default 2). |
2
|
sperm_displacement_rate
|
float
|
Probability of sperm displacement (default 0.05). |
0.05
|
expected_eggs_per_female
|
float
|
Expected number of eggs per female per tick. |
100.0
|
use_fixed_egg_count
|
bool
|
If True, use deterministic egg count. |
False
|
carrying_capacity
|
Optional[float]
|
Optional explicit carrying capacity (scaled later). |
None
|
sex_ratio
|
float
|
Proportion of newborns that are female. |
0.5
|
low_density_growth_rate
|
float
|
Intrinsic growth rate at low density. |
6.0
|
juvenile_growth_mode
|
int
|
Growth mode (see constants). |
LOGISTIC
|
generation_time
|
Optional[float]
|
Optional pre‑computed generation time; if None, computed. |
None
|
hook_slot
|
int
|
Slot index for hooks (default 0). |
0
|
has_sex_chromosomes
|
bool
|
Whether the species has sex‑chromosome constraints. If True, offspring sex is determined by genotype compatibility; if False, only sex_ratio is used (default False). |
False
|
genotype_to_gametes_map
|
Optional[NDArray[float64]]
|
Pre‑built mapping from genotype to gametes. |
None
|
gametes_to_zygote_map
|
Optional[NDArray[float64]]
|
Pre‑built mapping from gamete pair to zygote. |
None
|
initial_individual_count
|
Optional[NDArray[float64]]
|
Initial population counts (n_sexes, n_ages, n_genotypes). If None, filled with zeros. |
None
|
initial_sperm_storage
|
Optional[NDArray[float64]]
|
Initial sperm storage counts (n_ages, n_genotypes, n_genotypes). If None, filled with zeros. |
None
|
population_scale
|
float
|
Scaling factor for carrying capacity and expected adult females. |
1.0
|
age_1_carrying_capacity
|
Optional[float]
|
Population carrying capacity at age=1. |
None
|
old_juvenile_carrying_capacity
|
Optional[float]
|
Alias for age_1_carrying_capacity (deprecated, use age_1_carrying_capacity). |
None
|
expected_num_adult_females
|
Optional[float]
|
Expected number of adult females (unscaled). |
None
|
infer_capacity_from_initial_state
|
bool
|
If True and carrying_capacity is None, compute base capacity from initial_individual_count. |
True
|
equilibrium_individual_distribution
|
Optional[NDArray[float64]]
|
Optional distribution used to compute equilibrium metrics. |
None
|
external_expected_eggs
|
Optional[float]
|
Optional override for |
None
|
Returns:
| Type | Description |
|---|---|
PopulationConfig
|
A fully populated PopulationConfig instance. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If required dimensions are invalid or shape mismatches occur. |
Source code in src/natal/population_config.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
initialize_zygote_map
initialize_zygote_map(haploid_genotypes: List[HaploidGenotype], diploid_genotypes: List[Genotype], n_glabs: int = 1, zygote_modifiers: Optional[List[Callable[..., Any]]] = None) -> NDArray[np.float64]
Initialize the gametes_to_zygote_map tensor.
The function first populates a baseline mapping following Mendelian inheritance for all haplotype pairs and gamete-label combinations, and then applies optional zygote modifiers to transform the tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
haploid_genotypes
|
List[HaploidGenotype]
|
List of all haploid genotype objects. |
required |
diploid_genotypes
|
List[Genotype]
|
List of all diploid genotype objects. |
required |
n_glabs
|
int
|
Number of gamete labels (default: 1). |
1
|
zygote_modifiers
|
Optional[List[Callable[..., Any]]]
|
Optional sequence of callables that accept and
return a modified |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of shape (n_hgn_glabs, n_hgn_glabs, n_genotypes) representing |
NDArray[float64]
|
the probability of each zygote genotype given a pair of gametes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of the input lists is empty or n_glabs is not positive. |
Source code in src/natal/population_config.py
initialize_gamete_map
initialize_gamete_map(haploid_genotypes: List[HaploidGenotype], diploid_genotypes: List[Genotype], n_glabs: int = 1, gamete_modifiers: Optional[List[Callable[..., Any]]] = None) -> NDArray[np.float64]
Create and return a genotype_to_gametes_map tensor.
This mirrors the style of :func:initialize_zygote_map: build a baseline
mapping from each diploid genotype's gamete production and then apply
optional modifier callables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
haploid_genotypes
|
List[HaploidGenotype]
|
List of all haploid genotype objects. |
required |
diploid_genotypes
|
List[Genotype]
|
List of all diploid genotype objects. |
required |
n_glabs
|
int
|
Number of gamete labels (default: 1). |
1
|
gamete_modifiers
|
Optional[List[Callable[..., Any]]]
|
Optional sequence of callables that accept and
return a modified |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
NDArray[np.float64]: Array shaped |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of the input lists is empty or n_glabs is not positive. |
Source code in src/natal/population_config.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | |
extract_gamete_frequencies
extract_gamete_frequencies(genotype_to_gametes_map: NDArray[float64], sex_idx: int, genotype_idx: int, haploid_genotypes: List[HaploidGenotype], n_glabs: int = 1) -> dict[HaploidGenotype, float]
Extract gamete frequencies for a specific (sex, genotype) pair.
This convenience function converts a row of genotype_to_gametes_map from compressed haploid-glab indices back to HaploidGenotype objects with their aggregated frequencies across all glab variants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genotype_to_gametes_map
|
NDArray[float64]
|
The (n_sexes, n_genotypes, n_hg*n_glabs) array. |
required |
sex_idx
|
int
|
Sex index (0, 1, ...). |
required |
genotype_idx
|
int
|
Diploid genotype index. |
required |
haploid_genotypes
|
List[HaploidGenotype]
|
List of all HaploidGenotype objects (aligned with indices). |
required |
n_glabs
|
int
|
Number of gamete-label variants per haplotype (default: 1). |
1
|
Returns:
| Type | Description |
|---|---|
dict[HaploidGenotype, float]
|
Dictionary mapping HaploidGenotype -> aggregated frequency across all glabs. |
dict[HaploidGenotype, float]
|
Only includes haplotype types with non-zero frequency. |
Examples:
>>> config = population._config
>>> hg_list = population._get_all_possible_haploid_genotypes()
>>> freqs = extract_gamete_frequencies(
... config.genotype_to_gametes_map,
... sex_idx=0,
... genotype_idx=5,
... haploid_genotypes=hg_list,
... n_glabs=config.n_glabs
... )
>>> # freqs = {haplotype_obj: 0.5, another_haplotype_obj: 0.5}
Source code in src/natal/population_config.py
extract_gamete_frequencies_by_glab
extract_gamete_frequencies_by_glab(genotype_to_gametes_map: NDArray[float64], sex_idx: int, genotype_idx: int, haploid_genotypes: List[HaploidGenotype], n_glabs: int = 1) -> dict[tuple[HaploidGenotype, int], float]
Extract gamete frequencies at (HaploidGenotype, glab_idx) granularity.
Unlike extract_gamete_frequencies which aggregates across all glab
variants, this function preserves the glab dimension, returning separate
entries for each (haplotype, glab) combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genotype_to_gametes_map
|
NDArray[float64]
|
The (n_sexes, n_genotypes, n_hg*n_glabs) array. |
required |
sex_idx
|
int
|
Sex index (0, 1, ...). |
required |
genotype_idx
|
int
|
Diploid genotype index. |
required |
haploid_genotypes
|
List[HaploidGenotype]
|
List of all HaploidGenotype objects (aligned with indices). |
required |
n_glabs
|
int
|
Number of gamete-label variants per haplotype (default: 1). |
1
|
Returns:
| Type | Description |
|---|---|
dict[tuple[HaploidGenotype, int], float]
|
Dictionary mapping (HaploidGenotype, glab_idx) -> frequency. |
dict[tuple[HaploidGenotype, int], float]
|
Only includes entries with non-zero frequency. |
Examples:
>>> freqs = extract_gamete_frequencies_by_glab(
... config.genotype_to_gametes_map, 0, 5, hg_list, n_glabs=2
... )
>>> # freqs = {(hg_A, 0): 0.3, (hg_A, 1): 0.2, (hg_B, 0): 0.5}
Source code in src/natal/population_config.py
extract_zygote_frequencies
extract_zygote_frequencies(gametes_to_zygote_map: NDArray[float64], gamete1_compressed_idx: int, gamete2_compressed_idx: int, diploid_genotypes: List[Genotype], n_glabs: int = 1) -> dict[Genotype, float]
Extract zygote frequencies for a specific pair of gametes.
This convenience function converts a slice of gametes_to_zygote_map from compressed gamete indices to Genotype objects with their frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gametes_to_zygote_map
|
NDArray[float64]
|
The (n_hgn_glabs, n_hgn_glabs, n_genotypes) array. |
required |
gamete1_compressed_idx
|
int
|
Compressed index of first gamete (maternal). |
required |
gamete2_compressed_idx
|
int
|
Compressed index of second gamete (paternal). |
required |
diploid_genotypes
|
List[Genotype]
|
List of all Genotype objects (aligned with indices). |
required |
n_glabs
|
int
|
Number of gamete-label variants per haplotype (default: 1). |
1
|
Returns:
| Type | Description |
|---|---|
dict[Genotype, float]
|
Dictionary mapping Genotype -> frequency. Only includes genotypes with |
dict[Genotype, float]
|
non-zero frequency. |
Examples:
>>> config = population._config
>>> genotypes = list(population._genotypes)
>>> zygote_freqs = extract_zygote_frequencies(
... config.gametes_to_zygote_map,
... gamete1_compressed_idx=0,
... gamete2_compressed_idx=1,
... diploid_genotypes=genotypes,
... n_glabs=config.n_glabs
... )
>>> # zygote_freqs = {genotype1: 1.0 or {genotype2: 0.5, genotype3: 0.5}, etc}