Skip to content

Commit e266d9f

Browse files
authored
Add files via upload
1 parent f065ae6 commit e266d9f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Utils.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
import math
22

3-
#max_num_of_iterations = 6
4-
max_num_of_iterations = 15
3+
# Max Iterations
4+
# int_max_iter = 6
5+
int_max_iter = 15
56
const = 0.1
67

7-
def is_converged(new,old,num_of_iterations):
8-
converging_factor = 0.00000001
9-
if num_of_iterations > max_num_of_iterations :
8+
# pnew_trans = trans_en_fil_matrix
9+
# pold_trans = trans_en_fil_matrix_prev
10+
def is_converged(pnew_trans, pold_trans, pint_iter):
11+
# converging factor
12+
float_conv_factor = 0.00000001
13+
if pint_iter > int_max_iter:
1014
return True
1115

12-
for i in range(len(new)):
13-
for j in range(len(new[0])):
14-
if math.fabs(new[i][j]- old[i][j]) > converging_factor:
16+
# checking if the length of the dictionaries is converging to the converging factor
17+
for int_index in range(len(pnew_trans)):
18+
for int_index2 in range(len(pnew_trans[0])):
19+
if math.fabs(pnew_trans[int_index][int_index2] - pold_trans[int_index][int_index2]) > float_conv_factor:
1520
return False
1621
return True
1722

1823

19-
def nCr(n,r):
24+
def nCr(n, r):
2025
try:
21-
if (n-r < 0) :
26+
if (n - r < 0):
2227
return 1
2328
f = math.factorial
24-
return f(n) / f(r) / f(n-r)
29+
return f(n) / f(r) / f(n - r)
2530
except:
2631
print("value error " + str(n) + " " + str(r))
2732
raise
2833

2934

3035
def factorial(n):
31-
if n < 0 :
36+
if n < 0:
3237
return 1
3338
f = math.factorial
34-
return f(n)
39+
return f(n)

0 commit comments

Comments
 (0)