{"id":22839101,"url":"https://github.com/zichkoding/rustperceptron","last_synced_at":"2025-03-31T04:09:39.198Z","repository":{"id":267027653,"uuid":"900002436","full_name":"ZichKoding/RustPerceptron","owner":"ZichKoding","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-07T19:10:06.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T08:44:42.755Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/ZichKoding.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-12-07T15:48:21.000Z","updated_at":"2024-12-07T19:11:22.000Z","dependencies_parsed_at":"2024-12-07T20:18:29.686Z","dependency_job_id":"2ab17e4e-b8ce-404d-9aa1-9881bc550ea2","html_url":"https://github.com/ZichKoding/RustPerceptron","commit_stats":null,"previous_names":["zichkoding/rustperceptron"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZichKoding%2FRustPerceptron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZichKoding%2FRustPerceptron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZichKoding%2FRustPerceptron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZichKoding%2FRustPerceptron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZichKoding","download_url":"https://codeload.github.com/ZichKoding/RustPerceptron/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413232,"owners_count":20773053,"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":[],"created_at":"2024-12-13T00:09:57.047Z","updated_at":"2025-03-31T04:09:39.181Z","avatar_url":"https://github.com/ZichKoding.png","language":"Rust","readme":"# Rust Perceptron\n\n## Description\nThis project implements a simple perceptron in Rust, serving as a foundational introduction to neural networks and machine learning concepts. The perceptron takes multiple inputs, each associated with a weight, sums them along with a bias term, and then applies a step activation function to produce a binary output (0 or 1). Through repeated training cycles (epochs) and simple weight-adjustment rules, this perceptron learns to distinguish between two classes of input patterns.\n\nBy developing this perceptron from scratch, the project showcases an understanding of:\n- Basic neural network principles\n- Weight initialization and parameter tuning\n- Activation functions and decision boundaries\n- Supervised learning with simple datasets\n- Writing clean, documented, and testable Rust code\n\n#\n\n## Table of Contents\n* [Description](#description)\n* [Libraries](#libraries)\n* [Classes \u0026 Methods](#classes--methods)\n* [Functions](#functions)\n* [Test Cases](#test-cases)\n* [How to use](#how-to-use)\n* [When to use](#when-to-use)\n* [Skills utilized in this project](#skills-utilized-in-this-project)\n\n#\n\n## Libraries\n* **Standard Rust Library**  \n  Uses standard collections and I/O functionality. No external crates are required for the perceptron's core logic.\n\n#\n\n## Classes \u0026 Methods\n* **Perceptron**\n    * **new(num_inputs: usize, learning_rate: f64) -\u003e Perceptron**  \n      Creates and returns a new Perceptron instance with zero-initialized weights and bias.  \n      **Parameters:**  \n      - `num_inputs`: The number of input features.  \n      - `learning_rate`: The pace at which the perceptron updates weights.\n      \n    * **activation(\u0026self, sum: f64) -\u003e f64**  \n      Applies a step activation function. Returns 1.0 if `sum \u003e 0.0`, else 0.0.\n      \n    * **predict(\u0026self, inputs: \u0026[f64]) -\u003e f64**  \n      Computes the perceptron's output for given inputs by calculating the weighted sum plus bias, then applying the activation function.\n      \n    * **train(\u0026mut self, training_data: \u0026[(Vec\u003cf64\u003e, f64)], epochs: usize)**  \n      Trains the perceptron on the provided dataset. For each input-target pair and for a given number of epochs, it updates the weights and bias based on the prediction error.\n\n#\n\n## Functions\n* **main()**  \n  Demonstrates the usage of the Perceptron by:\n  - Initializing a perceptron for a binary classification task.\n  - Training the perceptron to learn an AND logic function using a small dataset.\n  - Evaluating the trained perceptron on both the training and some new/unseen data.\n\n#\n\n## Test Cases\n* **test_perceptron_new()**  \n  Ensures that a new Perceptron is created with the correct initial weights, bias, and learning rate.\n\n* **test_perceptron_activation_1()**  \n  Checks that the activation function returns 1.0 for positive input sums.\n\n* **test_perceptron_activation_0()**  \n  Checks that the activation function returns 0.0 for non-positive input sums.\n\n* **test_perceptron_predict_1()**  \n  Tests that the `predict` method can produce a 1.0 output given certain weights, bias, and inputs.\n\n* **test_perceptron_predict_0()**  \n  Tests that the `predict` method can produce a 0.0 output given certain weights, bias, and inputs.\n\n* **test_perceptron_train()**  \n  Verifies that after one epoch of training on a given dataset, the perceptron updates its weights (and possibly bias) correctly.\n\n* **test_perceptron_train_2()**  \n  Checks the perceptron’s learning behavior on a slightly different dataset to ensure weight and bias updates are consistent.\n\n#\n\n## How to use\n1. **Clone the Repository:**  \n   ```bash\n   git clone https://github.com/ZichKoding/RustPerceptron.git\n   cd RustPerceptron\n   ```\n\n2. **Build the Project:**  \n   ```bash\n   cargo build\n   ```\n   \n3. **Run the Application:**  \n   ```bash\n   cargo run\n   ```\n   This will train the perceptron and display the predictions for the training data as well as for some test inputs.\n\n4. **Run the Tests:**  \n   ```bash\n   cargo test\n   ```\n   This will execute the suite of unit tests to ensure the Perceptron logic works as expected.\n\n#\n\n## When to use\nUse this perceptron implementation when:\n- Learning the fundamentals of neural networks and machine learning.\n- Demonstrating binary classification tasks (e.g., logical AND, OR).\n- Experimenting with basic learning rules and parameter tuning.\n- Gaining familiarity with Rust’s ownership, memory safety, and type system in a simple AI context.\n- Creating a baseline model before experimenting with more complex architectures or libraries.\n\n#\n\n## Skills utilized in this project\n- **Rust Programming:** Safe, systems-level development with attention to memory and type safety.\n- **Machine Learning Fundamentals:** Understanding model initialization, forward pass, backpropagation-like weight updates, and convergence behavior.\n- **Algorithmic Thinking:** Implementing the perceptron learning rule and applying a binary decision boundary function.\n- **Software Testing:** Writing comprehensive unit tests to verify correctness, stability, and reliability.\n- **Code Documentation:** Using doc comments and README formatting to create clear, maintainable, and user-friendly documentation.\n- **Version Control \u0026 Project Structure:** Adhering to Cargo standards, organizing code in modules, and ensuring reproducible builds and tests.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzichkoding%2Frustperceptron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzichkoding%2Frustperceptron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzichkoding%2Frustperceptron/lists"}