-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Mateusmsouza/dev
Dev
- Loading branch information
Showing
12 changed files
with
167 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<a id="nn.loss"></a> | ||
|
||
# nn.loss | ||
|
||
<a id="nn.loss.MeanSquaredError"></a> | ||
|
||
## MeanSquaredError Objects | ||
|
||
```python | ||
class MeanSquaredError() | ||
``` | ||
|
||
Class to compute the Mean Squared Error (MSE) and its gradient. | ||
|
||
<a id="nn.loss.MeanSquaredError.forward"></a> | ||
|
||
#### forward | ||
|
||
```python | ||
def forward(y_true: np.ndarray, y_pred: np.ndarray) -> np.ndarray | ||
``` | ||
|
||
Compute the Mean Squared Error between true and predicted values. | ||
|
||
**Arguments**: | ||
|
||
- `y_true` _np.ndarray_ - True values. | ||
- `y_pred` _np.ndarray_ - Predicted values. | ||
|
||
|
||
**Returns**: | ||
|
||
- `np.ndarray` - The mean squared error. | ||
|
||
|
||
**Raises**: | ||
|
||
- `ValueError` - If y_true and y_pred do not have the same shape. | ||
|
||
<a id="nn.loss.MeanSquaredError.backward"></a> | ||
|
||
#### backward | ||
|
||
```python | ||
def backward(y_true: np.ndarray, y_pred: np.ndarray) -> np.ndarray | ||
``` | ||
|
||
Compute the gradient of the Mean Squared Error with respect to the predicted values. | ||
|
||
**Arguments**: | ||
|
||
- `y_true` _np.ndarray_ - True values. | ||
- `y_pred` _np.ndarray_ - Predicted values. | ||
|
||
|
||
**Returns**: | ||
|
||
- `np.ndarray` - The gradient of the loss with respect to y_pred. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Installation | ||
|
||
## Introduction | ||
|
||
`liltorch` is a library for building and training machine learning models. This tutorial will guide you through the process of installing `liltorch` from PyPI, the Python Package Index. | ||
|
||
## Prerequisites | ||
|
||
Before installing `liltorch`, ensure that you have the following prerequisites: | ||
|
||
- Python 3.6 or higher | ||
- pip (Python package installer) | ||
|
||
You can verify your Python and pip versions by running the following commands in your terminal or command prompt: | ||
|
||
```sh | ||
python --version | ||
pip --version | ||
``` | ||
|
||
## Installation Steps | ||
Open the terminal and type: | ||
```sh | ||
pip install --upgrade pip | ||
pip install liltorch | ||
``` | ||
Check installation: | ||
```sh | ||
import liltorch | ||
print("liltorch version:", liltorch.__version__) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
site_name: LilTorch | ||
site_name: LilTorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
import numpy as np | ||
|
||
class MeanSquaredError: | ||
""" | ||
Class to compute the Mean Squared Error (MSE) and its gradient. | ||
""" | ||
|
||
def mse_loss(y_true: np.ndarray, y_pred: np.ndarray): | ||
if y_true.shape != y_pred.shape: | ||
raise ValueError("y_true and y_pred must have the same length.") | ||
return np.mean(np.power(y_true-y_pred, 2)); | ||
def forward(self, y_true: np.ndarray, y_pred: np.ndarray) -> np.ndarray: | ||
""" | ||
Compute the Mean Squared Error between true and predicted values. | ||
def mse_grad(y_true, y_pred): | ||
return 2*(y_pred-y_true)/y_true.size; | ||
Parameters: | ||
y_true (np.ndarray): True values. | ||
y_pred (np.ndarray): Predicted values. | ||
Returns: | ||
np.ndarray: The mean squared error. | ||
Raises: | ||
ValueError: If y_true and y_pred do not have the same shape. | ||
""" | ||
if y_true.shape != y_pred.shape: | ||
raise ValueError("y_true and y_pred must have the same length.") | ||
return np.mean(np.power(y_true - y_pred, 2)) | ||
|
||
def backward(self, y_true: np.ndarray, y_pred: np.ndarray) -> np.ndarray: | ||
""" | ||
Compute the gradient of the Mean Squared Error with respect to the predicted values. | ||
Parameters: | ||
y_true (np.ndarray): True values. | ||
y_pred (np.ndarray): Predicted values. | ||
Returns: | ||
np.ndarray: The gradient of the loss with respect to y_pred. | ||
""" | ||
return 2 * (y_pred - y_true) / y_true.size |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest==8.2.2 | ||
mkdocs==1.6.0 | ||
coverage==7.5.4 | ||
Sphinx==7.3.7 | ||
sphinx-autodoc-typehints==2.2.2 | ||
sphinx-markdown-builder==0.6.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters