使用python学线性代数
When we flip a coin, there are two possible outcomes as head or tail. Each outcome has a fixed probability of occurrence. In the case of fair coins, heads and tails each have the same probability of 1/2. In addition, there are cases in which the coin is biased, so that heads and tails have different probabilities of occurrence. Coin toss experiment for number of n trails can be called as a binomial distribution.
当我们掷硬币时,有两个结果可能是正面还是反面。 每个结果都有固定的发生概率。 对于公平硬币,正面和反面的概率分别为1/2。 此外,在某些情况下,硬币会有偏差,因此正面和反面的出现概率不同。 n次追踪的硬币折腾实验可以称为二项分布 。
As per Wikipedia Definition: In probability theory and statistics, the binomial distribution with parameters n and p is the discrete probability distribution of the number of successes in a sequence of n independent experiments, each asking a yes–no question, and each with its own boolean-valued outcome: success/yes/true/one (with probability p) or failure/no/false/zero (with probability q = 1 − p). A single success/failure experiment is also called a Bernoulli trial or Bernoulli experiment and a sequence of outcomes is called a Bernoulli process; for a single trial, i.e., n = 1, the binomial distribution is a Bernoulli distribution. The binomial distribution is the basis for the popular binomial test of statistical significance.
根据Wikipedia的定义 : 在概率论和统计学中,参数n和p的二项式分布是n个独立实验序列中成功次数的离散概率分布,每个独立实验询问一个是非问题,每个实验都有其自己的布尔值结果:成功/是/正确/一个(概率为p)或失败/否/错误/零(概率为q = 1-p)。 一个成功/失败的实验也称为伯努利试验或伯努利实验,一系列结果称为伯努利过程。 对于单项试验,即n = 1,二项式分布是伯努利分布。 二项式分布是流行的具有统计意义的二项式检验的基础。
Here, we will learn to create a binomial distribution using python with Probability parameter p = 0.1.
在这里,我们将学习使用概率参数p = 0.1的 python创建二项分布。
二项式过程的Python代码 (Python code for Binomial Process)
# Linear Algebra Learning Sequence
# Binomial Process
import pylab as pl
# defining factorial function
k = 0
def fact(num):
facto = 1
while num>0:
facto = facto*num
num = num - 1
return facto
# print(fact(5)) #// for checking
# Defining power function
def exp(num,po):
ex = 1
while po>0:
ex = ex*num
po = po - 1
return ex
# print(exp(2,8)) #// for checking
# Implementation of Binomial Process
# Probability of K arrivals with
# probability of arrival as pr
# not arrival probability is 1-pr
# P = n!/(n-r)!*r! * p^r * (1-p)^n-r
# r = k
def Binomial(N,k,pr):
BinCoef = (fact(N)/(fact(N-k)*fact(k)))
ProRatio = (exp(pr,k)*exp(1-pr,N-k))
Probability = BinCoef*ProRatio
return Probability
N = 1
n = 1
k = 1
pr = 0.1
prn = 0.9
# Use of Vector to save data and
# further algebric manipulation
x = []
y = []
while n<40:
x.append(n)
y.append(Binomial(n,k,pr))
n = n + 1
pl.plot(x,y)
print('Binomial Process Vector : ', y)
Output:
输出:
Binomial Process Vector : [0.1, 0.18000000000000002, 0.24300000000000005,
0.2916, 0.32805000000000006, 0.3542940000000001, 0.37200870000000014,
0.3826375200000001, 0.38742048900000015, 0.3874204890000002,
0.3835462841100002, 0.37657271530800024, 0.36715839742530026,
0.3558612159660602, 0.3431518868244152, 0.32942581135143856,
0.3150134321048131, 0.3001892705939984, 0.2851798070642985,
0.27017034353459857, 0.25531097464019564, 0.24072177608932738,
0.22649730750223074, 0.2127105148716602, 0.19941610769218143,
0.18665347679988184, 0.17444921100912034, 0.16281926360851232,
0.1517708135779347, 0.14130386091738747, 0.13141259065317037,
0.1220865358326228, 0.11331156606965304, 0.10507072490095098,
0.09734493630529284, 0.09011359817975681, 0.08335507831627505,
0.07704712644369205, 0.07116721416246292]
翻译自: https://www.includehelp.com/python/binomial-process.aspx
使用python学线性代数