{"id":21314629,"url":"https://github.com/dor-sketch/binary-perceptron-simulator","last_synced_at":"2025-03-15T21:22:42.687Z","repository":{"id":225733607,"uuid":"764843363","full_name":"Dor-sketch/binary-perceptron-simulator","owner":"Dor-sketch","description":"A Python-based project that utilizes perceptron neural networks to classify 21-digit binary numbers into categories based on the presence of 'ones'.","archived":false,"fork":false,"pushed_at":"2024-07-17T13:18:51.000Z","size":27947,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T10:23:04.946Z","etag":null,"topics":["ai","binary-classification","perceptron"],"latest_commit_sha":null,"homepage":"https://dorpascal.com/binary-perceptron-simulator/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dor-sketch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-28T20:10:50.000Z","updated_at":"2024-12-31T10:09:09.000Z","dependencies_parsed_at":"2024-03-04T01:48:02.933Z","dependency_job_id":"ef0bce2d-7a57-47ef-844e-e7bba863f478","html_url":"https://github.com/Dor-sketch/binary-perceptron-simulator","commit_stats":null,"previous_names":["dor-sketch/perceptualbinaryclassifier","dor-sketch/binary-perceptron-simulator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2Fbinary-perceptron-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2Fbinary-perceptron-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2Fbinary-perceptron-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dor-sketch%2Fbinary-perceptron-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dor-sketch","download_url":"https://codeload.github.com/Dor-sketch/binary-perceptron-simulator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243791136,"owners_count":20348423,"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":["ai","binary-classification","perceptron"],"created_at":"2024-11-21T18:14:18.974Z","updated_at":"2025-03-15T21:22:42.637Z","avatar_url":"https://github.com/Dor-sketch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧠 Perceptron Classifier for Binary Numbers\n\nA simple neural network consisting of two single-layer perceptrons to classify 21-digit binary numbers into three categories based on the count of 'ones' present in the number. This project implements the fundamental concepts of perceptron-based classification, including weight initialization, prediction, training, and plotting decision boundaries.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"./docs/images/cover.png\" target=\"_blank\"\u003e\n    \u003cimg src=\"./docs/images/cover.png\" alt=\"Perceptron Classifier\" width=\"400\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n\u003c!-- @import \"[TOC]\" {cmd=\"toc\" depthFrom=1 depthTo=6 orderedList=false} --\u003e\n\n\u003c!-- code_chunk_output --\u003e\n\n- [📖 Overview](#-overview)\n- [🌟 Features](#-features)\n- [💻 Technologies Used](#-technologies-used)\n- [🛠 Installation and Setup](#-installation-and-setup)\n- [🚀 Usage](#-usage)\n- [💡 How It Works](#-how-it-works)\n- [👥 Contributing](#-contributing)\n- [📄 License](#-license)\n- [🎉 Acknowledgments](#-acknowledgments)\n\n\u003c!-- /code_chunk_output --\u003e\n\n---\n\n## 📖 Overview\n\n\u003cp align=\"center\" style=\"background-color: transparent;\"\u003e\n  \u003cimg src=\"docs/images/transparant_animation.gif\" alt=\"Learning Process\" width=\"600\"\u003e\n\u003c/p\u003e\n\nThis project implements a simple neural network consisting of perceptrons to classify 21-digit binary numbers into three categories based on the count of 'ones' present in the number. The categories are:\n\n1. Numbers with more than 15 ones. ✅\n2. Numbers with less than 15 ones. ❌\n3. All other numbers. 🔄\n\nThe implementation demonstrates the fundamental concepts of perceptron-based classification, including weight initialization, prediction, training, and plotting decision boundaries. This project is part of my software engineering portfolio, showcasing my understanding of machine learning algorithms and my ability to implement them from scratch.\n\n---\n\n## 🌟 Features\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/images/wave_animation.gif\" alt=\"Perceptron Classifier\" width=\"320\"\u003e\n\u003c/p\u003e\n\n- **Perceptron Training**: Trains two separate perceptrons to classify the binary numbers into the specified categories.\n- **Prediction**: Predicts the category of a new 21-digit binary number.\n- **Visualization**: Plots the decision boundaries of the perceptrons and the distribution of the binary numbers based on the classification.\n- **Interactive GUI**: A simple Tkinter GUI for easy interaction with the perceptron classifier.\n\n## 💻 Technologies Used\n\n- Python 3\n- NumPy for numerical operations\n- Matplotlib for plotting\n- Tkinter for the GUI\n- Scikit-learn for PCA (Principal Component Analysis) used in plotting decision boundaries\n\n## 🛠 Installation and Setup\n\nEnsure you have Python 3.x installed on your system. You can download Python [here](https://www.python.org/downloads/).\n\nClone the repository to your local machine:\n\n```bash\ngit clone https://github.com/Dor-sketch/PerceptualBinaryClassifier/git\n```\n\nNavigate to the cloned repository:\n\n```bash\ncd perceptron-binary-classifier\n```\n\nInstall the required Python packages:\n\n```bash\npip install numpy matplotlib scikit-learn\n```\n\n---\n\n## 🚀 Usage\n\nTo run the program and launch the GUI, execute the following command in the terminal:\n\n```bash\npython perceptron.py\n```\n\nThe GUI will open, allowing you to interact with the perceptron classifier.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/images/gui_animation.gif\"  alt=\"Perceptron GUI\" width=\"800\"\u003e\n\u003c/p\u003e\n\nIn the GUI, you can:\n\n- Enter a 21-digit binary number to predict its category.\n\n- Train the perceptron models with generated binary numbers.\n\n- Plot the decision boundaries and the distribution of binary numbers.\n\n- Visualize the weights of the perceptrons and the learning process via real-time animations.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/images/boundary.png\" alt=\"Decision Boundaries\" width=\"400\"\u003e\n\u003c/p\u003e\n\nThe project also includes commented code for genrating advanced visualizations and testing the perceptron models. For now, it is not recommended to run the code in the `perceptron.py` file, as it may take a long time to execute.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/images/Separation3.gif\" alt=\"Perceptron Classifier\" width=\"400\"\u003e\n\n  \u003cimg src=\"docs/images/Separation.gif\" alt=\"Perceptron    Classifier\" width=\"400\"\u003e\n\n  \u003cimg src=\"docs/images/Separation2.gif\" alt=\"Perceptron Classifier\" width=\"400\"\u003e\n\n  \u003cimg src=\"docs/images/movie.gif\" alt=\"Perceptron Classifier\" width=\"400\"\u003e\n\u003c/p\u003e\n\n## 💡 How It Works\n\nOur task is classifying 21-digit binary numbers into 3 classes:\n\n1. More than 15 ones\n2. More than 15 zeros\n3. Else\n\nWe can't use a single one-layer perceptron to solve the problem for the following reasons:\n\n1. A perceptron can only classify linearly separable problems, and this problem is not linearly separable. The three classes are not linearly separable.\n\n2. Even if the problem were linearly separable, the output of the perceptron is binary, and we need to classify the input into 3 classes.\n\nWith multiple single-layer perceptrons **we can** classify the 21-digit binary numbers into 3 classes in the following way:\n\nThe input to the perceptrons will be the 21-digit binary number represented as a vector of 21 elements. The output of perceptron i will be 1 if there are more than i 1s in the input, and 0 otherwise.\n\nWe'll set eta to 1 for simplicity.\n\nWe will use a number of perceptrons as follows:\n\n1. The first perceptron will be trained to classify if the input has more than 15 1s. The weights of the perceptron will adjust during the training to find the hyperplane that separates the input into 2 classes. For example, a perceptron with the following weights will classify if the input has more than 0 1s: $w_{0+} = [1, 1, 1, ..., 1]$. A perceptron with the following weights will classify if the input has more than 1 1s: $w_{1+} = [0.5, 0.5, 0.5, ..., 0.5]$ And so on. Using the same method, we can construct the perceptrons that will classify if the input has more than 15 1s: $w_{15+} = [\\frac{1}{16}, \\frac{1}{16}, \\frac{1}{16}, ..., \\frac{1}{16}]$\n\n2. We can deduce the second class by taking the output of the 1's finders: if the output of the 6th perceptron is -1, then the input doesn't have more than 6 1s, and thus, has more than 15 0s. The same applies for the 5th perceptron and so on until the first perceptron. Alternatively, we can use a similar method to the one used for the 1's finders, but for zeros. For example, a perceptron with the following weights will classify if the input has at least 1 0: $w_{1-} = [\\frac{1}{21}, \\frac{1}{21}, \\frac{1}{21}, ..., \\frac{1}{21}]$. A perceptron with the following weights will classify if the input has at least 15 0s: $w_{15-} = [\\frac{1}{6}, \\frac{1}{6}, \\frac{1}{6}, ..., \\frac{1}{6}]$ And so on. Note again that the threshold is 1, so if we sum the weights and the input and the result is less than 1, then the input has at least 1 0.\n\n3. We can get the first class by taking the output of the first perceptrons, the second class by taking the output of the second perceptron - if it's -1, it means not even 6 ones, and hence -\u003e more than 15 zeros. The third class is identified by taking the rest of the cases (the first is -1 and the second is 1).\n\n| Before training | After training |\n| --- | --- |\n| \u003cimg src=\"docs/images/before.png\" alt=\"Before training\" width=\"400\"\u003e | \u003cimg src=\"docs/images/after.png\" alt=\"After training\" width=\"400\"\u003e |\n\n## 👥 Contributing\n\nContributions to this project are welcome! Please feel free to fork the repository, make your changes, and submit a pull request.\n\n## 📄 License\n\nThis project is open-sourced under the MIT License. See the [LICENSE](./docs/LICENSE) file for more information.\n\n## 🎉 Acknowledgments\n\nThis problem is an implementation of a problem presented in the course \"**CA 20581 Biological Computation**\" 2024a, taken at *the Open University of Israel*.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdor-sketch%2Fbinary-perceptron-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdor-sketch%2Fbinary-perceptron-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdor-sketch%2Fbinary-perceptron-simulator/lists"}