Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about group loss #1

Open
hhaAndroid opened this issue Aug 24, 2020 · 1 comment
Open

about group loss #1

hhaAndroid opened this issue Aug 24, 2020 · 1 comment

Comments

@hhaAndroid
Copy link

hhaAndroid commented Aug 24, 2020

Hello, thank you for your work.
After reading the paper and code, I found that Loss in the semantic grouping part is very difficult to understand, and the writing in the paper is relatively simple. Can you explain briefly?

LocalMaxGlobalMin

`
def forward(self, x):
x = x.pow(2)
intra_x = []
inter_x = []
for i in range(self.nparts):
if i == 0:
intra_x.append((1 - x[:, :self.seps[i], :self.seps[i]]).mean())
else:
intra_x.append((1 - x[:, self.seps[i - 1]:self.seps[i], self.seps[i - 1]:self.seps[i]]).mean())
inter_x.append(x[:, self.seps[i - 1]:self.seps[i], :self.seps[i - 1]].mean())

    loss = self.rho * 0.5 * (sum(intra_x) / self.nparts + sum(inter_x) / (self.nparts * (self.nparts - 1) / 2))

    return loss

`

@cswluo
Copy link
Owner

cswluo commented Aug 28, 2020

Hello, thank you for your work.
After reading the paper and code, I found that Loss in the semantic grouping part is very difficult to understand, and the writing in the paper is relatively simple. Can you explain briefly?

LocalMaxGlobalMin

`
def forward(self, x):
x = x.pow(2)
intra_x = []
inter_x = []
for i in range(self.nparts):
if i == 0:
intra_x.append((1 - x[:, :self.seps[i], :self.seps[i]]).mean())
else:
intra_x.append((1 - x[:, self.seps[i - 1]:self.seps[i], self.seps[i - 1]:self.seps[i]]).mean())
inter_x.append(x[:, self.seps[i - 1]:self.seps[i], :self.seps[i - 1]].mean())

    loss = self.rho * 0.5 * (sum(intra_x) / self.nparts + sum(inter_x) / (self.nparts * (self.nparts - 1) / 2))

    return loss

`

The input variable, x, is a 3d tensor with the dimensionality nsamples * nfeatures * nfeatures. For each slice (nfeature * nfeature), it should be considered as a block matrix (also it is a symmetric matrix). The blocks on the main diagonal are correlations of feature channels from the same group while the off-diagonal blocks are those from different groups.

self.seps stores the indices of boundaries between groups. The equation provides the average correlation by dividing the total correlation of each type by the number of corresponding blocks.

hope it's helpful to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants