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

Edgelist #5

Open
neenerrh opened this issue Aug 31, 2020 · 4 comments
Open

Edgelist #5

neenerrh opened this issue Aug 31, 2020 · 4 comments

Comments

@neenerrh
Copy link

I tried to run the ABRW method by creating the graph using edgelist. But I encountered an error when reading the attribute file self.g_u.read_node_attr(attribute_file) File "\model\libnrl\graph.py", line 83, in read_node_attr self.G.nodes[vec[0]]['attr'] = np.array([float(x) for x in vec[1:]]) File "C:\Users\Administrator\Anaconda3\lib\site-packages\networkx\classes\reportviews.py", line 178, in __getitem__ return self._nodes[n] KeyError: '98'

But the code works fine when I used adjacency list to create the graph. Do you have any suggestion

@houchengbin
Copy link
Owner

There might be two possible solutions:

  1. You could convert edge list to adjacency list using networkx API (I recommend this one).
  2. If you still want to load your edge list, did you specify the parameter "--graph-format edgelist" ? Please see
    parser.add_argument('--graph-format', default='adjlist', choices=['adjlist', 'edgelist'],
    , in which the default parameter is "adjlist".

If the solution 2 is still not working, could you please paste your edge list here? e.g., the first 10 lines of your edge list.

@neenerrh
Copy link
Author

neenerrh commented Sep 8, 2020

I did changed the graph-format to edgelist. Below is the edgelist
1 932
1 931
1 911
1 97
1 942
1 912
1 904
1 96
1 943
1 924

@houchengbin
Copy link
Owner

houchengbin commented Sep 10, 2020

Please see my attempt below:

  1. Put the above edgelist in a file under 'data' folder, namely 'graph.txt';
  2. Generate a file for attributes under 'data' folder, namely 'attr.txt';
1 0.1 0.2 0.3
932 0.1 0.2 0.3
931 0.1 0.2 0.3
911 0.1 0.2 0.3
97 0.1 0.2 0.3
942 0.1 0.2 0.3
912 0.1 0.2 0.3
904 0.1 0.2 0.3
96 0.1 0.2 0.3
943 0.1 0.2 0.3
924 0.1 0.2 0.3

Note that, if you run an Attributed Network Embedding (ANE) method, e.g., '-method abrw', you should also provide the corresponding attributes. Otherwise, you may get the error message as you provided above.

  1. Having the above two files, try the following command:
cd OpenANE
python src/main.py --method abrw --ABRW-topk 5 --graph-format edgelist --graph-file data/graph.txt --attribute-file data/attr.txt --task lp --emb-file emb/test_abrw_emb --save-emb

Note that, you may need to set '--ABRW-topk 5', because the graph is too small. The number specified here should be larger than the number of nodes in the graph.

@neenerrh
Copy link
Author

neenerrh commented Sep 11, 2020

Thank you for the detailed code and explanation. I tried using it with the provided edge list and attribute list. I believe what caused the error is that I tried to add attributes to nodes that are not in my edgelist

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