MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / compute_L_inverse

Method compute_L_inverse

core/utils/transformation.py:566–584  ·  view source on GitHub ↗
(self, X, Y)

Source from the content-addressed store, hash-verified

564 return warped_grid
565
566 def compute_L_inverse(self, X, Y):
567 N = X.size()[0] # num of points (along dim 0)
568 # construct matrix K
569 Xmat = X.expand(N, N)
570 Ymat = Y.expand(N, N)
571 P_dist_squared = torch.pow(Xmat - Xmat.transpose(0, 1), 2) + torch.pow(Ymat - Ymat.transpose(0, 1), 2)
572 P_dist_squared[P_dist_squared == 0] = 1 # make diagonal 1 to avoid NaN in log computation
573 K = torch.mul(P_dist_squared, torch.log(P_dist_squared))
574 if self.reg_factor != 0:
575 K += torch.eye(K.size(0), K.size(1)) * self.reg_factor
576 # construct matrix L
577 O = torch.FloatTensor(N, 1).fill_(1)
578 Z = torch.FloatTensor(3, 3).fill_(0)
579 P = torch.cat((O, X, Y), 1)
580 L = torch.cat((torch.cat((K, P), 1), torch.cat((P.transpose(0, 1), Z), 1)), 0)
581 Li = torch.inverse(L)
582 if self.use_cuda:
583 Li = Li.cuda()
584 return Li
585
586 def apply_transformation(self, theta, points):
587 if theta.dim() == 2:

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected