Skip to main content

A Python library

Project description

adAI (adaiml-tools)

License: MIT Python Version Build Status Documentation Status

adAI (published as adaiml-tools) is a lightweight, modular, and high-performance machine learning library built entirely from scratch in Python using NumPy. Designed to make AI/ML components accessible, transparent, and easy to understand, adAI lets you construct anything from simple single-layer Perceptrons to Deep Multi-Layer Perceptrons (MLPs) and Convolutional Neural Networks (CNNs).


🚀 Key Features

  • Built from Scratch: Zero deep learning framework dependencies—only raw Python and NumPy.
  • Deep MLP & CNN Support: Full forward and backward propagation implementation for convolutional, dense, batch normalization, and dropout layers.
  • Advanced Optimizers: Includes SGD, Adam, AdamW, RAdam, and RAdamW.
  • Learning Rate Schedulers: Fine-tune training with StepLR, ExponentialLR, CosineAnnealingLR, and ReduceLROnPlateau.
  • A Rich Ecosystem of Components:
    • Activations: Sigmoid, ReLU, Tanh, Linear, Softmax.
    • Losses: Mean Squared Error (MSE), Mean Absolute Error (MAE), Binary Cross Entropy, Categorical Cross Entropy, Hinge Loss.
    • Layers: Dense, Conv2D, Flatten, MaxPool2D, BatchNorm, Dropout.

📦 Installation

To install the latest stable version from PyPI:

pip install adaiml-tools

For development and building from source:

git clone https://github.com/artheidendureza/adAI.git
cd adAI
pip install -e ".[dev]"

⚡ Quick Start

adAI provides intuitive generators (GeneratePerceptron, GenerateMLP, GenerateCNN) to instantiate pre-configured networks instantly.

1. Single Perceptron

import numpy as np
from adAI import GeneratePerceptron

# Instantiate a Perceptron for binary classification
perceptron = GeneratePerceptron(input_size=5, learning_rate=0.01, epochs=500)

# Generate synthetic train/val/test data
data = perceptron.generate_data(n_train=200, n_val=50, n_test=50)

# Train the model
history = perceptron.train(
    data['X_train'], data['y_train'],
    X_val=data['X_val'], y_val=data['y_val'],
    early_stopping=True, patience=10
)

# Evaluate and predict
metrics = perceptron.evaluate(data['X_test'], data['y_test'])
print(f"Test Accuracy: {metrics['accuracy']:.2%}")

2. Multi-Layer Perceptron (MLP)

import numpy as np
from adAI import GenerateMLP, StepLR

# Define a 3-layer MLP for classification
mlp = GenerateMLP(
    input_size=10,
    hidden_layers=[64, 32],
    output_size=3,
    learning_rate=0.01,
    epochs=100,
    activation="relu",
    output_activation="softmax",
    dropout=0.2
)

# Set up learning rate scheduling
scheduler = StepLR(step_size=30, gamma=0.5)

# Custom training loop with scheduling
for epoch in range(100):
    mlp.learning_rate = scheduler.get_lr(mlp.learning_rate, epoch)
    history = mlp.train(X_train, y_train, batch_size=32, verbose=False)

3. Convolutional Neural Network (CNN)

from adAI import GenerateCNN

# Build a CNN with two Conv layers and a Dense head
cnn = GenerateCNN(
    input_shape=(14, 14, 1), # Height, Width, Channels
    conv_layers=[(16, 3), (32, 3)], # (Filters, Kernel Size)
    dense_layers=[32],
    output_size=3,
    learning_rate=0.02,
    epochs=20,
    optimizer="adamw"
)

# Train the CNN
history = cnn.train(X_train, y_train, X_val=X_test, y_val=y_test, batch_size=16)

# Save/Load models easily
cnn.save("saved_cnn.npz")

🛠️ API & Configuration

Supported Optimizers

Specify any of the following string aliases or class instances:

  • "sgd" / SGD
  • "adam" / Adam
  • "adamw" / AdamW
  • "radam" / RAdam
  • "radamw" / RAdamW

Supported Loss Functions

  • "mse" / mean_squared_error
  • "mae" / mean_absolute_error
  • "binary_crossentropy" / binary_cross_entropy
  • "categorical_crossentropy" / categorical_cross_entropy
  • "hinge" / hinge_loss

Learning Rate Schedulers

  • ConstantLR
  • StepLR(step_size, gamma)
  • ExponentialLR(gamma)
  • CosineAnnealingLR(T_max, eta_min)
  • ReduceLROnPlateau(factor, patience, min_lr)

🧪 Testing

We use pytest for unit testing and verifying gradient computations. Run tests with coverage using:

# Run all tests
pytest

# Run tests with HTML coverage report
pytest --cov=src/adAI

🤝 Contributing

Contributions are welcome! Please read our CONTRIBUTING.md guide to learn how you can submit Pull Requests, report issues, or suggest new features.


📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adaiml_tools-0.1.1.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adaiml_tools-0.1.1-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file adaiml_tools-0.1.1.tar.gz.

File metadata

  • Download URL: adaiml_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for adaiml_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7ed9d66d27bdff4d1f7230196785bdd3e1ef08274bb27da37de6d9cd513b5b80
MD5 549ba730c33947fdf66a72f4f21e6e2a
BLAKE2b-256 e94e57a803b34c944f8edbbba8f557abf9d5c27bee6e5aaa2dbb2060d44829f3

See more details on using hashes here.

File details

Details for the file adaiml_tools-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: adaiml_tools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for adaiml_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6650ad33e8492033a5341855ada5d56134631e019e46d76edb87cfa467d8ce5
MD5 456fb9fa3b4dc3e121faabae7e6c0f2e
BLAKE2b-256 024dcf0c11a647394ad6a33fe9886b5781fee66361fcec2277eb25c6316780ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page