Uniform Distributions
random.uniform() returns a float between 0 and 1 but if you use matplotlib and seaborn to graph the distribution, the curve has tails above 1 and below zero. The higher the sample size parameter, the more the distribution becomes flat top but it still has the tails.
The seaborn.distplot() has a label="some term here" parameter.
A logistic distribution has fatter tails than a normal distribution.
Multinomial Distribution
The multinomial function has 3 parameters:
1. The 1st argument is the number of samples.
2. 2nd argument is a list of probabilities expressed numerically or as fractions, or both. Oddly, the probabilities do not have to sum to one and can be less than one. If the probabilities sum to more than one, python will generate an error. You are permitted to insert zeros.
3. The size=(#,#,#) argument where # is an integer and an array is generated. If there is only one #, i.e. a 1-D array, then the return variable is a row vector.
Examples
from numpy import random
x = random.multinomial(n=44, pvals=[0, 0, 0, 0, 0, 1/6])
print(x)
# result is:
[ 0 0 0 0 0 44]
from numpy import random
# probabilities sum to one but there are two zeros
x = random.multinomial(n=44, pvals=[0, 2/6, 1/6, 0, 2/6, 1/6])
print(x)
# result is:
from numpy import random
# probabilities sum to one but there are two zeros
x = random.multinomial(n=1, pvals=[0, 2/6, 1/6, 0, 2/6, 1/6])
print(x)
# result is:
[0 1 0 0 0 0]
from numpy import random
# probabilities sum to one but there are two zeros
x = random.multinomial(n=12, pvals=[0, 2/6, 1/6, 0, 2/6, 1/6], size=(3,4))
print(x)
# result is:
# Note that the 3rd dimension is the number of distinct probabilities in pvals.
# So the total number of elements is 3 * 4 *6 = 72.
# Note that columns where pval =0 have a zero as the element returned.
[[[0 3 0 0 5 4]
[0 6 1 0 5 0]
[0 4 4 0 3 1]
[0 3 0 0 7 2]]
[[0 5 2 0 0 5]
[0 3 2 0 5 2]
[0 4 3 0 3 2]
[0 4 1 0 4 3]]
[[0 4 1 0 5 2]
[0 2 1 0 5 4]
[0 4 3 0 1 4]
[0 9 0 0 2 1]]]
No comments:
Post a Comment