Semen Allocation#2966
Conversation
|
Current Coverage: % Mypy errors on semen_allocation branch: 1229 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on semen_allocation branch: 1233 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on semen_allocation branch: 1221 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on semen_allocation branch: 1221 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on semen_allocation branch: 1221 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on semen_allocation branch: 1221 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Thanks for putting this together, Allister! The whole framework is here! I like the direction of making semen allocation percentile-based and keeping Main things I noticed1. Ranking index calculation seems inconsistentI think the individual animal ranking index and the population ranking list are currently being calculated with different formulas. For the individual animal, ranking_index = 0.318 * EBV_fat + 0.13 * EBV_proteinBut the population list used for breeding around ranking_index_for_breeding = 0.71 * EBV_fat + 0.29 * EBV_proteinThen later, np.array(population_ranking_index) <= animal_ranking_indexI think that comparison only works if both sides are calculated with the same formula/scale. Otherwise the percentile may be biased. In this case, since the individual value is on a smaller scale, I would expect animals to get artificially low percentiles, which could skew the semen allocation. Could we make the ranking index calculation come from one shared source of truth? For example, the same helper function or the same configured weights could be used both for the animal-level value and for the population ranking list. 2. The gate for selective reproduction seems to have drifted
The issue is more around when we build/pass the ranking list. From what I can tell, the ranking list is only built when all of these are true, around simulate_genetics
and selective_repro_strategy
and ranking_method == "genetic"
and all eligible animals have ranking indexesBut on the consume side, selective_repro_strategySo there are some config combinations that can reach selective_repro_strategy: true
ranking_method: nullor: selective_repro_strategy: true
ranking_method: "genetic"
simulate_genetics: falseThese eventually hit something like: np.mean(np.array(None) <= None)which gives a Could we do two things here?
Also, for the genuinely empty-list case, we may want a defined fallback or a clear error. Right now 3. Calf sex rate constants may need one source of truthI noticed this in the animal constants: BEEF_MALE_CALF_RATE = 0.1I would guess this is a typo? the male calf rate is expected be closer to I also saw that male_calf_rate_conventional_semen: float = 0.53
male_calf_rate_sexed_semen: float = 0.10
selective_repro_strategy: bool = False
ranking_method: str = "genetic"
genetic_selection_index_weights: dict[str, float] = {
"fat": 0.71,
"protein": 0.29,
}
heiferII_semen_allocation_proportions: dict[str, float] = {
"sexed_dairy": 0.5,
"conventional_dairy": 0.5,
"beef": 0.0,
}
cow_semen_allocation_proportions: dict[str, float] = {
"sexed_dairy": 0.2,
"conventional_dairy": 0.5,
"beef": 0.3,
}I am not totally sure whether these config fields are still active or stale. If the new code now uses hardcoded constants while these config fields still exist, we may have multiple sources of truth. Could we either remove the stale config fields or route these values through config consistently? I think this would make it clearer where calf sex rates, ranking weights, and semen allocation proportions are supposed to come from. Side bug I found while debuggingI also saw this output: This looks like a real lifecycle issue. Together with Claude, we found for cow
So again the problem is the sampling from the animal pool. Could we add a guard before synchronization setup and/or before This affects calf sex outputs and hormone use/AI/semen stats, but I think it's not in this PR's scope. If it looks right to you, I can create an issue for this. And you can fix it in another smaller bug-fixing PR. |
Context
Issue(s) closed by this pull request: closes #
What
Why
How
Test plan
Input Changes
Output Changes
Filter