Advertisement
575

Uniform distribution

575
Nov 6th, 2022 (edited)
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import time
  4.  
  5.  
  6. # Построить точки (для построения равномерного распределения)
  7. def DrawDots(x):
  8.     x_draw, y_draw = np.array([]), np.array([])
  9.  
  10.     for i in range(0, int(len(x)), 2):
  11.         if i+1 >= len(x):
  12.             break
  13.         x_draw = np.append(x_draw, x[i])
  14.         y_draw = np.append(y_draw, x[i + 1])
  15.    
  16.     plt.plot(x_draw, y_draw, 'o')
  17.     plt.grid(True)
  18.     plt.show()
  19.  
  20. #Построить гистограмму(для построения нормального,экспоненциального и распределения по Коши)
  21. def DrawHistogram(beg, end, down, up, X):
  22.     h = 0.1
  23.     x = np.arange(beg, end+h, h)
  24.     Y = np.array([])
  25.  
  26.     for i in range(1, len(x)):
  27.         temp = 0
  28.         for j in range(len(X)):
  29.             if X[j] > x[i - 1] and X[j] <= x[i]:
  30.                 temp += 1
  31.         Y = np.append(Y, temp/len(X))
  32.    
  33.     x = np.delete(x, 0)
  34.  
  35.     plt.axis([beg, end, down, up])
  36.     plt.grid(True)
  37.     plt.bar(x, Y)
  38.     plt.show()
  39.  
  40. # R(0, 1), N – количество элементов
  41. def RStandart(N):
  42.     # const
  43.     c1 = 4096
  44.     c2 = 150889
  45.     c3 = 714025
  46.  
  47.     nk = np.array([])
  48.     xk = np.array([])
  49.    
  50.     # init
  51.     n0 = np.mod(time.time(), c1)
  52.     nk = np.append(nk, n0)
  53.     xk = np.append(xk, nk[0]/c3)
  54.    
  55.     for i in range(1,N):
  56.         nk = np.append(nk, np.mod(c1*nk[i-1] + c2, c3))
  57.         xk = np.append(xk, nk[i]/c3)
  58.    
  59.     return xk
  60.  
  61. # Строим равномерное распределение
  62. R = RStandart(5000)
  63. DrawDots(R)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement