Skip to content

Commit

Permalink
add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddeshSambasivam committed Jun 27, 2021
1 parent 0b61720 commit 4a0f746
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,51 @@ pip install --upgrade matterix
<h3 style="font-weight:bold">Example usage</h3>

```python
"""
Task: Simple model to predict if a given number is odd/even
"""

import numpy as np
from matterix import Tensor
import matterix.nn as nn
import matterix.functions as F
from matterix.loss import RMSE

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

class Model(nn.Module):
def __init__(self) -> None:
super().__init__()
self.w1 = Tensor(np.random.randn(1, 150), requires_grad=True)
self.b1 = Tensor(np.random.randn(1, 150), requires_grad=True)
self.w2 = Tensor(np.random.randn(150, 1), requires_grad=True)
self.b2 = Tensor(np.random.randn(1), requires_grad=True)

def forward(self, x) -> Tensor:
out_1 = (x @ self.w1) + self.b1
out_2 = F.sigmoid(out_1)
output = (out_2 @ self.w2) + self.b2

return output

model = Model()
optimizer = SGD(model, model.parameters())

EPOCHS = 100
t_bar = trange(EPOCHS)

for i in t_bar:

optimizer.zero_grad()

y_pred = model(x_train)

loss = RMSE(y_train, y_pred)

loss.backward()

optimizer.step()
t_bar.set_description("Epoch: %.0f Loss: %.5f" % (i, loss.data))
t_bar.refresh()

# TO BE ADDED
```

Take a look at `examples` for different examples
Expand All @@ -76,10 +113,18 @@ pytest -v
<h3 style="font-weight:bold" id="releases">Release history</h3>

- **0.1.0**

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

- **0.1.1**
- **ADD:** Optimizer: SGD
- **ADD:** Functions: Relu
- **ADD:** Loss functions: RMSE, MSETensor
- **ADD:** Module: For defining neural networks
- **FIX:** Floating point precision issue when calculating gradient

<h3 style="font-weight:bold" id="contributing">Contributing</h3>

1. Fork it
Expand Down
2 changes: 1 addition & 1 deletion matterix/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from numpy.random import logseries
from .tensor import Tensor

# TODO: RMSE, MAE, Binary cross-entropy, Categorical cross-entropy, kullback leibler divergence loss
# TODO: MAE, Binary cross-entropy, Categorical cross-entropy, kullback leibler divergence loss


def MSE(y_train: Tensor, y_pred: Tensor) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion matterix/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ArrayableType = Union[float, list, np.ndarray]
TensorableType = Union[float, np.ndarray, "Tensor"]

# TODO: randn, normal, randint, argmax
# TODO: randn, normal, randint, argmax, batching


def enforceTensor(_input: TensorableType) -> "Tensor":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="MatterIx",
version="0.1.0",
version="0.1.1",
author="Siddesh Sambasivam Suseela",
author_email="[email protected]",
description="Just another deep learning framework",
Expand Down

0 comments on commit 4a0f746

Please sign in to comment.