Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Oct 17 17:08:42 2017
- @author: Karolis
- """
- import numpy as np
- import matplotlib.pyplot as plt
- currentState = int(0) #dabartine busena
- state1 = 0 #kiek kartu grandine buvo 1-ame mazge
- state2 = 0 #kiek kartu grandine buvo 2-ame mazge
- state3 = 0 #kiek kartu grandine buvo 3-ame mazge
- #funkcija pradiniam grandines mazgui nustatyti
- def initState():
- x = np.random.random_sample()
- if x <= 1/3:
- currentState = 1
- global state1
- state1 += 1
- else:
- if x <= 2/3:
- currentState = 2
- global state2
- state2 += 1
- else:
- currentState = 3
- global state3
- state3 += 1
- return currentState
- #funkcija nustatyti sekanciam grandines mazgui
- def RNG(currentState):
- if currentState == 1 or currentState == 3:
- currentState = 2
- global state2
- state2 += 1
- else:
- if (np.random.random_sample() <= 0.5):
- currentState = 1
- global state1
- state1 += 1
- else:
- currentState = 3
- global state3
- state3 += 1
- return currentState
- stateHistory = [] #masyvas, laikantis pirmu 50 busenu istorija
- t = np.linspace(0, 49, 50)
- currentState = initState() #pradines busenos inicializacija
- for i in range(50): #pirmi 50 busenos pokyciu
- stateHistory.append(currentState)
- currentState = RNG(currentState)
- for i in range(9949):
- currentState = RNG(currentState)
- plt.plot(t, stateHistory, c='r')
- print('Pirmos 50 busenu:')
- print(stateHistory)
- print('Pirmo, antro ir trecio mazgo apsilankymu skaiciai:')
- print(state1, state2, state3)
- pst1 = float(state1/10000)
- pst2 = float(state2/10000)
- pst3 = float(state3/10000)
- print('Tikimybes:')
- print(pst1, pst2, pst3)
- print('Tikimybes is analiziniu skaiciavimu:')
- print('0.25 0.5 0.25')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement