[SciPy-user] Newbie question
Travis E. Oliphant
oliphant at ee.byu.edu
Wed Oct 22 12:12:07 EDT 2003
Santiago Erquicia wrote:
> Sorry to do this, but I don't find any documentation about how to do this.
>
> I want to use the pdf and cdf method of the triangular distribution. I
> was looking at the constructor of the distribution and its methods and I
> really have no clue what every parameter means.
>
> In my case, I have triangular distributions with min_value = 3, mode = 5
> and max_value = 7. How do I need to construct the triangular
> distribution? triang_dist = scipy.stats.distribution.triang_gen(3,5,7)?
>
Which version of SciPy are you using?
For the current version > 0.2 the following help is provided.
There is a general pattern for all the distribution, but you have to
read the documentation (continuous.pdf) in order to understand it at all.
I am in the process of adding docstrings for all the stats functions
(does anybody know of someway to alter the docstring dynamically?)
Here is the basic idea:
All distributions are defined from a simple standard random variable
with any appropriate shape parameters. Then, the variance can be
changed by adding the appropriate scale parameter (scale=) and the mean
can be changed by adding a location parameter (loc=)
If the following variables are defined:
u --- mean of standard random variable
o --- standard deviation of standard random variable
S --- scale parameter (user supplied)
L --- location parameter (user supplied)
then the new mean and standard deviation are
u1 = S u + L
o1 = S o
For the triangle distribution, the simple standard form is a triangle
pdf between 0 and 1. The user supplies an additional shape parameter
(c) that gives the location of the peak of the triangle (0<c<1)
To get a triangle between other points you use the scale and location
parameters appropriately to shift the standard pdf.
For arbitrary shape (c), scale (S), and location (L) parameters, the
triangle pdf is defined between
L and L+S with the peak at L + cS
Conversely, to get a triangle between D and E with a midpoint at F:
L = D
S = E-D
c = (F-D)/(E-D) = (F-L)/S
For example,
To get a triangle between 3 and 7 with a midpoint at 5:
L = 3
S = (7-3) = 4
c = (5-3) / (7-3) = 0.5
> The other simple problem (not for me) is that I want to get the cdf of
> the distribution at point 6. I supposed that with triang_dist.pdf(6)
> would do it, but it asks me for two parameters. How about the pdf?
stats.triang.cdf(6,0.5,loc=3,scale=4)
stats.triang.pdf(6,0.5,loc=3,scale=4)
I will be adding simpler versions of some common distributions, but this
general approach makes remember how to use all the distributions easier
once you get used to it.
The way the distributions are implemented made it difficult to add
docstrings in the simple way (without redefining pdf and cdf for all
distributions).
I was looking for a way to add docstrings dynamically, but I never found
one. It would appear that the __doc__ attribute is read-only
At some point we may add some simpler interfaces to common distributions
--- the triangle distribution is one that has already been asked for.
Thanks for your patience.
-Travis Oliphant
More information about the SciPy-User
mailing list