File tree Expand file tree Collapse file tree 1 file changed +18
-13
lines changed Expand file tree Collapse file tree 1 file changed +18
-13
lines changed Original file line number Diff line number Diff line change 1
1
import math
2
2
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
5
6
const = 0.1
6
7
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 :
10
14
return True
11
15
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 :
15
20
return False
16
21
return True
17
22
18
23
19
- def nCr (n ,r ):
24
+ def nCr (n , r ):
20
25
try :
21
- if (n - r < 0 ) :
26
+ if (n - r < 0 ):
22
27
return 1
23
28
f = math .factorial
24
- return f (n ) / f (r ) / f (n - r )
29
+ return f (n ) / f (r ) / f (n - r )
25
30
except :
26
31
print ("value error " + str (n ) + " " + str (r ))
27
32
raise
28
33
29
34
30
35
def factorial (n ):
31
- if n < 0 :
36
+ if n < 0 :
32
37
return 1
33
38
f = math .factorial
34
- return f (n )
39
+ return f (n )
You can’t perform that action at this time.
0 commit comments