Year varying categories produce incorrect answers across many processes/objections
Zaita opened this issue · 3 comments
I HAVE DISABLED YEAR VARYING CATEGORIES IN CASAL2 UNTIL THIS IS RESOLVED
Describe the bug
Any object in Casal2 that has vectors of parameters correlating to categories and using a for(i = 0) style look will have calculation issues when year varying categories are implemented.
e.g.
@process p
categories male female
selectivities M F
The above will work fine when correlating category name to the selectivity index (e.g. if i = 0 then male and M are selected, if i = 1 then female and F are selected).
When we introduce year varying categories this breaks
@process p
categories male male.2000 female female.2000 # .2000 only valid in year 2000
selectivities M M F F
During years other than 2000, the lookup will be i == 1 then male.2000 and M are selected.
If year == 2000 and i == 1 then female and M are selected.
The list of selecitivities is a constant length, but the list of categories is not. So we can end up in scenarios where a category is using an incorrect selectivity because the category list size has changed due to year variations.
Release version(s) and/or repository branch(es) affected?
All
Operating system type and version (and build tools types and versions, if applicable)
All
Steps to reproduce the bug
Run a model with pretty much any process or observations and year varying categories.
Expected behavior
The other parameters that are indexed based on the category year are also modified to ensure the relationships are maintained.
Actual behavior
N/A
Screenshots
N/A
Additional context
This is a significnt problem for Casal2. It appears that after Year varying categories were implemented originally (circa 2014) that no testing or validation has been done on them as new functionality has been added to Casal2. The basic year varying category unit tests continue to work as expected, but processes/observations that have been added since do not make any considerations for the year varying category concepts.
Fixing this will require building a new method of interacting with the partition/categories that forces future developers to ensure they're aligning different vectors properly to automatically handle parameter association.
I HAVE DISABLED YEAR VARYING CATEGORIES IN CASAL2 UNTIL THIS IS RESOLVED
As discussed there are two approaches to fixing this.
- Is less elagent but fairly easy to implement, and that is have a flag on each category to indicate whether it is available this year i.e.
auto iterator = partition_.begin();
for (unsigned i = 0; i < partition_.size() && iterator != partition_.end(); ++i, ++iterator) {
if((*iterator)->available_this_year()) {
// dosomething
}
- The second which would be prefered, but would require high level input and a lot more work is to re-design the accessors.
closed, depreciated for now. On the future feature list
Casal2PartitionTimeVaryingFix.zip
From Scott.
"The summary is that you template the partition accessors, then pass them a unique attribute object per process that contains the elements you want associated with each category. Then the accessor returns the attributes for each category as part of the iteration
I am using a map in the example because it's quicker. In Casal2 I'd use an indexed vector to be significantly quicker"