daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as mtl
  3. import scipy.optimize as ort
  4.  
  5. f=open('input.txt')
  6. array=[]
  7. arrayCor=[]
  8. arrayNormCor=[]
  9. tNormCor0=[]
  10. tNormCor1=[]
  11. tNormCor2=[]
  12. tNormCor3=[]
  13. num=[]
  14. average =0
  15. eps0=0
  16. eps1=0
  17. eps2=0
  18. eps3=0
  19. dis=0
  20. rmin=0
  21. i=0
  22. while i!=5000:
  23.     line = f.readline()
  24.     array.append(float(line))
  25.     i=i+1
  26. #print(array)
  27. def averageF():
  28.     sum=0
  29.     for i in range(5000):
  30.         sum=sum+array[i]
  31.     return sum/5000
  32.  
  33. average=averageF()
  34.  
  35. def disF():
  36.     sum=0
  37.     for i in range(5000):
  38.         sum=sum+(array[i]-average)**2
  39.     return sum/4999
  40.  
  41. dis=disF()
  42.  
  43. def corF():
  44.     for i in range(4999):
  45.         sum=0
  46.         for j in range(5000-i):
  47.             sum= sum + (array[j]-average)*(array[j+i]-average)
  48.         arrayCor.append(sum/(4999-i))
  49.     return arrayCor
  50.  
  51. arrayCor = corF()
  52.  
  53.  
  54.  
  55.  
  56.  
  57. def normCorF():
  58.     for i in range(4999):
  59.         arrayNormCor.append(arrayCor[i]/dis)
  60.     return arrayNormCor
  61.  
  62. arrayNormCor = normCorF()
  63.  
  64. def rminF():
  65.     i = 20
  66.     while(i>=0) & (abs(arrayNormCor[i])< 1/np.e):
  67.         i=i-1
  68.     return i
  69.  
  70. rmin = rminF()
  71.  
  72.  
  73.  
  74. for i in range(100):
  75.     num.append(i)
  76. x=[0, 101]
  77. y=[average,average]
  78. y1 = [average + np.math.sqrt(dis),average + np.math.sqrt(dis)]
  79. y2 = [average - np.math.sqrt(dis),average - np.math.sqrt(dis)]
  80. y3 = [1/np.e,1/np.e]
  81. y4 = [-1/np.e,-1/np.e]
  82. x3 = [0,20]
  83.  
  84.  
  85. mtl.figure(1)
  86. mtl.grid()
  87. leg1,leg2,leg3,leg4= mtl.plot(num,array[0:100],'b',x,y,'r',x,y1,'g',x,y2)
  88. mtl.legend((leg1,leg2,leg3,leg4),("function","average","MX+S","MX-S"))
  89.  
  90. mtl.figure(2)
  91. mtl.grid()
  92. leg1,leg2,leg3,leg4=mtl.plot(num[0:20],arrayNormCor[0:20],'b',[rmin,rmin],[-1,1],'r',x3,y3,'g',x3,y4)
  93. mtl.legend((leg1,leg2,leg3,leg4),("NCor","interval","e^(-1)", "-e^(-1)"))
  94.  
  95. mtl.show()
  96.  
  97.  
  98. a0 = np.math.sqrt(arrayCor[0])
  99. print('коэффициент Ар(0)', a0)
  100.  
  101. A=[[arrayCor[1], 1],[arrayCor[0],0]]
  102. B=[[arrayCor[0]],[arrayCor[1]]]
  103. ar1=np.linalg.solve(A,B)
  104. print("Коэффициенты АР(1) ",ar1[0][0],np.math.sqrt(ar1[1][0]))
  105.  
  106. A=[[arrayCor[1],arrayCor[2], 1],[arrayCor[0],arrayCor[1],0],[arrayCor[1],arrayCor[0],0]]
  107. B=[[arrayCor[0]],[arrayCor[1]],[arrayCor[2]]]
  108. ar2=np.linalg.solve(A,B)
  109. print("Коэффициенты АР(2) ",ar2[0][0],ar2[1][0],np.math.sqrt(ar2[2][0]))
  110.  
  111. A=[[arrayCor[1],arrayCor[2],arrayCor[3], 1],[arrayCor[0],arrayCor[1],arrayCor[2],0],[arrayCor[1],arrayCor[0],arrayCor[1],0],[arrayCor[2],arrayCor[1],arrayCor[0],0]]
  112. B=[[arrayCor[0]],[arrayCor[1]],[arrayCor[2]],[arrayCor[3]]]
  113. ar3=np.linalg.solve(A,B)
  114. print("Коэффициенты АР(3) ",ar3[0][0],ar3[1][0],ar3[2][0],np.math.sqrt(ar3[3][0]))
  115.  
  116. a0ss = np.math.sqrt(arrayCor[0])
  117. print('коэффициент CC(0)', a0ss)
  118. def recAr0(i):
  119.     if(i==0):
  120.         return 1
  121.     else:
  122.         return 0*recAr0(i-1)
  123.  
  124. def recAr1(i):
  125.     if (i == 0):
  126.         return arrayNormCor[0]
  127.     if( i==1):
  128.         return arrayNormCor[1]
  129.     else:
  130.         return ar1[0][0] * recAr1(i - 1)
  131.  
  132. def recAr2(i):
  133.     if (i == 0):
  134.         return arrayNormCor[0]
  135.     if( i==1):
  136.         return arrayNormCor[1]
  137.     if(i==2):
  138.         return arrayNormCor[2]
  139.     else:
  140.         return ar2[0][0] * recAr2(i - 1)+ar2[1][0] *recAr2(i-2)
  141. def recAr3(i):
  142.     if (i == 0):
  143.         return arrayNormCor[0]
  144.     if( i==1):
  145.         return arrayNormCor[1]
  146.     if(i==2):
  147.         return arrayNormCor[2]
  148.     if (i == 2):
  149.         return arrayNormCor[3]
  150.     else:
  151.         return ar3[0][0] * recAr3(i - 1)+ar3[1][0] *recAr3(i-2)+ar3[2][0]*recAr3(i-3)
  152.  
  153. for i in range(11):
  154.     tNormCor3.append(recAr3(i))
  155.     tNormCor2.append(recAr2(i))
  156.     tNormCor1.append(recAr1(i))
  157.     tNormCor0.append(recAr0(i))
  158.  
  159.  
  160.  
  161. for i in range(11):
  162.     eps0= eps0+(tNormCor0[i]-arrayNormCor[i])**2
  163.     eps1 = eps1 + (tNormCor1[i] - arrayNormCor[i]) ** 2
  164.     eps2 = eps2 + (tNormCor2[i] - arrayNormCor[i]) ** 2
  165.     eps3 = eps3 + (tNormCor3[i] - arrayNormCor[i]) ** 2
  166.  
  167. print(tNormCor0)
  168. print ('eps0',eps0)
  169. print ('eps1',eps1)
  170. print ('eps2',eps2)
  171. print ('eps3',eps3)
  172. aSS1 = []
  173. aSS2 = []
  174. aSS3 = []
  175. emptyArray =[]
  176. def SS1():
  177.  
  178.     a0= (np.math.sqrt(arrayCor[0]+2*arrayCor[1])+ np.math.sqrt(arrayCor[0]-2*arrayCor[1]))/2
  179.     a1= (np.math.sqrt(arrayCor[0]+2*arrayCor[1])- np.math.sqrt(arrayCor[0]-2*arrayCor[1]))/2
  180.     aSS1.append(a0)
  181.     aSS1.append(a1)
  182.     return aSS1
  183. def SS2():
  184.     a0=np.math.sqrt(arrayCor[0])
  185.     a1=0
  186.     a2=0
  187.     i=0
  188.     while (i !=200):
  189.         a2 = arrayCor[2]/a0
  190.         a1= (arrayCor[1]-a1*a2)/a0
  191.         i=i+1
  192.         if(arrayCor[0]<(a1**2+a2**2)):
  193.             return emptyArray
  194.         else:
  195.             a0=np.math.sqrt(arrayCor[0]-a1**2-a2**2)
  196.     aSS2.append(a0)
  197.     aSS2.append(a1)
  198.     aSS2.append(a2)
  199.     return aSS2
  200. def SS3():
  201.     a0=np.math.sqrt(arrayCor[0])
  202.     a1=0
  203.     a2=0
  204.     a3=0
  205.     emptyArray =[]
  206.     i=0
  207.     while (i !=200):
  208.         a3 = arrayCor[3]/a0
  209.         a2= (arrayCor[2]-a1*a3)/a0
  210.         a1=(arrayCor[1]-a1*a2-a2*a3)/a0
  211.         i=i+1
  212.         if(arrayCor[0]<(a1**2+a2**2+a3**2)):
  213.             return emptyArray
  214.         else:
  215.             a0=np.math.sqrt(arrayCor[0]-a1**2-a2**2-a3**2)
  216.     aSS3.append(a0)
  217.     aSS3.append(a1)
  218.     aSS3.append(a2)
  219.     aSS3.append(a3)
  220.     return aSS3
  221.  
  222. aSS1=SS1()
  223. aSS2=SS2()
  224. aSS3=SS3()
  225.  
  226.  
  227.  
  228. def recSS1(i):
  229.     if (i == 0):
  230.         return arrayNormCor[0]
  231.     if( i==1):
  232.         return arrayNormCor[1]
  233.     else:
  234.         return aSS1[0] * recSS1(i - 1)
  235.  
  236. tNormSS1=[]
  237. for i in range(11):
  238.     tNormSS1.append(recSS1(i))
  239. print('hhhhhh',tNormSS1)
  240.  
  241.  
  242.  
  243. print(aSS1)
  244. print(aSS2)
  245. print(aSS3)
  246.  
  247. print('Среднее', average)
  248. print('Дисперсия', dis)
  249. print('Среднеквадротичное отклонение', np.math.sqrt(dis))
  250. print('Выборочная корреляционная функция',arrayCor)
  251. print('Нормированная корреляционная функция',arrayNormCor)
  252. print('Интервал корреляционной функции',rmin)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'SPRING SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top