Skip to main content

A Neural Network Library

Project description

Madrin

A cute Neural Network library with Keras-like API. Build for fun and educational purposes. Because the code is so simple, it is very easy to change to your needs. Still under active development.

Dependencies

Installation

pip install madrin

Demo

Create a neural network:
You can create a Neural Network by passing a list of layers to the Network constructor.
Currently it supports the following layers:

Linear(no_of_neurons, input_size)
Relu()
LeakyRelu()
Sigmoid()
Tanh()
Softmax()

import numpy as np

# Import the necessary classes from the madrin library
from madrin import Linear, Sigmoid, Relu, LeakyRelu, Tanh, Softmax, Network

# Generate some dummy data for training
np.random.seed(0)  # For reproducibility
X_train = np.random.randn(1000, 3)  # 1000 samples, 3 features each
y_train = np.random.randint(0, 3, 1000)  # 1000 labels (3 classes)

# Create the network
model = Network([
    Linear(no_of_neurons=5, input_size=3),  # First layer: 3 input features, 5 neurons
    Relu(),  # ReLU activation
    Linear(no_of_neurons=3, input_size=5),  # Second layer: 5 input features, 3 neurons (output layer)
    Softmax()  # Softmax activation for multi-class classification
])

# See the total number of trainable parameters(i.e., weights and biases)
print(model.n_parameters())

# Compile the network with loss function and learning rate
model.compile(loss='categorical_crossentropy', lr=0.01)

# Train the network
model.fit(X_train, y_train, epochs=1000, batch_size=100, track_loss = True)

# Make predictions
predictions = model.forward(X_train)

# Print the predictions
print(predictions)

# Print the training costs
import matplotlib.pyplot as plt
plt.plot(np.arange(len(model.costs)),model.costs)
plt.xlabel('Epochs')
plt.ylabel('Cost')
plt.title('Training Cost Over Time')
plt.show()

Contributing

Contributions are welcome! Please open an issue or submit a pull request on Github.

License

Madrin is released under the MIT License.

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

madrin-1.0.0.tar.gz (230.3 kB view details)

Uploaded Source

Built Distribution

madrin-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file madrin-1.0.0.tar.gz.

File metadata

  • Download URL: madrin-1.0.0.tar.gz
  • Upload date:
  • Size: 230.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for madrin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aa55004da4cf733aced52007573d0574f205acd17ee5365fea0a21c3a2057722
MD5 5914d4702d767e2156c723a525f732a0
BLAKE2b-256 7dd22de80d76dc2802d21a3e2a05c06f91411abe0096256f336b396df8fafc10

See more details on using hashes here.

File details

Details for the file madrin-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: madrin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for madrin-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfe353d8d6f985c914401764e9254e0b52b46f41d39e725cb09efd09c0f8c6d5
MD5 92c2307f8e13bfe8398e8ff691caf160
BLAKE2b-256 d87bea879ac44aee1a24b6b8aa994fd487dd3cbc88aedc944a0f7394176eedb3

See more details on using hashes here.

Supported by

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