Open rheiland opened 5 years ago
In the following function (in /engine/src/), if we allow for a rate=0, i.e., "random_rate >= 0.", then it runs OK.
NodeIndex MaBEstEngine::getTargetNode(RandomGenerator* random_generator, const MAP<NodeIndex, double>& nodeTransitionRates, double total_rate) const
{
double U_rand2 = random_generator->generate();
double random_rate = U_rand2 * total_rate;
MAP<NodeIndex, double>::const_iterator begin = nodeTransitionRates.begin();
MAP<NodeIndex, double>::const_iterator end = nodeTransitionRates.end();
NodeIndex node_idx = INVALID_NODE_INDEX;
while (begin != end && random_rate > 0.) {
node_idx = (*begin).first;
double rate = (*begin).second;
random_rate -= rate;
++begin;
}
assert(node_idx != INVALID_NODE_INDEX);
assert(network->getNode(node_idx)->getIndex() == node_idx);
return node_idx;
}
It turns out, the reason is that
random_generator->generate();
can return a 0 (and 1) on MinGW, but not OSX/Linux. Perhaps the PRNG is inclusive on MinGW, i.e., returns [0,1], but exclusive, (0,1), on OSX/Linux.
Note, in the config file, Four_cycle_FEscape.cfg
, we have:
use_physrandgen = FALSE;
//use_physrandgen = TRUE;
Probably need to take a closer look at what's happening in RandomGenerator.h
:
public:
StandardRandomGenerator(int seed) : seed(seed) {
#ifdef HAS_RAND48_T
memset(&data, 0, sizeof(data));
srand48_r(seed, &data);
#elif defined(HAS_RAND48)
srand48(seed);
#else
srand(seed);
#endif
}
Thanks, Randy!
Others on this list, is that reasonable?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Paul Macklin, Ph.D. Associate Professor
Director of Undergraduate Studies
Intelligent Systems Engineering Indiana University Founder and Lead of PhysiCell http://physicell.mathcancer.org/ and MultiCellDS http://multicellds.org/ mobile: 626-372-1203 <(626)%20372-1203> email: macklinp@iu.edu email: Paul.Macklin@MathCancer.org web: http://MathCancer.org http://mathcancer.org/ Twitter: @MathCancer http://www.twitter.com/MathCancer
On Thu, Jan 24, 2019 at 12:47 PM Randy Heiland notifications@github.com wrote:
In the following function (in /engine/src/), if we allow for a rate=0, i.e., "random_rate >= 0.", then it runs OK.
NodeIndex MaBEstEngine::getTargetNode(RandomGenerator random_generator, const MAP<NodeIndex, double>& nodeTransitionRates, double total_rate) const { double U_rand2 = random_generator->generate(); double random_rate = U_rand2 total_rate; MAP<NodeIndex, double>::const_iterator begin = nodeTransitionRates.begin(); MAP<NodeIndex, double>::const_iterator end = nodeTransitionRates.end(); NodeIndex node_idx = INVALID_NODE_INDEX; while (begin != end && random_rate > 0.) { node_idx = (begin).first; double rate = (begin).second; random_rate -= rate; ++begin; }
assert(node_idx != INVALID_NODE_INDEX); assert(network->getNode(node_idx)->getIndex() == node_idx); return node_idx; }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rheiland/maboss_pc/issues/1#issuecomment-457290886, or mute the thread https://github.com/notifications/unsubscribe-auth/AKubcDV97MpaiKrOLMoTTFouZ34Vnj1bks5vGfHAgaJpZM4aRYWZ .
Is it total_rate or U_rand2 that is =0 when this error occurs ?
Le jeu. 24 janv. 2019 à 19:06, Paul Macklin notifications@github.com a écrit :
Thanks, Randy!
Others on this list, is that reasonable?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Paul Macklin, Ph.D. Associate Professor
Director of Undergraduate Studies
Intelligent Systems Engineering Indiana University Founder and Lead of PhysiCell http://physicell.mathcancer.org/ and MultiCellDS http://multicellds.org/ mobile: 626-372-1203 <(626)%20372-1203> email: macklinp@iu.edu email: Paul.Macklin@MathCancer.org web: http://MathCancer.org http://mathcancer.org/ Twitter: @MathCancer http://www.twitter.com/MathCancer
On Thu, Jan 24, 2019 at 12:47 PM Randy Heiland notifications@github.com wrote:
In the following function (in /engine/src/), if we allow for a rate=0, i.e., "random_rate >= 0.", then it runs OK.
NodeIndex MaBEstEngine::getTargetNode(RandomGenerator random_generator, const MAP<NodeIndex, double>& nodeTransitionRates, double total_rate) const { double U_rand2 = random_generator->generate(); double random_rate = U_rand2 total_rate; MAP<NodeIndex, double>::const_iterator begin = nodeTransitionRates.begin(); MAP<NodeIndex, double>::const_iterator end = nodeTransitionRates.end(); NodeIndex node_idx = INVALID_NODE_INDEX; while (begin != end && random_rate > 0.) { node_idx = (begin).first; double rate = (begin).second; random_rate -= rate; ++begin; }
assert(node_idx != INVALID_NODE_INDEX); assert(network->getNode(node_idx)->getIndex() == node_idx); return node_idx; }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rheiland/maboss_pc/issues/1#issuecomment-457290886, or mute the thread < https://github.com/notifications/unsubscribe-auth/AKubcDV97MpaiKrOLMoTTFouZ34Vnj1bks5vGfHAgaJpZM4aRYWZ
.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rheiland/maboss_pc/issues/1#issuecomment-457297338, or mute the thread https://github.com/notifications/unsubscribe-auth/Ag6hYXnZSr15szwj3nprLoR9ih2UfPXuks5vGfYwgaJpZM4aRYWZ .
I'm not sure if people are notified when I edit a previous entry, but I did - see above. Basically, U_rand2 can be 0. I suggested that I/we have a closer look at StandardRandomGenerator...
Ok, I see the edit now. If this inclusion of 0 and 1 does not happen frequently, i think the fix you propose of putting random_rate >=0 is totally fine. But we should keep in mind that there is this difference, I am not sure if it can play a role in other functions. Or add in the StandardRandomGenerator that if result is exactly 0 or 1, to change it by 0+epsilon and 1-epsilon to be sure to exclude it ?
I agree that adding the random_rate >=0 part is a good solution. I should check if this is used elsewhere, but afaik it is not. Cheers!
This test runs OK on Linux and OSX, but fails on MinGW.