@@ -33,19 +33,15 @@ def __find_HE(self, ODhat, eigvecs, alpha):
3333 That = torch .matmul (ODhat , eigvecs )
3434 phi = torch .atan2 (That [:, 1 ], That [:, 0 ])
3535
36- minPhi = torch . tensor ( percentile (phi , alpha ) )
37- maxPhi = torch . tensor ( percentile (phi , 100 - alpha ) )
36+ minPhi = percentile (phi , alpha )
37+ maxPhi = percentile (phi , 100 - alpha )
3838
3939 vMin = torch .matmul (eigvecs , torch .stack ((torch .cos (minPhi ), torch .sin (minPhi ))).T ).unsqueeze (1 )
4040 vMax = torch .matmul (eigvecs , torch .stack ((torch .cos (maxPhi ), torch .sin (maxPhi ))).T ).unsqueeze (1 )
4141
4242 # a heuristic to make the vector corresponding to hematoxylin first and the
4343 # one corresponding to eosin second
44- if vMin [0 ] > vMax [0 ]:
45- HE = torch .cat ((vMin , vMax ), dim = 1 )
46-
47- else :
48- HE = torch .cat ((vMax , vMin ), dim = 1 )
44+ HE = torch .where (vMin [0 ] > vMax [0 ], torch .cat ((vMin , vMax ), dim = 1 ), torch .cat ((vMax , vMin ), dim = 1 ))
4945
5046 return HE
5147
@@ -66,7 +62,7 @@ def __compute_matrices(self, I, Io, alpha, beta):
6662 HE = self .__find_HE (ODhat , eigvecs , alpha )
6763
6864 C = self .__find_concentration (OD , HE )
69- maxC = torch .tensor ([percentile (C [0 , :], 99 ), percentile (C [1 , :], 99 )])
65+ maxC = torch .stack ([percentile (C [0 , :], 99 ), percentile (C [1 , :], 99 )])
7066
7167 return HE , C , maxC
7268
0 commit comments