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

Potential errors in fuzzy c-means #5

Open
wangfuli opened this issue Oct 18, 2023 · 5 comments
Open

Potential errors in fuzzy c-means #5

wangfuli opened this issue Oct 18, 2023 · 5 comments

Comments

@wangfuli
Copy link

wangfuli commented Oct 18, 2023

Hello authors of ViHGNN,

When I tried to run the fuzzy c-means to form hypergraphs, I found the hyperedge matrix is suspiciously dense, so I went back to check the actual implementation and found that the resulting membership tensor (batch_size, num_points, n_clusters) might not be computed appropriately, because the entries of membership[b, p, :] are not fractions and 'torch.sum(membership, dim=2)' does not yield 1's.

I have tried to replace the following code

inv_dist = 1.0 / (dist_to_centers + 1e-10)
power = 2 / (m - 1)
membership = (inv_dist / inv_dist.sum(dim=-1, keepdim=True).pow(power)).pow(power) # (batch_size, num_points, n_clusters)

with my implementation:

y = dist_to_centers.unsqueeze(-1).expand(-1, -1,-1, dist_to_centers.size(2)) # (batch_size, num_points, n_clusters, n_clusters)
z = y.transpose(-1, -2) # (batch_size, num_points, n_clusters, n_clusters)
power = 2 / (m - 1)
membership = 1.0 / torch.sum((y / z).pow(power), dim=-1) # (batch_size, num_points, n_clusters)

and it fixed the problem.

It might be me misunderstanding the code, so please let me know what you think. Thank you so much.

@jerryzhu1229
Copy link

@wangfuli Hello, I have a question for you.
In the process of debugging this code, the fuzzy_c_means function after a few iterations, the elements inside membership matrix all become the same. This doesn't seem to make sense. Do you meet the same situation?

@wangfuli
Copy link
Author

@wangfuli Hello, I have a question for you. In the process of debugging this code, the fuzzy_c_means function after a few iterations, the elements inside membership matrix all become the same. This doesn't seem to make sense. Do you meet the same situation?

Hello, in your problem, if the elements inside the membership matrix all become the same, the weights and centers will not change at all, and this would lead to the convergence break before i hits max_iter -1. This situation didn't happen to me, I was able to run the updating process until the max_iter.

However, some images, especially images with many common pixel values could lead to the problem you encountered. For one of my images (with most pixel values are 0), I found 16145/ 16384 rows are the same in its corresponding membership matrix(torch.Size([16384, 9])), and this makes sense because these 0-value pixels (nodes) should all have the same membership allocation.

@Batman0096
Copy link

Batman0096 commented Oct 24, 2023

@wangfuli Hello, have you debugged with the HypergraphConv2d function, I have met tensor mismatch issues when "Adding the hyperedge center features to the aggregated hyperedge features" with following code

aggregated_hyperedge_features += centers

Do you meet this issue? How to solve it?

Actually, the whole function seems weried, many issues.

@xuxuxuzy
Copy link

Hello authors of ViHGNN,

When I tried to run the fuzzy c-means to form hypergraphs, I found the hyperedge matrix is suspiciously dense, so I went back to check the actual implementation and found that the resulting membership tensor (batch_size, num_points, n_clusters) might not be computed appropriately, because the entries of membership[b, p, :] are not fractions and 'torch.sum(membership, dim=2)' does not yield 1's.

I have tried to replace the following code

inv_dist = 1.0 / (dist_to_centers + 1e-10) power = 2 / (m - 1) membership = (inv_dist / inv_dist.sum(dim=-1, keepdim=True).pow(power)).pow(power) # (batch_size, num_points, n_clusters)

with my implementation:

y = dist_to_centers.unsqueeze(-1).expand(-1, -1,-1, dist_to_centers.size(2)) # (batch_size, num_points, n_clusters, n_clusters) z = y.transpose(-1, -2) # (batch_size, num_points, n_clusters, n_clusters) power = 2 / (m - 1) membership = 1.0 / torch.sum((y / z).pow(power), dim=-1) # (batch_size, num_points, n_clusters)

and it fixed the problem.

It might be me misunderstanding the code, so please let me know what you think. Thank you so much.

hello,Have you successfully implemented this paper, I found that there are a lot of errors in the construct_hyperedges function

@lcs0215
Copy link

lcs0215 commented Nov 16, 2023

@wangfuli Hello, I have a question for you.
In the process of debugging this code, the fuzzy_c_means function after a few iterations, the elements inside membership matrix all become the same. This doesn't seem to make sense. Do you meet the same situation?

@jerryzhu1229 hi, I meet the same issue, have you fixed it?

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

5 participants