Patches item #1681432, was opened at 2007-03-15 14:09 Message generated for change (Comment added) made by miathan6 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1681432&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Library (Lib) Group: Python 2.6 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Wladmir van der Laan (miathan6) Assigned to: Raymond Hettinger (rhettinger) Summary: Add triangular distribution to random Initial Comment: This patch adds the so called Triangular distribution for random values. It is often used in simulations when an upper and lower bound is known, and a most likely value but not the exact distribution. This distribution interpolates these values linearly. http://en.wikipedia.org/wiki/Triangular_distribution ---------------------------------------------------------------------- >Comment By: Wladmir van der Laan (miathan6) Date: 2007-05-02 11:28 Message: Logged In: YES user_id=49336 Originator: YES I found one catch that we might want to avoid. If you input integers into this function instead of floats, it breaks. It might be a good idea to wrap the parameters in float(arg). ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2007-04-03 03:43 Message: Logged In: YES user_id=80475 Originator: NO Will get this fixe-up and applied to Py2.6. That is due out any time soon, so I'll keep it on my todo list for a bit. ---------------------------------------------------------------------- Comment By: Mark Dickinson (marketdickinson) Date: 2007-03-17 17:54 Message: Logged In: YES user_id=703403 Originator: NO Looks correct to me, and seems to work well with correct parameters. The arguments to the square roots are never negative; this means that we get silent failure (that is, some distribution that isn't the triangular distribution) if the input parameters don't satisfy left <= center <= right. Maybe the inputs should be checked, and a ValueError raised on bad input? If the test "x < (center-left)/(right-left)" is replaced by "x*(right-left) < (center - left)" then the code does the right thing in the limit-case when left == center == right (that is, it gives a delta distribution at center); currently it'll raise a ZeroDivisionError in this case. It's not clear to me which behaviour should be preferred. ---------------------------------------------------------------------- Comment By: Paul Hankin (paulhankin) Date: 2007-03-17 17:12 Message: Logged In: YES user_id=1740099 Originator: NO Some minor quibbles: the distributions in random name their parameters after the most common use in math text books. Is n't that 'a, b, c' here rather than 'left, right, center' (note, different order too)? Admittedly your parameter names are clearer. There's not total consistency in random, but it looks like 'triangularvariate' would be the right name for the function - although my knowledge of stats is sketchy, so perhaps there's a distinction I'm not aware of. Indentation and spacing around operators needs fixing also. ---------------------------------------------------------------------- Comment By: Wladmir van der Laan (miathan6) Date: 2007-03-16 09:57 Message: Logged In: YES user_id=49336 Originator: YES Yes, I will add some tests and docs, although usage is quite straightforward. That's the main reason also for adding this distribution, it has three parameters which are intuitive (left, center and right) the distribution is just a linear interpolation (P(left)=0 and P(center)=1 and P(right)=0 ). I am writing an event simulation and I added it because I was missing some kind of assymetric distribution for timings; in an uniform distribution t-x and t+y would be just as likely as t, in a gaussian distribution you can only set sigma but not the upper and lower bound. With all the other distributions in there I thought it might come in handy for other people too. I also believe it has its uses in sound generation/processing. Sorry for providing a patch against 2.3 and not 2.5 or higher, I cooked it up at work and it seems I have this ancient version here. ---------------------------------------------------------------------- Comment By: Collin Winter (collinwinter) Date: 2007-03-16 03:22 Message: Logged In: YES user_id=1344176 Originator: NO Could you work up some tests (Lib/test/test_random.py) and docs (Doc/lib/librandom.tex) for this? An explanation of why you think this should be included in the standard library would be helpful, too. Also, it seems you made this patch against Python 2.3. While this particular patch still applied (relatively) cleanly to Python 2.6a0 source, Python 2.3 is no longer supported and most patches made against it have a high probability of inapplicability. See http://www.python.org/dev/faq/ for information on how to obtain a read-only checkout of the latest source code. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1681432&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches