def get_std(self, num_items, vars, expectation):
num_pairs = 0
std_sum = 0.0
# If self distance computed std for top and bottom half
if self.use_self_distance:
for i in xrange(num_items):
var_half_1, var_half_2 = torch.chunk(vars[i], 2, dim=2)
std_sum += np.square(self.as_np(self.distance(var_half_1, var_half_2)) - expectation)
return np.sqrt(std_sum / num_items)
# Otherwise compute std for all pairs of images
for i in xrange(num_items - 1):
for j in xrange(i + 1, num_items):
num_pairs += 1
std_sum += np.square(self.as_np(self.distance(vars[i], vars[j])) - expectation)
return np.sqrt(std_sum / num_pairs)
评论列表
文章目录