Shen-Lab / GraphCL

[NeurIPS 2020] "Graph Contrastive Learning with Augmentations" by Yuning You, Tianlong Chen, Yongduo Sui, Ting Chen, Zhangyang Wang, Yang Shen
MIT License
547 stars 103 forks source link

A bug in aug_random_edge #12

Closed skydetailme closed 3 years ago

skydetailme commented 3 years ago

Hi, Shen. Thanks for your efforts in this program. I noticed there might have a logical bug in the aug_random_edge function.

“for i in index_list: single_index_list.append(i) index_list.remove((i[1], i[0]))”

Removing items in a list while iterating that list may cause problems, as the list changed but the current index is not changed.

This blog illustrated well. https://thispointer.com/python-remove-elements-from-a-list-while-iterating/

Thanks for your help.

yyou1996 commented 3 years ago

Hi @skydetailme,

Thanks for your interest in our work. Would you mind pointing out which file you are referring to? I think in my implementation I did not use "remove()" function but directly use indexing to modify them, e.g. https://github.com/Shen-Lab/GraphCL/blob/88f2a1590a67bbbe1ae848156e74adc08f888271/semisupervised_TU/pre-training/tu_dataset.py#L224

skydetailme commented 3 years ago

Hi, thanks for the reply. Here is the link. https://github.com/Shen-Lab/GraphCL/blob/master/unsupervised_Cora_Citeseer/aug.py

yyou1996 commented 3 years ago

@yongduosui, would you mind giving some comments on this? Thanks!

yongduosui commented 3 years ago

@skydetailme The aim of this code is to convert to convert bidirectional edges index to unidirectional index. I just debug my code and did't find any bug. It remove the other edge index pair successfully. You can print the list and check. Thanks.

skydetailme commented 3 years ago

@skydetailme The aim of this code is to convert to convert bidirectional edges index to unidirectional index. I just debug my code and did't find any bug. It remove the other edge index pair successfully. You can print the list and check. Thanks.

Would you mind take some minutes to read the link I posted, it explains well. And you will find that after this iteration, index_list is not empty, those are the items accidentally jumped because of index error. Those items are not solved. The result may right on some occasions but this code may not logically right.

skydetailme commented 3 years ago

@skydetailme The aim of this code is to convert to convert bidirectional edges index to unidirectional index. I just debug my code and did't find any bug. It remove the other edge index pair successfully. You can print the list and check. Thanks.

Also, thanks for your help.

skydetailme commented 3 years ago

@skydetailme The aim of this code is to convert to convert bidirectional edges index to unidirectional index. I just debug my code and did't find any bug. It remove the other edge index pair successfully. You can print the list and check. Thanks.

It seems that if the adj matrix is self-loop, this code may cause a wrong result, and the index_list is not empty. If it's not a self-loop adj matrix, the result is right.

yyou1996 commented 3 years ago

@skydetailme Thank you for your carefulness, and I see your point. The citation net datasets happen to be without self-loop. I will read the post and give some comments after finishing my work at hand.

skydetailme commented 3 years ago

@skydetailme Thank you for your carefulness, and I see your point. The citation net datasets happen to be without self-loop. I will read the post and give some comments after finishing my work at hand.

Thanks for your reply and contribution. This project helps a lot.

yyou1996 commented 3 years ago

Hi @skydetailme,

Sorry for the late reply that I just survive a DDL. I make certain modifications according to the blog u share https://thispointer.com/python-remove-elements-from-a-list-while-iterating/. Thanks again for your carefulness.