{"id":21037594,"url":"https://github.com/faranalytics/neuralplex","last_synced_at":"2025-04-12T14:33:00.621Z","repository":{"id":225614587,"uuid":"765393876","full_name":"faranalytics/neuralplex","owner":"faranalytics","description":"An object oriented neural network implementation.","archived":false,"fork":false,"pushed_at":"2025-01-18T22:55:45.000Z","size":474,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T22:06:02.916Z","etag":null,"topics":["deep-learning","neural-network","visualization"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/neuralplex/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faranalytics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-29T20:44:33.000Z","updated_at":"2025-01-18T22:55:47.000Z","dependencies_parsed_at":"2024-03-03T09:08:32.681Z","dependency_job_id":"6d0ef3de-785e-44e8-8a45-05e7a70e9381","html_url":"https://github.com/faranalytics/neuralplex","commit_stats":null,"previous_names":["faranalytics/neuralplex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faranalytics%2Fneuralplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faranalytics%2Fneuralplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faranalytics%2Fneuralplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faranalytics%2Fneuralplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faranalytics","download_url":"https://codeload.github.com/faranalytics/neuralplex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581260,"owners_count":21128137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","neural-network","visualization"],"created_at":"2024-11-19T13:27:06.211Z","updated_at":"2025-04-12T14:33:00.600Z","avatar_url":"https://github.com/faranalytics.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural-pleX\n\nAn object oriented neural network implementation.\n\n## Introduction\n\n**Neural-pleX** is an intuitive object oriented neural network implementation. The Neural-pleX API consists of Network, Layer, and Neuron constructors. The networks can be easily [visualized](#visualizations-of-the-network-before-and-after-training) using a visualization library.\n\n## Table of contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Example](#example)\n- [Test](#test)\n\n## Installation\n\n```bash\npip install neuralplex\n```\n\n## Usage\n\nThis implementation demonstrates each component of the API. A 3 layer neural network is constructed that has a 4 neuron input Layer and a 1 neuron output layer. The hidden layer has 8 neurons.\n\n### Implement a 3 layer neural network\n\n#### Import the Network, Layer, and Neuron classes.\n\n```python\nfrom neuralplex import Network, Layer, Neuron\n```\n\n#### Set a step.\n\n```python\nSTEP = 1e-4\n```\n\n#### Construct a neural network by specifying the Neurons for each Layer and adding the Layers to a Network. \n\nThe resulting neural network will have 4 input neurons, 1 ouput neuron, and 8 neurons in the hidden layer.\n\n```python\nl1 = Layer(neurons=[Neuron(m=random()) for i in range(0, 4)], step=STEP)\nl2 = Layer(neurons=[Neuron(m=random()) for i in range(0, 8)], step=STEP)\nl3 = Layer(neurons=[Neuron(m=random())], step=STEP)\nn1 = Network([l1, l2, l3])\n```\n\n#### With the Network defined, you can train the network. \n\nHere the network is trained to recognize the nibble 1111 as the decimal number 15.\n\n```python\nn1.train([1,1,1,1], [15])\n```\n\nYou can generate and print a prediction using the `predict` method. Because the network underwent just one iteration of training, the estimate will likely be inaccurate. The accuracy of the prediction can be improved by iteratively training the network. Please see the [Train and Visualize a Neural-pleX Network](#train-and-visualize-a-neural-plex-network) implementation for an example of how to iteratively train the network.\n\n```python\nprediction = n1.predict([1,1,1,1])\nprint(prediction)\n```\n\n## Example\n\n### Train and visualize a Neural-pleX network\n\nIn this example you will use [D3](https://d3js.org/) and [D3Blocks](https://d3blocks.github.io/d3blocks/pages/html/index.html) in order to visualize a neural network _before_ and _after_ training.\n\n#### Import the necessary dependencies.\n\n```python\nfrom random import random, randint\nimport pandas as pd\nfrom neuralplex import Network, Layer, Neuron, get_edge_data\nfrom d3blocks import D3Blocks\n```\n\n#### Implement a function that will visualize the network.\n\n```python\ndef visualize(n):\n\n    d3 = D3Blocks()\n\n    df = pd.DataFrame(get_edge_data(n))\n\n    df['weight'] = df['weight'] * 42\n\n    d3.d3graph(df, charge=1e4, filepath=None)\n\n    for index, source, target, weight in df.to_records():\n        if source.startswith('l1'):\n            color = 'green'\n        elif source.startswith('l2'):\n            color = 'red'\n        else:\n            color='yellow'\n\n        d3.D3graph.node_properties[source]['color'] = color\n        d3.D3graph.node_properties[source]['size'] = weight\n\n    d3.D3graph.show(save_button=True, filepath='./Neural-pleX.html')\n```\n\n#### Set a step.\n\n```python\nSTEP = 1e-5\n```\n\n#### Construct a network.\n\n```python\nn = Network([Layer(neurons=[Neuron(m=random(), name=f'l{layer}-p{i}') for i in range(1, size+1)], step=STEP) for layer, size in zip([1,2,3], [4, 8, 1])])\n```\n\n#### Use D3 and D3Blocks in order to visualize the network _before_ training.\n\n```python\nvisualize(n)\n```\n\n#### Train the network.\n\n```python\nfor i in range(0, int(1e5)):\n    rn = randint(1, 15)\n    b = [int(n) for n in bin(rn)[2:]]\n    while len(b) \u003c 4:\n        b = [0] + b\n    n.train(b, [rn])\n```\n\n#### Use D3 and D3Blocks in order to visualize the network _after_ training.\n\n```python\nvisualize(n)\n```\n\n##### Visualizations of the network before and after training:\n\nThe green nodes comprise the inputs, the red nodes comprise the hidden layer, and the yellow node is the output. The size of the Neuron is proportional to its coefficient and dependent on its random initialization and subsequent training.\n\n|                             Before Training                              |                             After Training                             |\n| :----------------------------------------------------------------------: | :--------------------------------------------------------------------: |\n| ![Neural-pleX Before Training](./images/Neural-pleX_before_training.png) | ![Neural-pleX After Training](./images/Neural-pleX_after_training.png) |\n\n## Test\n\n### How to run the Nibble Challenge\n\nA model is trained that estimates a decimal value given a binary nibble.\n\n#### Clone the repository.\n\n```bash\ngit clone https://github.com/faranalytics/neuralplex.git\n```\n\n#### Change directory into the repository.\n\n```bash\ncd neuralplex\n```\n\n#### Install the package in editable mode.\n\n```bash\npip install -e .\n```\n\n#### Run the tests.\n\n```bash\npython -m unittest -v\n```\n\n##### Output\n\n```bash\ntest_nibbles (tests.test.Test.test_nibbles) ... Training the model.\nTraining iteration: 0\nTraining iteration: 1000\nTraining iteration: 2000\nTraining iteration: 3000\nTraining iteration: 4000\nTraining iteration: 5000\nTraining iteration: 6000\nTraining iteration: 7000\nTraining iteration: 8000\nTraining iteration: 9000\n1 input: [0, 0, 0, 1], truth: 1 prediction: [1.8160007977374275]\n2 input: [0, 0, 1, 0], truth: 2 prediction: [2.768211299141504]\n3 input: [0, 0, 1, 1], truth: 3 prediction: [4.584212096878932]\n4 input: [0, 1, 0, 0], truth: 4 prediction: [3.772563194981495]\n5 input: [0, 1, 0, 1], truth: 5 prediction: [5.588563992718923]\n6 input: [0, 1, 1, 0], truth: 6 prediction: [6.540774494122998]\n7 input: [0, 1, 1, 1], truth: 7 prediction: [8.356775291860426]\n8 input: [1, 0, 0, 0], truth: 8 prediction: [6.784403350226391]\n9 input: [1, 0, 0, 1], truth: 9 prediction: [8.600404147963818]\n10 input: [1, 0, 1, 0], truth: 10 prediction: [9.552614649367897]\n11 input: [1, 0, 1, 1], truth: 11 prediction: [11.368615447105324]\n12 input: [1, 1, 0, 0], truth: 12 prediction: [10.556966545207885]\n13 input: [1, 1, 0, 1], truth: 13 prediction: [12.372967342945314]\n14 input: [1, 1, 1, 0], truth: 14 prediction: [13.32517784434939]\n15 input: [1, 1, 1, 1], truth: 15 prediction: [15.141178642086818]\nR2: 0.9599237139109126\nok\n\n----------------------------------------------------------------------\nRan 1 test in 0.333s\n\nOK\n```\n\n## Support\nIf you have a feature request or run into any issues, feel free to submit an [issue](https://github.com/faranalytics/neuralplex/issues) or start a [discussion](https://github.com/faranalytics/neuralplex/discussions). You’re also welcome to reach out directly to one of the authors.\n\n- [Adam Patterson](https://github.com/adamjpatterson)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaranalytics%2Fneuralplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaranalytics%2Fneuralplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaranalytics%2Fneuralplex/lists"}