{ "info": { "author": "Scott Gigante, Yale University", "author_email": "scott.gigante@yale.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Framework :: Jupyter", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Natural Language :: English", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Scientific/Engineering :: Visualization" ], "description": "# M-PHATE\n\n[![Latest PyPi version](https://img.shields.io/pypi/v/m-phate.svg)](https://pypi.org/project/m-phate/)\n[![Travis CI Build](https://api.travis-ci.com/scottgigante/m-phate.svg?branch=master)](https://travis-ci.com/scottgigante/m-phate)\n[![Coverage Status](https://coveralls.io/repos/github/scottgigante/m-phate/badge.svg?branch=master)](https://coveralls.io/github/scottgigante/m-phate?branch=master)\n[![arXiv Preprint](http://img.shields.io/badge/cs.LG-arXiv%3A1908.02831-B31B1B.svg)](https://arxiv.org/abs/1908.02831)\n[![Twitter](https://img.shields.io/twitter/follow/scottgigante.svg?style=social&label=Follow)](https://twitter.com/scottgigante)\n[![GitHub stars](https://img.shields.io/github/stars/scottgigante/M-PHATE.svg?style=social&label=Stars)](https://github.com/scottgigante/M-PHATE/)\n\n![Demonstration M-PHATE plot](demonstration.png)\n\nMultislice PHATE (M-PHATE) is a dimensionality reduction algorithm for the visualization of time-evolving data. To learn more about M-PHATE, you can read our preprint on arXiv in which we apply it to the evolution of neural networks over the course of training. Above we show a demonstration of M-PHATE applied to a 3-layer MLP over 300 epochs of training, colored by epoch (left), hidden layer (center) and the digit label that most strongly activates each hidden unit (right). Below, you see the same network with dropout applied in training embedded in 3D, also colored by most active unit.\n\n### Table of Contents\n\n* [How it works](#How-it-works)\n* [Installation](#Installation)\n* [Usage](#Usage)\n * [Basic Usage Example](#Basic-usage-example)\n * [Network Training](#Network-training)\n * [Example Notebooks](#Examples-notebooks)\n* [Parameter Tuning](#Parameter-tuning)\n* [Figure Reproduction](#Figure-reproduction)\n* [Help](#Help)\n\n![3D rotating gif](dropout3d.gif)\n\n## How it works\n\nMultislice PHATE (M-PHATE) combines a novel multislice kernel construction with the [PHATE visualization](https://github.com/KrishnaswamyLab/PHATE). Our kernel captures the dynamics of an evolving graph structure, that when when visualized, gives unique intuition about the evolution of a system; in our preprint, we show this applied to a neural network over the course of training and re-training. We compare M-PHATE to other dimensionality reduction techniques, showing that the combined construction of the multislice kernel and the use of PHATE provide significant improvements to visualization. In two vignettes, we demonstrate the use M-PHATE on established training tasks and learning methods in continual learning, and in regularization techniques commonly used to improve generalization performance.\n\nThe multislice kernel used in M-PHATE consists of building graphs over time slices of data (e.g. epochs in neural network training) and then connecting these slices by connecting each point to itself over time, weighted by its similarity. The result is a highly sparse, structured kernel which provides insight into the evolving structure of the data.\n\nFor more details, check out our [preprint on arXiv](https://arxiv.org/abs/1908.02831).\n\n![Example of multislice graph](multislice_graph.png)\n\n![Example of multislice kernel](multislice_kernel.png)\n\n## Installation\n\n### Install from `pypi`\n\n```\npip install --user m-phate\n```\n\n### Install from source\n\n```\npip install --user git+https://github.com/scottgigante/m-phate.git\n```\n\n## Usage\n\n### Basic usage example\n\nBelow we apply M-PHATE to simulated data of 50 points undergoing random motion.\n\n```\nimport numpy as np\nimport m_phate\nimport scprep\n\n# create fake data\nn_time_steps = 100\nn_points = 50\nn_dim = 25\nnp.random.seed(42)\ndata = np.cumsum(np.random.normal(0, 1, (n_time_steps, n_points, n_dim)), axis=0)\n\n# embedding\nm_phate_op = m_phate.M_PHATE()\nm_phate_data = m_phate_op.fit_transform(data)\n\n# plot\ntime = np.repeat(np.arange(n_time_steps), n_points)\nscprep.plot.scatter2d(m_phate_data, c=time, ticks=False, label_prefix=\"M-PHATE\")\n```\n\n![Example embedding](example.png)\n\n### Network training\n\nTo apply M-PHATE to neural networks, we provide helper classes to store the samples from the network during training. In order to use these, you must install [`tensorflow`](https://www.tensorflow.org/install) and [`keras`](https://keras.io/#installation).\n\n```\nimport numpy as np\n\nimport keras\nimport scprep\n\nimport m_phate\nimport m_phate.train\nimport m_phate.data\n\n# load data\nx_train, x_test, y_train, y_test = m_phate.data.load_mnist()\n\n# select trace examples\ntrace_idx = [np.random.choice(np.argwhere(y_test[:, i] == 1).flatten(),\n 10, replace=False)\n for i in range(10)]\ntrace_data = x_test[np.concatenate(trace_idx)]\n\n# build neural network\nlrelu = keras.layers.LeakyReLU(alpha=0.1)\ninputs = keras.layers.Input(\n shape=(x_train.shape[1],), dtype='float32', name='inputs')\nh1 = keras.layers.Dense(128, activation=lrelu, name='h1')(inputs)\nh2 = keras.layers.Dense(128, activation=lrelu, name='h2')(h1)\nh3 = keras.layers.Dense(128, activation=lrelu, name='h3')(h2)\noutputs = keras.layers.Dense(10, activation='softmax', name='output_all')(h3)\n\n# build trace model helper\nmodel_trace = keras.models.Model(inputs=inputs, outputs=[h1, h2, h3])\ntrace = m_phate.train.TraceHistory(trace_data, model_trace)\n\n# compile network\nmodel = keras.models.Model(inputs=inputs, outputs=outputs)\nmodel.compile(optimizer='adam', loss='categorical_crossentropy',\n metrics=['categorical_accuracy', 'categorical_crossentropy'])\n\n# train network\nmodel.fit(x_train, y_train, batch_size=128, epochs=200,\n verbose=1, callbacks=[trace],\n validation_data=(x_test,\n y_test))\n\n# extract trace data\ntrace_data = np.array(trace.trace)\nepoch = np.repeat(np.arange(trace_data.shape[0]), trace_data.shape[1])\n\n# apply M-PHATE\nm_phate_op = m_phate.M_PHATE()\nm_phate_data = m_phate_op.fit_transform(trace_data)\n\n# plot the result\nscprep.plot.scatter2d(m_phate_data, c=epoch, ticks=False,\n label_prefix=\"M-PHATE\")\n```\n\n### Example notebooks\n\nFor detailed examples, see our sample notebooks in `keras` and `tensorflow` in [`examples`](https://github.com/scottgigante/m-phate/tree/master/examples):\n\n* Keras\n * [Classifier](https://nbviewer.jupyter.org/github/scottgigante/m-phate/blob/master/examples/classification_keras.ipynb)\n * [Autoencoder](https://nbviewer.jupyter.org/github/scottgigante/m-phate/blob/master/examples/autoencoder_keras.ipynb)\n* Tensorflow\n * [Classifier](https://nbviewer.jupyter.org/github/scottgigante/m-phate/blob/master/examples/classification_tensorflow.ipynb)\n * [Autoencoder](https://nbviewer.jupyter.org/github/scottgigante/m-phate/blob/master/examples/autoencoder_tensorflow.ipynb)\n\n## Parameter tuning\n\nThe key to tuning the parameters of M-PHATE is essentially balancing the tradeoff between interslice connectivity and intraslice connectivity. This is primarily achieved with `interslice_knn` and `intraslice_knn`. You can see an example of the effects of parameter tuning in [this notebook](https://nbviewer.jupyter.org/github/scottgigante/m-phate/blob/master/examples/parameter_tuning.ipynb).\n\n## Figure reproduction\n\nWe provide scripts to reproduce all of the empirical figures in the preprint. \n\nTo run them:\n\n```\ngit clone https://github.com/scottgigante/m-phate\ncd m-phate\npip install --user .\nDATA_DIR=~/data/checkpoints/m_phate # change this if you want to store the data elsewhere\n\nchmod +x scripts/generalization/generalization_train.sh\nchmod +x scripts/task_switching/classifier_mnist_task_switch_train.sh\n\n./scripts/generalization/generalization_train.sh $DATA_DIR\n./scripts/task_switching/classifier_mnist_task_switch_train.sh $DATA_DIR\n\npython scripts/demonstration_plot.py $DATA_DIR\npython scripts/comparison_plot.py $DATA_DIR\npython scripts/generalization_plot.py $DATA_DIR\npython scripts/task_switch_plot.py $DATA_DIR\n\n# generalization plot using training data\n./scripts/generalization/generalization_train.sh ${DATA_DIR}/train_data --sample-train-data\nmkdir train_data; cd train_data; python -i ../scripts/generalization_plot.py ${DATA_DIR}/train_data; cd ..\n```\n\n## TODO\n\n* Provide support for PyTorch\n* Notebook examples for:\n * Classification, pytorch\n * Autoencoder, pytorch\n* Build readthedocs page\n* Update arXiv link\n\n## Help\n\nIf you have any questions, please feel free to [open an issue](https://github.com/scottgigante/m-phate/issues).\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/scottgigante/m-phate/archive/v0.1.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/scottgigante/m-phate", "keywords": "big-data,computational-biology", "license": "GNU General Public License Version 3", "maintainer": "", "maintainer_email": "", "name": "m-phate", "package_url": "https://pypi.org/project/m-phate/", "platform": "", "project_url": "https://pypi.org/project/m-phate/", "project_urls": { "Download": "https://github.com/scottgigante/m-phate/archive/v0.1.1.tar.gz", "Homepage": "https://github.com/scottgigante/m-phate" }, "release_url": "https://pypi.org/project/m-phate/0.1.1/", "requires_dist": [ "numpy (>=1.14.0)", "scipy (>=1.1.0)", "scikit-learn (>=0.19.1)", "pandas (>=0.25)", "joblib", "scprep (>=1.0)", "phate (>=0.4.3)", "graphtools (>=1.1)", "matplotlib (<3.1,>=3.0)", "sphinx (<=1.8.5) ; extra == 'doc'", "sphinxcontrib-napoleon ; extra == 'doc'", "autodocsumm ; extra == 'doc'", "ipykernel ; extra == 'doc'", "nbsphinx ; extra == 'doc'", "nose2 ; extra == 'test'", "coverage ; extra == 'test'", "coveralls ; extra == 'test'", "keras (>=2.2) ; extra == 'test'", "tensorflow (<2.0,>=1.13) ; extra == 'test'", "parameterized ; extra == 'test'" ], "requires_python": "", "summary": "m-phate", "version": "0.1.1" }, "last_serial": 5946260, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "5e8e1f219a7c9f670d7c522099e4e807", "sha256": "791c2f72ad442507576d7b978591b97e57c3b1ae30dbb4996032ae58e9e256d0" }, "downloads": -1, "filename": "m_phate-0.1.0-py3.5.egg", "has_sig": false, "md5_digest": "5e8e1f219a7c9f670d7c522099e4e807", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 20536, "upload_time": "2019-08-07T23:35:39", "url": "https://files.pythonhosted.org/packages/53/f4/56f3246b36a044b04daf127517a58dbc9a6ae7506ee35d91e7e8bf50bbf3/m_phate-0.1.0-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "eede5970a2082ae117601b61b6b5eca6", "sha256": "e0530ac1be2340f6604d153965f16341a9099a664596d9f7b7c6393730d422ad" }, "downloads": -1, "filename": "m_phate-0.1.0-py3.6.egg", "has_sig": false, "md5_digest": "eede5970a2082ae117601b61b6b5eca6", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 20363, "upload_time": "2019-08-07T23:35:39", "url": "https://files.pythonhosted.org/packages/39/97/79efeef45e2c9ed8909f2f1f58fcc1c7495fe94d521a3c4a9afa172cfbe9/m_phate-0.1.0-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "b1d2adfff5aede832496e89fb8d633b4", "sha256": "77118aa1bd27ba92db4deb0eccd3694b73f0cb9dc3974ee069a0aa92dfedd961" }, "downloads": -1, "filename": "m_phate-0.1.0-py3.7.egg", "has_sig": false, "md5_digest": "b1d2adfff5aede832496e89fb8d633b4", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 20395, "upload_time": "2019-08-07T23:35:39", "url": "https://files.pythonhosted.org/packages/d9/99/4d0ad4bca46723838d442f596ca97d0d82649464ac80e12cdfa1f952eadb/m_phate-0.1.0-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "269c1416e2dbfcddb855e0ca9c1630eb", "sha256": "68dd6d84eba43b5c1acc6114630efeae84853e4576dce0502b5c05e476b6d15c" }, "downloads": -1, "filename": "m_phate-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "269c1416e2dbfcddb855e0ca9c1630eb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23551, "upload_time": "2019-08-07T23:35:36", "url": "https://files.pythonhosted.org/packages/29/9a/2fdc414e4aa136088385bf59ac7c5a66b726e32b336db89078fe2f00fefc/m_phate-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e11b508291a489ccf262bfe22d39f529", "sha256": "b5c7f1e47dc6507a502d89a39091fe9c910f3a06a287cabd31b41a68eac01698" }, "downloads": -1, "filename": "m_phate-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e11b508291a489ccf262bfe22d39f529", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15104, "upload_time": "2019-08-07T23:35:40", "url": "https://files.pythonhosted.org/packages/e3/a6/b5dfd332ea0a5cfc90a89b58164ffe2704a98ff18ee0a61b3543b511604d/m_phate-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "32032f38e6851618a54ddd533a8a1c3e", "sha256": "987876d69baa7ea74419becf20f0e3ba183ea449b7b22fc9e590e1015ed9c962" }, "downloads": -1, "filename": "m_phate-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "32032f38e6851618a54ddd533a8a1c3e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23837, "upload_time": "2019-10-08T19:16:54", "url": "https://files.pythonhosted.org/packages/4b/e1/7553d1bc87fcf08560461449aa3aa4a7d85f2675df7e58af5e060ce3513e/m_phate-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ad782190f8c70ad7c41d62dbb88fcd2e", "sha256": "f0a93441e35207e7dd2525e8122d9be4d894c650d32ab8512d04f5f17e4723e7" }, "downloads": -1, "filename": "m_phate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ad782190f8c70ad7c41d62dbb88fcd2e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15629, "upload_time": "2019-10-08T19:16:55", "url": "https://files.pythonhosted.org/packages/42/18/d00bd32290d6a1ab3a16d58f9d691faa0e52391614c7d71ffe9c97732d9c/m_phate-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "32032f38e6851618a54ddd533a8a1c3e", "sha256": "987876d69baa7ea74419becf20f0e3ba183ea449b7b22fc9e590e1015ed9c962" }, "downloads": -1, "filename": "m_phate-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "32032f38e6851618a54ddd533a8a1c3e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23837, "upload_time": "2019-10-08T19:16:54", "url": "https://files.pythonhosted.org/packages/4b/e1/7553d1bc87fcf08560461449aa3aa4a7d85f2675df7e58af5e060ce3513e/m_phate-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ad782190f8c70ad7c41d62dbb88fcd2e", "sha256": "f0a93441e35207e7dd2525e8122d9be4d894c650d32ab8512d04f5f17e4723e7" }, "downloads": -1, "filename": "m_phate-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ad782190f8c70ad7c41d62dbb88fcd2e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15629, "upload_time": "2019-10-08T19:16:55", "url": "https://files.pythonhosted.org/packages/42/18/d00bd32290d6a1ab3a16d58f9d691faa0e52391614c7d71ffe9c97732d9c/m_phate-0.1.1.tar.gz" } ] }