Repository navigation
Refine variance mappings, colony indexing, and brood summaries - #2
janaobsteter merged 21 commits into
Conversation
|
Ok, tests on GitHub finally pass;) |
|
@janaobsteter I noticed that we were not consistent with colony ID - it was integer/numeric, whereas in AlphaSimR we have them character so they behave as names. This is very important for indexing (see expanded tests). ALSO, I don't know why you changed colony ID to queen ID. This is not the same thing. Colony is an entity that holds the queen, so if we use queen ID for the colony ID, we would then have just one ID (of the queen) and be done with it. But, we can have a colony without the queen, so the colony would then also be without the ID, which does not make sense, since we can still have such a colony at some point in time. I know this is PITA, but being pedantic with such bits really is important or you can't reason safely about what an ID means and what does it represent. I feel that both of these points could have been baked in some of your scripts that you have developed - would be good to check and fix this in the scripts. I will run some more local tests to check if we conflated the two anywhere. |
|
Yeah, this colony/queen ID assumption is already causing issues/bugs - see HighlanderLab#644 |
janaobsteter
left a comment
There was a problem hiding this comment.
Leaving some comments below
| #' so it contributes one missing ID and preserves alignment with the MultiColony's entries. | ||
| #' An empty Pop or MultiColony contains no individuals or entries to identify. | ||
| #' An empty colony created with \code{createColony()} still has an assigned ID; | ||
| #' an uninitialised \code{new("Colony")} has no assigned ID. |
There was a problem hiding this comment.
MultiColony would only have IDs if create with TRUE for
@PARAM populateColonies boolean, whether to create n empty Colony objects within with assigned ID
#'
There was a problem hiding this comment.
I think we should discuss the colony vs queen ID. I think the current logic is broken the way we have it implemented. I think we started with colony ID (=ID of the colony as a physical entity) and queen ID (=ID of the queen leading the colony). I am fully aware that these two IDs are used interchangeably, however I think this is bad from data management perspective since a colony can be without a queen for a while, so we need to have an ID of that empty entity and without a queen it won't have one if there is no queen. An option would be for the getId(colony) to just call getId(colony@queen) and drop colony IDs altogether, but I still don't understand what one would use for colony ID that does not have the queen and some functions like getId could return NA/NULL which becomes PITA to handle in scripting. Happy to discuss and drop these colony/queen IDs from the PR (I tried to do to many things). Thoughts?
There was a problem hiding this comment.
We started off without colony IDs, then realised we need them. I can't find in the issues exactly why but part of the issue was that two colonies could have the same queen, and also, when the queen changes, the offspring in the hive is still from the previous queen, so need to track the hive separately. However, in the simulation, we would track the queen since we are tracking the genetics. I suggest we keep the colonyIDs for now (separate from queen IDs)
There was a problem hiding this comment.
FYI Now we do have a warning that a queen is already in another colony, I think, I got a warning to this effect when I was doing polishing of this PR tests.
OK, I am glad to hear that we are converging on keeping hive/colony ID and queen ID as separate. I think the challenge will now be to ensure this works well and as intended. We have an issue at HighlanderLab#644 for this, so I think we just need to ensure that current code/PR is as it should and then we systematically address the HighlanderLab#644 issue.
|
|
||
| if (!workersFUN %in% c("sum", "mean")) { | ||
| stop("Invalid value for workersFUN. We currently only support either 'sum' or 'mean'.") | ||
| #' Calculate coefficients to map across individual and colony variances |
There was a problem hiding this comment.
This all is a bit long for function description, can we shorten?
There was a problem hiding this comment.
Hmm, I agree it's long, and I genuinely spent a lot of time trying to cut down on the words, while still communicating what is what. Can you suggest what to cut?
| #' | ||
| #' @description Level 2 function that re-queens a Colony or | ||
| #' MultiColony object by adding a mated or a virgin queen, removing the | ||
| #' previous queen, and changing the colony id to the new mated queen. |
There was a problem hiding this comment.
The code actually wasn't doing this
There was a problem hiding this comment.
Indeed! So, where do we then assign the new ID to colony then? Looks like we caught a bug here - do you agree? - we initially had colony and queen IDs separate, then I think you were fed up by this and started migration to colony ID = queen ID, but did not implemented that across all the package? Is that a fair summary. Let's discuss how to manage this.
| if (isColony(x)) { | ||
| swarmColony <- createColony(x = x@queen, simParamBee = simParamBee) | ||
| # It's not re-queening, but the function also sets the colony id | ||
| # The swarm receives a new colony ID, independent of its queen ID |
There was a problem hiding this comment.
Re this and the comment in the discussion - I think we were discussing whether the colony ID tracks he physical hive or the genetics. But the genetics is tracked with the queen's ID
There was a problem hiding this comment.
I think this is more complicated and my worry is more about indexing when queen is missing and such edge cases. If we want that colony ID = queen ID then we just make the getId(colony) call getId(colony@queen), but that can also return NA/NULL which are annoying to handle. Let's discuss or maybe pull out from this PR.
|
|
||
| ## Bug fixes | ||
|
|
||
| - Moved `future` to Suggests because it is used by the parallelisation vignette; |
There was a problem hiding this comment.
This was not "moved" since it is not present in the previous version
Co-authored-by: Gregor Gorjanc <gregor.gorjanc@gmail.com>
|
@janaobsteter I think I went over all your comments - good critical stuff! ;) See my replies and suggest how we should move onwards. |
|
@janaobsteter I did some security checking of the code and Codex suggested changes in gregorgorjanc@e00f9d3 (after my review/polish). I think the nParalleleWorkers and nThreads bit can be quite important (and confusing!) detail. It also suggested some args handling in the passed functions - I only did one and left the rest for future so this PR doesn't digress (it already is!): HighlanderLab#646 |
|
OK, then let's leave it in, it's also easier to correct latter |
|
@gregorgorjanc , if you just move future back to imports and change the text above (if you see any merit), then I will merge this PR and let's move on. I think colony ID handling should be ok, with the exception of that case in swarm where it overwrote it with the queenID (not sure what happened there). |

This updates variance mappings and colony indexing together, preserving the changes on Jana’s
Futurebranch.Colony IDs are consistently character IDs and remain independent of queen IDs when queens are removed or replaced. Numeric indexing selects positions; character indexing selects colony IDs. Crossing plans support non-numeric donor-colony IDs and reordered colony names, with regression tests for missing entries, empty collections, subsetting, and replacement.
The forward and inverse variance mappings distinguish within-bee covariance from queen–worker covariance, support explicit colony design coefficients and random or balanced worker allocation, validate inputs, and handle zero variance. Both mappings return
h2Queen,h2Worker,h2WorkerGroup, andh2Colony. Brood summaries handle queenless colonies and empty populations consistently; simulation-parameter forwarding andsplitPColonyStrength()are corrected. Updated help, vignettes, shared references, and release notes accompany these changes.The consolidated agent guidance replaces the duplicate agent file. Build exclusions cover development material, including
AGENTS.mdandTestingVarianceComponents.R.futureis moved from Imports to Suggests for vignette use; package functions importfuture.apply, removing the unused-import NOTE.Validation of the consolidated tree committed as
59a15c4:devtools::check(document = FALSE), including vignette rebuilds: 0 errors, 0 warnings, 0 notes.getCastetest. The installed testthat also reports being built under a newer R patch version.git diff --check: clean.