clovaai / rebias

Official Pytorch implementation of ReBias (Learning De-biased Representations with Biased Representations), ICML 2020
MIT License
170 stars 29 forks source link

Code doubts #11

Closed yaolu-zjut closed 2 years ago

yaolu-zjut commented 2 years ago

Hello, I wonder that whether the code 'KH = K - K.mean(0, keepdim=True)' is right? I think it should be 'KH = K - K.mean(1, keepdim=True)'

yaolu-zjut commented 2 years ago

Hello, I wonder that whether the code 'KH = K - K.mean(0, keepdim=True)' is right? I think it should be 'KH = K - K.mean(1, keepdim=True)'

Here is my code:

x =torch.Tensor([[1,2,1,2],[2,3,1,2],[2,4,1,1],[3,4,1,4]]) unit = torch.ones([4, 4]) I = torch.eye(4) H = I - unit / 4 truth = torch.mm(x, H) you = x - x.mean(0, keepdim=True) my = x - x.mean(1, keepdim=True) print(you-truth) print(my-truth)

The running result:

tensor([[-0.5000, -1.7500, 0.5000, -0.7500], [ 0.0000, -1.2500, 1.0000, -0.2500], [ 0.0000, -1.2500, 1.0000, -0.2500], [ 1.0000, -0.2500, 2.0000, 0.7500]]) tensor([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]])

SanghyukChun commented 2 years ago

@yaolu-zjut Hi, thanks for your interest in my paper :) KH is a typo. It should be HK.

However, my code is correct in terms of the HSIC implementation. Note that trace(KHLH) = trace(HKHL) because trace is invariant to a cyclic permutation. https://math.stackexchange.com/questions/1474812/how-to-prove-the-cyclic-property-of-the-trace

Also, I'd like to suggest using the unbiased estimator instead of the biased estimator. The default estimator is the unbiased one (algorithm='unbiased') https://github.com/clovaai/rebias/blob/master/criterions/hsic.py#L42

SanghyukChun commented 2 years ago

Closing the issue, assuming the answer resolves the problem. Please re-open the issue as necessary.