コード例 #1
0
 def base_digit_reality(cell, base = None, digit = None, total_wanted = None):
     if base is None:
         base = cell.base
     if digit is None:
         digit = cell.digit
     if total_wanted is None:
         total_wanted = cell.total_wanted
     base = float(base)
     digit = float(digit)
     k = float(total_wanted)
     total_possible_way = base**digit
     binomial_coefficient = float(alva.productA(digit)) / (alva.productA(k) * alva.productA(digit - k)) 
     total_work_way = binomial_coefficient * (base - 1)**(digit - k)
     probability = total_work_way / total_possible_way
     return (probability)
コード例 #2
0
 def base_digit_reality(cell, base = None, digit = None, total_wanted = None):
     if base is None:
         base = cell.base
     if digit is None:
         digit = cell.digit
     if total_wanted is None:
         total_wanted = cell.total_wanted
     base = float(base)
     digit = float(digit)
     k = float(total_wanted)
     total_possible_way = base**digit
     binomial_coefficient = float(alva.productA(digit)) / (alva.productA(k) * alva.productA(digit - k)) 
     total_work_way = binomial_coefficient * (base - 1)**(digit - k)
     probability = total_work_way / total_possible_way
     return (probability)
def AlvaBinomialD(i, N, p):
    B_distribution = 0.0*i
    B_distribution[:] = alva.productA(N) / (alva.productA(i[:]) * alva.productA(N - i[:]))                         * p**i[:] * (1 - p)**(N - i[:])
    return (B_distribution)
plt.title(r'$ Binomial-distribution---probability-mass-function $',fontsize = AlvaFontSize)
plt.text(0, 5.0/6, r'$ P(n|N) = \frac{N!}{n!(N - n)!} p^n (1 - p)^{N - n} $', fontsize = 1.2*AlvaFontSize)
plt.text(0, 4.0/6, r'$ 1-- \ a \ set \ of \ N \ events $', fontsize = AlvaFontSize)
plt.text(0, 3.0/6, r'$ 2-- \ either \ Success \ or \ Failure \ for \ each \ event $', fontsize = AlvaFontSize)
plt.text(0, 2.0/6, r'$ 3-- \ the \ probability-p \ is \ the \ same \ for \ all \ events $', fontsize = AlvaFontSize)
plt.text(0, 1.0/6, r'$ 4-- \ P(n|N) \ is \ the \ probability \ with \ n-success \ events \ in \ a \ total \ of \ N \ events $',
         fontsize = AlvaFontSize)
plt.savefig(save_figure, dpi = 300)
plt.show()


# In[3]:

#testing
i = 100
print ('AlvaM =', alva.productA(i))
print ('NumPy =', np.arange(1, i + 1).prod(dtype = float))


def AlvaBinomialD(i, N, p):
    B_distribution = 0.0*i
    B_distribution[:] = alva.productA(N) / (alva.productA(i[:]) * alva.productA(N - i[:]))                         * p**i[:] * (1 - p)**(N - i[:])
    return (B_distribution)

def AlvaBinomialC(m, N, p, binomialD):
    B_C = 0.0*m
    for j in range(np.size(m)):
        for k in range(m[j]):
            i = np.arange(k + 1)
            B_distribution = binomialD(i, N, p)
        B_C[j] = B_C[j] + B_distribution.sum()
コード例 #5
0
def AlvaBinomialD(i, N, p):
    B_distribution = 0.0 * i
    B_distribution[:] = alva.productA(N) / (alva.productA(
        i[:]) * alva.productA(N - i[:])) * p**i[:] * (1 - p)**(N - i[:])
    return (B_distribution)
コード例 #6
0
    2.0 / 6,
    r'$ 3-- \ the \ probability-p \ is \ the \ same \ for \ all \ events $',
    fontsize=AlvaFontSize)
plt.text(
    0,
    1.0 / 6,
    r'$ 4-- \ P(n|N) \ is \ the \ probability \ with \ n-success \ events \ in \ a \ total \ of \ N \ events $',
    fontsize=AlvaFontSize)
plt.savefig(save_figure, dpi=300)
plt.show()

# In[3]:

#testing
i = 100
print('AlvaM =', alva.productA(i))
print('NumPy =', np.arange(1, i + 1).prod(dtype=float))


def AlvaBinomialD(i, N, p):
    B_distribution = 0.0 * i
    B_distribution[:] = alva.productA(N) / (alva.productA(
        i[:]) * alva.productA(N - i[:])) * p**i[:] * (1 - p)**(N - i[:])
    return (B_distribution)


def AlvaBinomialC(m, N, p, binomialD):
    B_C = 0.0 * m
    for j in range(np.size(m)):
        for k in range(m[j]):
            i = np.arange(k + 1)
コード例 #7
0
def binomialPMF(total_event, p):
    x_event = np.arange(1, total_event + 1)
    y_PMF = alva.productA(total_event) / (alva.productA(x_event) * alva.productA(total_event - x_event))                         * p**x_event * (1 - p)**(total_event - x_event)
    return np.array([x_event, y_PMF])