Closed pixelzoom closed 4 years ago
I'm going to shake this down next week. Then I'll be assigning to @amanda-phet for review.
I went through this a couple of times, and it's ready for @amanda-phet to verify in master or 1.1.0-dev.4. Feel free to assign to anyone else that you might also want to have verify.
High priority, since this blocks the 1.0 prototype.
- [ ] From #153, limited food is ignored when the total population is < 6.
For this constraint, I realized that the recessive mutants who are waiting to meet eagerly were being excluded from "total population". After discussing with @amanda-phet, we decided to fix this, since it was easy and less likely to result in future confusion. That change was made in the above commit.
Please do any further testing with master or 1.1.0-dev.5.
@amanda-phet FYI...
If apply Limited Food from the beginning, or in the first generation or two, then either the population stabilizes and I reach the 1000-generation limit, or all bunnies die.
But if I wait to apply Limited Food until generation 5, then I can definitely get the bunnies to take over the world. Since food doesn't affect birth rate in our model, bunnies will be born faster than they die of starvation. Not sure if this is a problem that concerns you, but thought I'd mention it.
If apply Limited Food from the beginning, or in the first generation or two, then either the population stabilizes and I reach the 1000-generation limit, or all bunnies die.
But if I wait to apply Limited Food until generation 5, then I can definitely get the bunnies to take over the world. Since food doesn't affect birth rate in our model, bunnies will be born faster than they die of starvation. Not sure if this is a problem that concerns you, but thought I'd mention it.
This behavior bugs me too. I mentioned using fertility in https://github.com/phetsims/natural-selection/issues/158#issuecomment-669291680 but it sounded like it would be difficult to implement? And KP suggested a tiered death model https://github.com/phetsims/natural-selection/issues/153#issuecomment-668709577.
I wonder if we could explore what @pixelzoom wrote in that issue https://github.com/phetsims/natural-selection/issues/153#issuecomment-668715751
Rather than a tiered approach that relies on ranges... If you can describe the number of bunnies to kill (K) as a function of the total population (N), that's something that might be dropped into the current model.
I guess it depends on how realistic we want to make this. In real life, mice (and probably bunnies) eat their young when food becomes scarce. But my understanding was that we were not going for "real life", we were consciously limiting the things that environmental factors affect.
Making food affect fertility (or longevity) is a can of worms that we really do not want to open. The reproduction code is very complicated, and there is no accommodation built in for environmental factors.
Computing "percent to starve" as a function of the total population is still an option. It will be easier (but not at all trivial) to modify the food code for that. It will be the 4th major refactor.
Slack discussion with @amanda-phet:
Amanda McGarry:spiral_calendar_pad: 3:10 PM
If apply Limited Food from the beginning, or in the first generation or two, then either the population stabilizes and I reach the 1000-generation limit, or all bunnies die.
But if I wait to apply Limited Food until generation 5, then I can definitely get the bunnies to take over the world. Since food doesn’t affect birth rate in our model, bunnies will be born faster than they die of starvation. Not sure if this is a problem that concerns you, but thought I’d mention it.
I’m not sure this is true, and can’t find an explanation for why that is the case. Bunnies shouldn’t be born faster since the average rate that they die of starvation is .665, which is very close to compensating for the birth rate.
So, yes it would concern me, but I am not sure what you’re saying is accurate. When you say “definitely”, that is going to be true for many cases that go on for many many generations, since .665 < 2/3, but it’s close enough that it shouldn’t happen often. However it’s never going to be perfectly balanced (and I don’t really want it to be so perfect that there’s no variation)
Chris Malley 3:16 PM
I said "definitely" because I've seen it happen multiple times, usually > 500 generations.
0.65 is the average of limitedFoodPercentToKill=[0.6, 0.73]. But because it's randomly selected, you may not get that average, even over a few hundred runs. And you could get a value repeatedly that results in bunnies reproducing faster than they die of starvation. If it's OK that that happens occasionally, we're OK. I was just pointing out that it can happen, not that it always happens. (edited)
Amanda McGarry:spiral_calendar_pad: 3:24 PM
yes I understand it can happen. I don’t think we need something really sophisticated that says “whoa, if the population starts getting too large, make sure more die.” So I think it’s ok if it’s happening after a long time. If it was happening consistently within 20 generations I’d be more concerned.
On Slack, I said:
I said "definitely" because I've seen it happen multiple times, usually > 500 generations.
I need to correct this statement. I can make this happen consistently in a couple of generations.
Start the sim with ?log&labPopulation=500&secondsPerGeneration=1&limitedFoodPercentToKill=0.6,0.6
. This will allow us to simulate what happens if we turn on "Limited Food" with a large population (500) and 0.6 is chosen as the percentage to starve. Go to the Lab screen, check "Limited Food", press "Play". Bunnies will take over the world every time at Generation 3. If `labPopulation is larger, it happens even faster.
With labPopulation=600
, bunnies take over the world at Generation 2. With 700
, they take over at Generation 1.
limitedFoodPercentToKill=0.665,0.665
is the sweet spot where the problem goes away for labPopulation=700
So I think limitedFoodPercentToKill
needs to be adjusted.
More Slack:
Amanda McGarry:spiral_calendar_pad: 9:51 AM
the current limitedFoodPercentToKill
range averages to .665 I thought. Are you suggesting we don’t do a range, but just do [.665,.665] so we don’t have variability?
Chris Malley 9:51 AM
limitedFoodPercentToKill=[0.6, 0.73]
I'm not suggesting we keep it constant. I'm demonstrating what happens if the min is randomly selected.
Amanda McGarry:spiral_calendar_pad: 9:52 AM ok so 0.65, not it’s not 0.6. what about [0.665,0.667]? I think a tighter range would be fine
Chris Malley 9:52 AM If you want to prevent the population from taking over the world, you can't rely on the average occurring over a small number of generations. If you want to guarantee that they won't take over the world, then the range's min needs to be the value that prevents that from happening.
Amanda McGarry:spiral_calendar_pad: 9:53 AM When I run the sim for many generations, it looks very odd to me when the population is exactly the same from generation to generation, and it looks a lot more natural when there is some variability. But I do see the problem when the population is really large. And you’re saying the population won’t die out because if it’s <7 they won’t starve? We don’t want them to die out or take over, so I’m just trying to clarify
Chris Malley 9:55 AM
I'm saying that there are values of limitedFoodPercentToKill
for which bunnies will reproduce faster than they will starve, and they can therefore take over the world.
Amanda McGarry:spiral_calendar_pad: 9:55 AM Right, but there are also values for which they will die faster than they will reproduce, so we have to think about both bounds
Chris Malley 9:56 AM I'm sort of feeling like we should take a step back and reevaluate this entire food model. I've never been clear on the behavior that we're trying to produce. Perhaps we should write that down.
Amanda McGarry:spiral_calendar_pad: 9:57 AM The only behavior we’ve ever tried to produce with Limited Food is “stable population.” Figuring out how to do that is how these issues have come up.
Chris Malley 9:57 AM And I really do hate to suggest that. But having to describe this model when writing model.md raised a lot of red flags for me.
That's not true of Limited Food. There is also interaction with Tough Food, in which case the behavior is not stable population. And stable population is sometimes impossible if the remaining bunnies die of old age.
If you want stable population, then why don't we just keep track of how many bunnies were born, and starve exactly that number of bunnies? Then the population will be exactly stable on every application of limited food (without tough food).
Amanda McGarry:spiral_calendar_pad: 10:06 AM Sure. Maybe we can discuss this later today? Although I think both of us are pretty booked up. I would say we still want a similar behavior for tough food too, but within those killed, a higher percentage should be bunnies with short teeth. Eventually all the short-tooth bunnies will die, and there should be a stable population of long-tooth bunnies. I think that using the current model we are achieving this, but if we changed the model I wanted to mention how that should work.
Until we discuss this more, please defer review of the checklist in https://github.com/phetsims/natural-selection/issues/169#issue-674682344.
At 8/13/20 design meeting:
@kathy-phet suggested choosing a population limit (say 200, or [190,210]) that could be supported by limited food, and killing bunnies above that limit. This sounds promising. Needs to be discussed more, and how it would interact with tough food.
@kathy-phet suggested changing the order of food and wolves. We weren't sure why this would be necessary or advantageous.
We scheduled a tentative "food" design meeting for 8/18/20, sometime between 9:00am-12:00pm.
As I did in https://github.com/phetsims/natural-selection/issues/172#issuecomment-674299093 for wolves, I've added logging of the toughFoodPercentToKill
and limitedFoodPercentToKill
values that are randomly chosen. You'll see log messages like these:
randomly selected 0.6919790166629384 from limitedFoodPercentToKill
randomly selected 0.5398062137886961 from toughFoodPercentToKill
In 8/18/2020 design meeting, we devised major changes for the food model. So this issue will be closed because it is now irrelevant. The new food model will be reviewed in https://github.com/phetsims/natural-selection/issues/183.
Food.starveBunnies
is where tough food and limited food are applied. This bit of code has incrementally had additional constraints added, to a point that is has become unacceptably complicated/chaotic for code for an unpublished sim. And it was making it difficult for me to debug/fix issues like #158, #161, and #168.So
Food.starveBunnies
was refactored and cleaned up, and we (unfortunately) need to do a complete sanity check.Things to verify:
[ ] From #98, for limited food without tough food: The percentage of bunnies that starve is the same for both phenotypes, a random value from
limitedFoodPercentToKill
.[ ] From #98, for with tough food without limited food: The percentage of long-tooth bunnies that starve is a random value from
toughFoodPercentToKill
.The percentage of short-toothed bunnies that starve is the same random value from
toughFoodPercentToKill
, multiplied byshortTeethMultiplier
.[ ] From #98 tough food + limited food combined: The percentage of long-tooth bunnies that starve is a random value from
toughFoodPercentToKill
, multiplied bylimitedFoodMultiplier
.The percentage of short-toothed bunnies that starve is the same random value from
toughFoodPercentToKill
, multiplied byshortTeethMultiplier
, multiplied bylimitedFoodMultiplier
.[ ] From #153, limited food is ignored when the total population is < 6.
[ ] From #98, tough food is ignored for long-teeth bunnies when the number of long-teeth bunnies < 5.
[ ] For #161, limited food does not prefer long teeth.
[ ] For #158, bunnies do not take over the world when limited food is the sole selection factor.
[ ] For #158, it's OK for bunnies to sometimes die out when limited food is the sole selection factor. The bunnies that didn't starve may die of old age at the beginning of the next generation.
[ ] For #158, applying food is not skipped over in a generation clock cycle. If one of the food-related checkboxes is checked and the bunny population is not zero, then for each generation you should see a log message that says "Applying food: ..."
Please verify with
?log
. Please DO NOT use?secondsPerGeneration
and the fast-forward button together!For any reported problems, please include: