Skip to main content

Just another deep learning framework

Project description

PyPI - License PyPI

ReleasesContributingFeatures

MatterIx is a simple deep learning framework built to understand the fundamental concepts such as autodiff, optimizers, loss functions from a first principle method.

Features

MatterIx provide features such as automatic differntiation (autodiff) to compute gradients, optimizers, loss functions, basic modules to create your own neural networks. The core value of matterix is that it is a distilled version of pytorch so it is easier to understand what is happening under the hood.

At its core, matterix uses reverse-mode autodiff to compute gradients. All the computations are representated as a graph of tensors with each tensor holding a reference to a function which can compute the local gradient for the tensor. The calculation of the partial derivative for each node is completed when the entire graph is traversed.

Installation

a. Install it from github
# Install either with option-1 or option-2

# Option-1
pip install git+https://github.com/SiddeshSambasivam/MatterIx.git#egg=MatterIx

# Option-2
git clone https://github.com/SiddeshSambasivam/MatterIx.git

python setup.py install

b. Install from PyPI

# Install directly from PyPI repository
pip install --upgrade matterix

Example usage

"""
Task: Simple model to predict if a given number is odd/even
"""
import numpy as np
from matterix import Tensor
import matterix.functions as F

# Prepare training data
x = [[i] for i in range(1, 200)]
y = [[0] if i % 2 == 0 else [1] for i in range(1, 200)]

x_train, y_train = Tensor(x[:150]), Tensor(y[:150])
x_test, y_test = Tensor(x[150:]), Tensor(y[150:])

w1 = Tensor(np.random.randn(1, 150), requires_grad=True)
b1 = Tensor(np.random.randn(1, 150), requires_grad=True)
w2 = Tensor(np.random.randn(150, 1), requires_grad=True)


def model(x):

    out_1 = (x @ w1) + b1
    out_2 = F.sigmoid(out_1)
    output = out_2 @ w2

    return output


for i in range(100):

    y_pred = model(x_train)
    loss = y_train - y_pred

    mse_loss = (loss * loss).sum() * (1.0 / (loss.numel()))

    mse_loss.backward()

    w1 -= w1.grad * 0.001
    b1 -= b1.grad * 0.001
    w2 -= w2.grad * 0.001

    w1.zero_grad()
    w2.zero_grad()
    b1.zero_grad()

    print(f"Epoch: {i} Loss: {mse_loss.data}")

Take a look at examples for different examples

Development setup

Install the necessary dependecies in a seperate virtual environment

# Create a virtual environment during development to avoid dependency issues
pip install -r requirements.txt

# Before submitting a PR, run the unittests locally
pytest -v

Release history

  • 0.1.0
    • First stable release
    • ADD: Tensor, tensor operations, sigmoid functions
    • FIX: Inaccuracies with gradient computation

Contributing

  1. Fork it

  2. Create your feature branch

    git checkout -b feature/new_feature
    
  3. Commit your changes

    git commit -m 'add new feature'
    
  4. Push to the branch

    git push origin feature/new_feature
    
  5. Create a new pull request (PR)


Siddesh Sambasivam Suseela - @ssiddesh45 - plutocrat45@gmail.com

Distributed under the MIT license. See LICENSE for more information.

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

MatterIx-0.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

MatterIx-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file MatterIx-0.1.0.tar.gz.

File metadata

  • Download URL: MatterIx-0.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.0

File hashes

Hashes for MatterIx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3d20b4d9f4b9d52530f9f69236ec6bbdc9267fd37c6de824ceb3165004bde80
MD5 9d791add327a3d21d3de00bf74a4fd00
BLAKE2b-256 f20cb43c056f4c8e39e647c87b7924f1a8d4fab93c63289fb34d5dddaa9624ad

See more details on using hashes here.

File details

Details for the file MatterIx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: MatterIx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.0

File hashes

Hashes for MatterIx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b75e243e79c3140915e238323ff80a3e5cc8fafa4b0323150c84e9516c39dbc4
MD5 e836db5d8114d80d7bd021532da75087
BLAKE2b-256 6ff4270b637e7b0c4b97b4dcba0ce9ed8e66365d5c4ac8dffdaf602541d2e4f6

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