From ac1a89a1b452fbbbf072752a8b4038ecd9f5a3f1 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 27 Jan 2020 13:21:17 +0100 Subject: [PATCH 1/4] Reorganize files and encapsulate commands in main() functions --- src/netmf/__init__.py | 0 netmf.py => src/netmf/netmf.py | 5 ++++- predict.py => src/netmf/predict.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/netmf/__init__.py rename netmf.py => src/netmf/netmf.py (99%) rename predict.py => src/netmf/predict.py (99%) diff --git a/src/netmf/__init__.py b/src/netmf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netmf.py b/src/netmf/netmf.py similarity index 99% rename from netmf.py rename to src/netmf/netmf.py index 6eebe77..88166e7 100644 --- a/netmf.py +++ b/src/netmf/netmf.py @@ -122,7 +122,7 @@ def netmf_small(args): logger.info("Save embedding to %s", args.output) np.save(args.output, deepwalk_embedding, allow_pickle=False) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser() parser.add_argument("--input", type=str, required=True, help=".mat input file path") @@ -155,3 +155,6 @@ def netmf_small(args): else: netmf_small(args) + +if __name__ == "__main__": + main() diff --git a/predict.py b/src/netmf/predict.py similarity index 99% rename from predict.py rename to src/netmf/predict.py index ba4d50c..1d34106 100644 --- a/predict.py +++ b/src/netmf/predict.py @@ -88,7 +88,7 @@ def predict_cv(X, y, train_ratio=0.2, n_splits=10, random_state=0, C=1.): np.mean(macro) * 100) -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser() parser.add_argument("--label", type=str, required=True, help="input file path for labels (.mat)") @@ -136,3 +136,6 @@ def predict_cv(X, y, train_ratio=0.2, n_splits=10, random_state=0, C=1.): predict_cv(embedding, label, train_ratio=tr/100., n_splits=args.num_split, C=args.C, random_state=args.seed) + +if __name__ == "__main__": + main() From 8e4bbcffc56a507f960a3c3ca3f076dceb771bc9 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 27 Jan 2020 13:29:51 +0100 Subject: [PATCH 2/4] Add minimal setup configuration I took the liberty to put a few classifiers as well. --- setup.cfg | 44 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 8 ++++++++ 2 files changed, 52 insertions(+) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..5053a86 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,44 @@ +########################## +# Setup.py Configuration # +########################## +# Configuring setup() +[metadata] +name = netmf +version = 0.0.1 + +# Author information +author = Jiezhong Qiu + +# License information +license = MIT +license_file = LICENSE + +# Search tags +classifiers = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Science/Research + License :: OSI Approved :: MIT License + Operating System :: OS Independent + Programming Language :: Python + Topic :: Scientific/Engineering :: Artificial Intelligence +keywords = + Node Representation Learning + Network Representation Learning + +[options] +install_requires = + scipy + numpy + theano + sklearn + +python_requires = >=3.5 + +# Where is my code +packages = find: +package_dir = + = src + +[options.packages.find] +where = src diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a78fbfd --- /dev/null +++ b/setup.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +"""Setup module.""" + +import setuptools + +if __name__ == '__main__': + setuptools.setup() From b65eeac9e558dcc4db596a2175f3af3702b2a73f Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 27 Jan 2020 13:30:39 +0100 Subject: [PATCH 3/4] Add CLI entrypoints and documentation in README --- README.md | 10 ++++++++++ setup.cfg | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a7d457e..5b63128 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,16 @@ Wikipedia [Source](http://www.mattmahoney.net/dc/textdata) [Preprocessed](http:/ [Flickr](http://leitang.net/code/social-dimension/data/flickr.mat) +## Usage + +This is a minimal example to use the code via the command line to train on the PPI network. + +```bash +$ wget http://snap.stanford.edu/node2vec/Homo_sapiens.mat +$ netmf-train --input Homo_sapiens.mat --output homo_sapiens_embeddings.txt +$ netmf-predict --label Homo_sapiens.mat --embedding homo_sapiens_embeddings.txt.npy --seed 5 +``` + ## Cite Please cite our paper if you use this code in your own work: diff --git a/setup.cfg b/setup.cfg index 5053a86..246b026 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,3 +42,8 @@ package_dir = [options.packages.find] where = src + +[options.entry_points] +console_scripts = + netmf-train = netmf.netmf:main + netmf-predict = netmf.predict:main From 14943fa8b463e06cc57a635ff456854a87d4d901 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Mon, 27 Jan 2020 14:08:33 +0100 Subject: [PATCH 4/4] Add installation documentation --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 5b63128..13c5baf 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,24 @@ Wikipedia [Source](http://www.mattmahoney.net/dc/textdata) [Preprocessed](http:/ [Flickr](http://leitang.net/code/social-dimension/data/flickr.mat) +## Installation + +The latest version of NetMF can be downloaded and installed from +[GitHub](https://github.com/xptree/NetMF) on Python 3.5+ with: + +```bash +$ pip install git+https://github.com/xptree/NetMF.git +``` + +For developers, NetMF can be installed from the source code in +in development mode with: + +```bash +$ git clone https://github.com/xptree/NetMF.git +$ cd NetMF +$ pip install -e . +``` + ## Usage This is a minimal example to use the code via the command line to train on the PPI network.