使用python学线性代数_二项式过程| 使用Python的线性代数

秒速五厘米 2023-03-05 12:36 204阅读 0赞

使用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)

  1. # Linear Algebra Learning Sequence
  2. # Binomial Process
  3. import pylab as pl
  4. # defining factorial function
  5. k = 0
  6. def fact(num):
  7. facto = 1
  8. while num>0:
  9. facto = facto*num
  10. num = num - 1
  11. return facto
  12. # print(fact(5)) #// for checking
  13. # Defining power function
  14. def exp(num,po):
  15. ex = 1
  16. while po>0:
  17. ex = ex*num
  18. po = po - 1
  19. return ex
  20. # print(exp(2,8)) #// for checking
  21. # Implementation of Binomial Process
  22. # Probability of K arrivals with
  23. # probability of arrival as pr
  24. # not arrival probability is 1-pr
  25. # P = n!/(n-r)!*r! * p^r * (1-p)^n-r
  26. # r = k
  27. def Binomial(N,k,pr):
  28. BinCoef = (fact(N)/(fact(N-k)*fact(k)))
  29. ProRatio = (exp(pr,k)*exp(1-pr,N-k))
  30. Probability = BinCoef*ProRatio
  31. return Probability
  32. N = 1
  33. n = 1
  34. k = 1
  35. pr = 0.1
  36. prn = 0.9
  37. # Use of Vector to save data and
  38. # further algebric manipulation
  39. x = []
  40. y = []
  41. while n<40:
  42. x.append(n)
  43. y.append(Binomial(n,k,pr))
  44. n = n + 1
  45. pl.plot(x,y)
  46. print('Binomial Process Vector : ', y)

Output:

输出:

  1. Binomial Process Vector : [0.1, 0.18000000000000002, 0.24300000000000005,
  2. 0.2916, 0.32805000000000006, 0.3542940000000001, 0.37200870000000014,
  3. 0.3826375200000001, 0.38742048900000015, 0.3874204890000002,
  4. 0.3835462841100002, 0.37657271530800024, 0.36715839742530026,
  5. 0.3558612159660602, 0.3431518868244152, 0.32942581135143856,
  6. 0.3150134321048131, 0.3001892705939984, 0.2851798070642985,
  7. 0.27017034353459857, 0.25531097464019564, 0.24072177608932738,
  8. 0.22649730750223074, 0.2127105148716602, 0.19941610769218143,
  9. 0.18665347679988184, 0.17444921100912034, 0.16281926360851232,
  10. 0.1517708135779347, 0.14130386091738747, 0.13141259065317037,
  11. 0.1220865358326228, 0.11331156606965304, 0.10507072490095098,
  12. 0.09734493630529284, 0.09011359817975681, 0.08335507831627505,
  13. 0.07704712644369205, 0.07116721416246292]

binomial process output

翻译自: https://www.includehelp.com/python/binomial-process.aspx

使用python学线性代数

发表评论

表情:
评论列表 (有 0 条评论,204人围观)

还没有评论,来说两句吧...

相关阅读