Giter VIP home page Giter VIP logo

m-nmf's Introduction

M-NMF

codebeat badge repo sizebenedekrozemberczki

Abstract

Network embedding, aiming to learn the low-dimensional representations of nodes in networks, is of paramount importance in many real applications. One basic requirement of network embedding is to preserve the structure and inherent properties of the networks. While previous network embedding methods primarily preserve the microscopic structure, such as the first- and second-order proximities of nodes, the mesoscopic community structure, which is one of the most prominent feature of networks, is largely ignored. In this paper, we propose a novel Modularized Nonnegative Matrix Factorization (M-NMF) model to incorporate the community structure into network embedding. We exploit the consensus relationship between the representations of nodes and community structure, and then jointly optimize NMF based representation learning model and modularity based community detection model in a unified framework, which enables the learned representations of nodes to preserve both of the microscopic and community structures. We also provide efficient updating rules to infer the parameters of our model, together with the correctness and convergence guarantees. Extensive experimental results on a variety of real-world networks show the superior performance of the proposed method over the state-of-the-arts.

The model is now also available in the package Karate Club.

This repository provides a TensorFlow implementation for M-NMF as it is described in:

Community Preserving Network Embedding. Xiao Wang, Peng Cui, Jing Wang, Jain Pei, WenWu Zhu, Shiqiang Yang. Proceedings of the Thirsty-First AAAI conference on Artificial Intelligence (AAAI-17).

A reference MatLab implementation is available [here].

Requirements

The codebase is implemented in Python 3.5.2. Package versions used for development are just below.

networkx          2.4
tqdm              4.19.5
numpy             1.13.3
pandas            0.20.3
tensorflow-gpu    1.12.0
jsonschema        2.6.0
texttable         1.2.1
python-louvain    0.11

Datasets

The code takes an input graph in a csv file. Every row indicates an edge between two nodes separated by a comma. The first row is a header. Nodes should be indexed starting with 0. A sample graph for the `Facebook Politicians` dataset is included in the `data/` directory.

Logging

The models are defined in a way that parameter settings and cluster quality is logged in every single epoch. Specifically we log the followings:

1. Hyperparameter settings.     We save each hyperparameter used in the experiment.
2. Cluster quality.             Measured by modularity. We calculate it in every epoch.
3. Runtime.                     We measure the time needed for optimization -- measured by seconds.

Options

Learning of the embedding is handled by the src/main.py script which provides the following command line arguments.

Input and output options

  --input                STR         Input graph path.                                 Default is `data/food_edges.csv`.
  --embedding-output     STR         Embeddings path.                                  Default is `output/embeddings/food_embedding.csv`.
  --cluster-mean-output  STR         Cluster centers path.                             Default is `output/cluster_means/food_means.csv'`.
  --log-output           STR         Log path.                                         Default is `output/logs/food.log`.
  --assignment-output    STR         Node-cluster assignment dictionary path.          Default is `output/assignments/food.json`.
  --dump-matrices        BOOL        Whether the trained model should be saved.        Default is `True`.

Model options

  --dimensions        INT         Number of dimensions.                             Default is 16.
  --clusters          INT         Number of clusters.                               Default is 20.
  --lambd             FLOAT       KKT penalty.			                                Default is 0.2.
  --alpha             FLOAT       Clustering penalty.                               Default is 0.05.
  --beta              FLOAT       Modularity regularization penalty.                Default is 0.05.
  --eta               FLOAT       Similarity mixing parameter.                      Default is 5.0.
  --lower-control     FLOAT       Floating point overflow control.                  Default is 10**-15.
  --iteration-number  INT         Number of power iterations.                       Default is 200.
  --early-stopping    INT         Early stopping round number based on modularity.  Default is 3.

Examples

The following commands learn a graph embedding, cluster centers and writes them to disk. The node representations are ordered by the ID.

Creating an MNMF embedding of the default dataset with the default hyperparameter settings. Saving the embedding, cluster centres and the log file at the default path.

$ python src/main.py

Turning off the model saving.

$ python src/main.py --dump-matrices False

Creating an embedding of an other dataset the Facebook Companies. Saving the output and the log in a custom place.

$ python src/main.py --input data/company_edges.csv  --embedding-output output/embeddings/company_embedding.csv --cluster-mean-output output/cluster_means/company_means.csv

Creating a clustered embedding of the default dataset in 128 dimensions and 10 cluster centers.

$ python src/main.py --dimensions 128 --clusters 10

License


m-nmf's People

Contributors

benedekrozemberczki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

m-nmf's Issues

community.modularity()

I meet a problem about community.modularity(). First, "community" is not in your requirements so I did not install it. Then I found it and install it. But there is an error that, "community" does not have attribute modularity.

I also tried networkx.community.modularity(), but it said that:

Traceback (most recent call last):
File "main.py", line 17, in
create_and_run_model(args)
File "main.py", line 13, in create_and_run_model
model.optimize()
File "/home/grad/yanzhong/yanzhong/NE/M-NMF/modularity_nmf.py", line 150, in optimize
current_modularity = self.update_state(H)
File "/home/grad/yanzhong/yanzhong/NE/M-NMF/modularity_nmf.py", line 111, in update_state
current_modularity = nx.community.modularity()(indices,self.G)
TypeError: modularity() takes at least 2 arguments (0 given)

ask

Excuse me , I use the M-NMF to embedd network that has nodes more than 10k. When the node number is more than 10k, the error will occur.
捕获

AttributeError: 'MNMF' object has no attribute 'optimal_indices'

Hi there, I am trying to use your method in a dataset, but an error occurs.
it's so strange that sometime this error occurs but sometimes not..(well basically when I first ran the program, there was an 'embedding.csv' document generated(not sure whether it is well trained or not),but the second time when I ran it ,the error occurs.

Traceback (most recent call last):
File "C:\Users\weaton\Desktop\exp\M-NMF-master_2\M-NMF-master\src\main.py", line 103, in
create_and_run_model(args)
File "C:\Users\weaton\Desktop\exp\M-NMF-master_2\M-NMF-master\src\main.py", line 99, in create_and_run_model
model.optimize()
File "C:\Users\weaton\Desktop\exp\M-NMF-master_2\M-NMF-master\src\modularity_nmf.py", line 155, in optimize
self.initiate_dump(session, feed_dict)
File "C:\Users\weaton\Desktop\exp\M-NMF-master_2\M-NMF-master\src\modularity_nmf.py", line 125, in initiate_dump
json_dumper(self.optimal_indices, self.args.assignment_output)
AttributeError: 'MNMF' object has no attribute 'optimal_indices'

AttributeError: 'MNMF' object has no attribute 'optimal_indices'

Hi,there ,
its me again ,
I tried to generate a network that is denser then before and tried to use this method ,but the same error occurs..

well ,the fact is that ,I ran it for 5times, and four times I got the error, and one time I got an embedding.(the program showed me the table like this ...
+-------+------------+
| Round | Modularity |
+=======+============+
but I am not sure whether the embedding is availiable to use.....
the test data is only 8kb ,and only 960+ edges..I deleted all the isolated edges..
THX..

File "E:\M-NMF-master_2\M-NMF-master\src\modularity_nmf.py", line 155, in optimize
self.initiate_dump(session, feed_dict)
File "E:\M-NMF-master_2\M-NMF-master\src\modularity_nmf.py", line 125, in initiate_dump
json_dumper(self.optimal_indices, self.args.assignment_output)
AttributeError: 'MNMF' object has no attribute 'optimal_indices'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.