Metadata-Version: 2.1
Name: ndlearn
Version: 0.0.1
Summary: Learning from and reconstructing networks using Nonnegative Matrix Factorization
Home-page: https://github.com/jvendrow/Network-Dictionary-Learning
Author: Joshua Vendrow
Author-email: jvendrow@math.ucla.edu
License: MIT
Keywords: ndlearn
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research 
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: networkx
Requires-Dist: scipy
Requires-Dist: scikit-learn
Requires-Dist: matplotlib
Requires-Dist: tqdm
Requires-Dist: psutil
Requires-Dist: tensorly
Provides-Extra: all
Requires-Dist: numpy ; extra == 'all'
Requires-Dist: networkx ; extra == 'all'
Requires-Dist: scipy ; extra == 'all'
Requires-Dist: scikit-learn ; extra == 'all'
Requires-Dist: matplotlib ; extra == 'all'
Requires-Dist: tqdm ; extra == 'all'
Requires-Dist: psutil ; extra == 'all'
Requires-Dist: tensorly ; extra == 'all'
Requires-Dist: bump2version (>=1.0.0) ; extra == 'all'
Requires-Dist: ipython (>=7.5.0) ; extra == 'all'
Requires-Dist: twine (>=1.13.0) ; extra == 'all'
Requires-Dist: wheel (>=0.33.1) ; extra == 'all'
Provides-Extra: dev
Requires-Dist: numpy ; extra == 'dev'
Requires-Dist: networkx ; extra == 'dev'
Requires-Dist: scipy ; extra == 'dev'
Requires-Dist: scikit-learn ; extra == 'dev'
Requires-Dist: matplotlib ; extra == 'dev'
Requires-Dist: tqdm ; extra == 'dev'
Requires-Dist: psutil ; extra == 'dev'
Requires-Dist: tensorly ; extra == 'dev'
Requires-Dist: bump2version (>=1.0.0) ; extra == 'dev'
Requires-Dist: ipython (>=7.5.0) ; extra == 'dev'
Requires-Dist: twine (>=1.13.0) ; extra == 'dev'
Requires-Dist: wheel (>=0.33.1) ; extra == 'dev'
Provides-Extra: docs
Provides-Extra: setup
Provides-Extra: test
Requires-Dist: numpy ; extra == 'test'
Requires-Dist: networkx ; extra == 'test'
Requires-Dist: scipy ; extra == 'test'
Requires-Dist: scikit-learn ; extra == 'test'
Requires-Dist: matplotlib ; extra == 'test'
Requires-Dist: tqdm ; extra == 'test'
Requires-Dist: psutil ; extra == 'test'
Requires-Dist: tensorly ; extra == 'test'

<p align="center">
<img width="600" src="https://github.com/jvendrow/Network-Dictionary-Learning/blob/master/NDL_logo.png" alt="logo">
</p>


# 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:

```bash
$ pip install ndlearn
```

This is the preferred method to install Network Dictionary Learning. If you don't have [pip](https://pip.pypa.io) installed, these [installation instructions](http://docs.python-guide.org/en/latest/starting/installation/) can guide you through the process.

## Usage

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

```python
>>> from NNetwork import Wtd_NNetwork
>>> G = Wtd_NNetwork()
>>> G.load_edges("Data/example.txt", delimiter=",")
```
#### Learning a Dictionary

```python
>>> 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:
```python
>>> NDL.display_dict(save_file="Dictionaries/example_dict.npy")
```

Replace the dictionary with a pre-trained dictionary and/or replace the network:
```python
>>> NDL.set_dict(W)
>>> NDL.set_network(G)
```
#### Reconstructing a Network

```python
>>> 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)

```python
>>> 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:
```python
>>> 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:
```python
>>> 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
```





