Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# Problem 1 - Markov Absorbing Chain
import numpy as np
from numpy.linalg import inv
def GetAverageMatrix(mTable):
bTable = mTable[:4, :4]
iden = np.identity(4)
sub = iden - bTable
res = inv(sub)
return res
def GetGraduationChance(mTable):
testTable = np.matmul(mTable, mTable)
for i in range(1000):
testTable = np.matmul(testTable, mTable)
start = np.array([1, 0, 0, 0, 0, 0])
grad = np.matmul(start, testTable)
return grad[4]
def GenerateStudent(mTable, aTable, bTable):
ogQuit = 0.15
i = 0.01
while i < 0.16:
row = int(i*100)
aTable[row, 0] = i
bTable[row, 0] = i
mTable[0, 5] = i
mTable[0, 0] = 0.1 + ogQuit - i
aTable[row, 1] = GetGraduationChance(mTable)
res = GetAverageMatrix(mTable)
bTable[row, 1] = np.sum(res[0]) + 1
mTable[0, 0] = 0.1
mTable[0, 1] = 0.75 + ogQuit - i
aTable[row, 2] = GetGraduationChance(mTable)
res = GetAverageMatrix(mTable)
bTable[row, 2] = np.sum(res[0]) + 1
half = (ogQuit - i)/2
mTable[0, 0] = 0.1 + half
mTable[0, 1] = 0.75 + half
aTable[row, 3] = GetGraduationChance(mTable)
res = GetAverageMatrix(mTable)
bTable[row, 3] = np.sum(res[0]) + 1
i += 0.01
return
def main():
print()
print("CSE 3504 Project 2 - Problem 1:")
print()
mTable = np.array([[0.1, 0.75, 0, 0, 0, 0.15], \
[0, 0.1, 0.8, 0, 0, 0.1], \
[0, 0, 0.15, 0.75, 0, 0.1], \
[0, 0, 0, 0.1, 0.8, 0.1], \
[0, 0, 0, 0, 1, 0], \
[0, 0, 0, 0, 0, 1]])
print("Problem 1: Part b")
print()
sol = GetAverageMatrix(mTable)
print(sol)
print()
print("With average execution time (years to graduate), we get: ")
print(np.sum(sol[0])+1) # the +1 is for graduation (since example online shows s5 as a 1 because absorb state)
print()
print()
print("Problem 1: Part c") # Probability of graduation - This is definitely wrong?
print()
print("Graduation chance, I think: ") # AYYYYY I think this is it. Although 58% seems low... lets put it to the test!
print(GetGraduationChance(mTable))
print()
# okay so for now forget the P(graduate) cause thats clearly wrong
aTable = np.zeros((16,4))
aTable[0] = [0, 1, 2, 3]
bTable = np.zeros((16,4))
bTable[0] = [0, 1, 2, 3]
GenerateStudent(mTable, aTable, bTable)
print("Quit Value, Stay Fresh, Become Soph, Middleman")
print(aTable)
print(bTable)
if __name__ == '__main__':
main()