A light-weight Artificial Neural Network implementation from scratch
Project description
Annpy 🧠
Annpy is a lightweight, efficient, and fully transparent Artificial Neural Network (ANN) implementation built from scratch using NumPy.
While many frameworks are "black boxes," Annpy is designed to be customizable and clear, making it perfect for educational purposes, lightweight integrations, and fast prototyping.
✨ Key Features
- 🎯 Total Architectural Flexibility:
- Any Input Size: Configure the network to accept any number of input features—from 2 to 2,000+.
- Customizable Hidden Layer: You define the number of neurons in the hidden layer to perfectly balance learning power and processing speed.
- 🧠 From-Scratch Implementation: No heavy dependencies like PyTorch or TensorFlow. Just pure Python and NumPy logic.
- ⚡ Built-in Preprocessing: Features automated data normalization (scaling to [0, 1]) and shuffling to ensure your model trains effectively out of the box.
- 🛠️ Developer Friendly: Clean, documented code that is easy to read, extend, and debug.
🚀 Installation
Install Annpy directly via pip:
pip install annpy-neopydev5454
🛠️ Quick Start: The Iris Dataset Example
In this example, we configure Annpy to classify a dataset of 20 samples. The network is set to receive 4 inputs and uses a hidden layer of 10 neurons.
import numpy as np
from annpy_neopydev5454 import ANN
# 1. Prepare synthetic data (20 samples, 4 features each)
X = np.array([
[5.1, 3.5, 1.4, 0.2], [4.9, 3.0, 1.4, 0.2], [7.0, 3.2, 4.7, 1.4], [6.4, 3.2, 4.5, 1.5],
[5.8, 2.7, 4.1, 1.0], [5.1, 2.5, 3.0, 1.1], [6.7, 3.1, 5.6, 2.4], [6.3, 2.3, 4.4, 1.3],
[5.0, 3.4, 1.5, 0.2], [5.9, 3.0, 5.1, 1.8], [5.2, 3.5, 1.5, 0.2], [4.7, 3.2, 1.3, 0.2],
[6.9, 3.1, 4.9, 1.5], [5.4, 3.9, 1.7, 0.4], [6.5, 2.8, 4.6, 1.5], [5.7, 2.8, 4.5, 1.3],
[6.3, 3.3, 4.7, 1.6], [4.6, 3.1, 1.5, 0.2], [5.0, 3.6, 1.4, 0.2], [6.1, 2.8, 4.0, 1.3]
])
# 2. Prepare target labels (Must match X length)
y = np.array([0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1])
# 3. Initialize the model
# input_size=4 (features), hidden_layer_size=10 (neurons)
model = ANN(input_size=4, hidden_layer_size=10)
# 4. Train the model
# X: The training features matrix
# y: The target labels (must be the same length as X)
# learning_rate: The step size for weight updates
# epochs: Number of times to iterate over the entire dataset
model.train(X, y, learning_rate=0.1, epochs=1500)
# 5. Predict a new sample
new_sample = np.array([5.0, 3.6, 1.4, 0.3])
prediction = model.predict(new_sample)
print(f"Prediction: {prediction}")
📊 How it Works
Annpy implements a Multi-Layer Perceptron (MLP) with one hidden layer:
- Dynamic Weights: Initialized based on your
input_sizeandhidden_layer_size. - Forward Pass: Uses the Sigmoid activation function to compute the output.
- Backpropagation: Updates weights using Gradient Descent.
- Auto-Normalization: Automatically scales input data to [0, 1] for better convergence.
📜 License
Distributed under the MIT License. See the LICENSE file for more information.
Created with ❤️ by Nehorai Yosef
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file annpy_neopydev5454-0.1.1.tar.gz.
File metadata
- Download URL: annpy_neopydev5454-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5345e24ed13d64401129b865deac19c2cf587b84ab20f78ea26a432f4030fea
|
|
| MD5 |
c6ecbe83803a17c773d53dce4e70a312
|
|
| BLAKE2b-256 |
3cbf40be921dff41795281a7434392d470c7b13ff335b086a993992e6e1daa45
|
File details
Details for the file annpy_neopydev5454-0.1.1-py3-none-any.whl.
File metadata
- Download URL: annpy_neopydev5454-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4727ede3ffce0f790bbce6b714e0fa53c04b5cfe5761e55571dc84b212b1341a
|
|
| MD5 |
47fa023a06acbab70efe5d2778face39
|
|
| BLAKE2b-256 |
85c02255f911f7b99aca39914d5c3a05422e0cc1b9ec414016bba0fc75cd723f
|