ZeroDivisionError: division by zero #461
Replies: 4 comments 2 replies
-
I'm also a bit worried about the division by standard deviation in the code, and I'd appreciate if you could explain the reason behind that. Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for opening this. I don't understand the meaning of having a standard deviation equal to 0 with a random function. What is Vensim doing in this case? Is it returning the Vensim a lot of times allows operations that make no sense, e.g. allocation functions work with negative values and give an unexpected output without raising any error or warning. So the fact that works in Vensim doesn't mean that it is working well. We are dividing by the standard deviation to have the same output as Vensim. Scipy's documentation gives more information about the distribution https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.truncnorm.html In their note they have the equation a, b = (a_trunc - loc) / scale, (b_trunc - loc) / scale while Vensim takes This transformation is tested in our test suite as we compared different distribution outputs by Vensim with the results of our translations. |
Beta Was this translation helpful? Give feedback.
-
Thank you! Vensim returns I'm not an expert, but I would use the regular random generator function and check if the returned values are within bounds (min, max). If not, I'd replace them with another draw from the function. Hope it helps, |
Beta Was this translation helpful? Give feedback.
-
Thank you,
It will take me some days to do the fix, as I am currently traveling. I will try to make it the next week.
Eneko
2025(e)ko urtarrilakren 27(a) 15:23:16 (CET)-(e)an, ali-akhavan89 ***@***.***>-(e)k hau idatzi zuen:
…Thank you!
Vensim returns `loc=mean` if `scale=std_dev=0`, same as NumPy and SciPy.
I'm not an expert, but I would use the regular random generator function and check if the returned values are within bounds (min, max). If not, I'd replace them with another draw from the function.
Hope it helps,
Ali
--
Reply to this email directly or view it on GitHub:
#461 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a simple Random Walk model that doesn't have any division formulation inside Vensim. But it seems that pysd does so during truncation calculation. If the standard deviation of the Normal Random in Vensim is zero, pysd throws the following error:
Here's the script I use:
I've also attached the .mdl and .py files.
RandomWalk.zip
Let me know if I can provide further information.
Best,
Ali
Beta Was this translation helpful? Give feedback.
All reactions