-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompare.py
30 lines (30 loc) · 839 Bytes
/
Compare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from MultiLevel import MultiLevel
from GaussSeidel import GaussSeidel
from BirthDeath import BirthDeath
import numpy as np
import math
import time
import sys
# Compare function is used to run GaussSeidel and ML(basic strategy) for the
# same BirthDeath Markov Process.
# n = 100
start = time.time()
n = int(sys.argv[1])
birth = 1
death = 1
Q = BirthDeath(n, birth, death) #generate transition matrix
P = np.transpose(Q)
grid = 4
level = int(math.log(n, 4))
print level
iterations = 0;
pi, iterations = MultiLevel(P, level, iterations, grid)
lamda = 1e-7
piG, iterationsG = GaussSeidel(Q, n, lamda, True)
print "MultiLevel:", pi
print "GaussSeidel:", piG
print "Difference: ", np.linalg.norm(pi-piG)
end = time.time()
print "Number of Iterations: ", iterations
print "Number of States: ", n
print "Time Elapsed: ", end-start, " seconds"