Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Oct 17 17:08:42 2017
  4.  
  5. @author: Karolis
  6. """
  7.  
  8. import numpy as np
  9. import matplotlib.pyplot as plt
  10.  
  11. currentState = int(0) #dabartine busena
  12. state1 = 0 #kiek kartu grandine buvo 1-ame mazge
  13. state2 = 0 #kiek kartu grandine buvo 2-ame mazge
  14. state3 = 0 #kiek kartu grandine buvo 3-ame mazge
  15.  
  16. #funkcija pradiniam grandines mazgui nustatyti
  17. def initState():
  18. x = np.random.random_sample()
  19. if x <= 1/3:
  20. currentState = 1
  21. global state1
  22. state1 += 1
  23. else:
  24. if x <= 2/3:
  25. currentState = 2
  26. global state2
  27. state2 += 1
  28. else:
  29. currentState = 3
  30. global state3
  31. state3 += 1
  32. return currentState
  33.  
  34. #funkcija nustatyti sekanciam grandines mazgui
  35. def RNG(currentState):
  36. if currentState == 1 or currentState == 3:
  37. currentState = 2
  38. global state2
  39. state2 += 1
  40. else:
  41. if (np.random.random_sample() <= 0.5):
  42. currentState = 1
  43. global state1
  44. state1 += 1
  45. else:
  46. currentState = 3
  47. global state3
  48. state3 += 1
  49. return currentState
  50.  
  51.  
  52. stateHistory = [] #masyvas, laikantis pirmu 50 busenu istorija
  53. t = np.linspace(0, 49, 50)
  54.  
  55. currentState = initState() #pradines busenos inicializacija
  56.  
  57. for i in range(50): #pirmi 50 busenos pokyciu
  58. stateHistory.append(currentState)
  59. currentState = RNG(currentState)
  60.  
  61. for i in range(9949):
  62. currentState = RNG(currentState)
  63.  
  64. plt.plot(t, stateHistory, c='r')
  65. print('Pirmos 50 busenu:')
  66. print(stateHistory)
  67. print('Pirmo, antro ir trecio mazgo apsilankymu skaiciai:')
  68. print(state1, state2, state3)
  69. pst1 = float(state1/10000)
  70. pst2 = float(state2/10000)
  71. pst3 = float(state3/10000)
  72. print('Tikimybes:')
  73. print(pst1, pst2, pst3)
  74. print('Tikimybes is analiziniu skaiciavimu:')
  75. print('0.25 0.5 0.25')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement