Skip to main content

Learning from and reconstructing networks using Nonnegative Matrix Factorization

Project description

logo

Network-Dictionary-Learning

Learning from and reconstructing networks using MCMC motif sampling and Nonnegative Matrix Factorization

Installation

To install the Network Dictionary Learning package, run this command in your terminal:

$ pip install ndlearn

This is the preferred method to install Network Dictionary Learning. If you don't have pip installed, these installation instructions can guide you through the process.

Usage

Our package lies on the backbone of the NNetwork class (see https://github.com/HanbaekLyu/NNetwork).

>>> from NNetwork import Wtd_NNetwork
>>> G = Wtd_NNetwork()
>>> G.load_edges("Data/example.txt", delimiter=",")

Learning a Dictionary

>>> from ndl import NetDictLearner
>>> NDL = NetDictLearner(G=G, n_components=25, k=21)
>>> NDL.train_dict()
>>> W = NDL.get_dictionary()

Display and save the learned dictionary:

>>> NDL.display_dict(save_file="Dictionaries/example_dict.npy")

Replace the dictionary with a pre-trained dictionary and/or replace the network:

>>> NDL.set_dict(W)
>>> NDL.set_network(G)

Reconstructing a Network

>>> G_recons = NDL.reconstruct(recons_iter=10000)

The NetDictLearner class provices the base code to perform network dictionary learning and network reconstruction, but we also provide a series of helper fuctions to use alongside the NetDictLearner class to assist on performing tasks related to Network Dictionary Learning and evaluate performance.

Measure Accuracy of Reconstruction (Jaccard)

>>> from ndl import utils
>>> utils.recons_accuracy(G, G_recons)
0.92475345

Network Denoising Application

To add positive corruption (overlaying edges) or negative corruption (deleting edges) from a networks:

>>> len(G.edges())
1000
>>> G_add = utils.corrupt(G, p=0.1, noise_type="ER")
>>> G_remove_10 = utils.corrupt(G, p=0.1, noise_type="negative")
>>>len(G_remove_10.edges())
900

To measure the AUC of network denoising with positive (or negative) noise:

>>> G_corrupt = utils.corrupt(G, p=0.1, noise_type="ER")
>>> NDL_corrupt = NetDictLearner(G=G_corrupt)
>>> NDL_corrupt.train_dict()
>>> G_corrupt_recons = NDL_corrupt.reconstruct(recons_iter=10000)
>>> utils.auc(original=G, corrupt=G_corrupt, corrupt_recons=G_corrupt_recons, type="positive")
0.864578

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndlearn-0.0.1.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

ndlearn-0.0.1-py2.py3-none-any.whl (24.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ndlearn-0.0.1.tar.gz.

File metadata

  • Download URL: ndlearn-0.0.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

File hashes

Hashes for ndlearn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7cb664f966bf7ae6230e958e62039d09d513ce60b663c40a4763434c931bd2bf
MD5 f7e9e2126f6769a91a6c6739435e00a4
BLAKE2b-256 291e1e4b4ba860eef015af6e19fc02686e2d04648ed1da77aae973e0bf19085c

See more details on using hashes here.

File details

Details for the file ndlearn-0.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: ndlearn-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

File hashes

Hashes for ndlearn-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f1c05a1d7e343ee8d3ebe244c6cb51b4423ed8e15b1fb771568c78f69d8e7b35
MD5 3958757fb90a3fa581362fed30f1de48
BLAKE2b-256 900ede08d0870d48e97a4b46f947898164f25f93839d818a2c4116c6fe890422

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page