diff --git a/README.md b/README.md index d0cd228..ff5c790 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,51 @@ pip install --upgrade matterix

Example usage

```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 @@ -76,10 +113,18 @@ pytest -v

Release history

- **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 +

Contributing

1. Fork it diff --git a/matterix/loss.py b/matterix/loss.py index 5c57c38..5e546ed 100644 --- a/matterix/loss.py +++ b/matterix/loss.py @@ -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: diff --git a/matterix/tensor.py b/matterix/tensor.py index d8c4c3c..e32fe8e 100644 --- a/matterix/tensor.py +++ b/matterix/tensor.py @@ -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": diff --git a/setup.py b/setup.py index efed795..6da424b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="MatterIx", - version="0.1.0", + version="0.1.1", author="Siddesh Sambasivam Suseela", author_email="plutocrat45@gmail.com", description="Just another deep learning framework",