Loss Functions in RavML

Pranit Abhinav
RavenProtocol
Published in
4 min readSep 2, 2022

Loss functions are crucial for building your Machine learning algorithms as they measure the difference between the target output and the predicted output. Different use cases require different loss functions and it’s essential to use them.
RavML supports various loss functions which can be utilized while building your various machine learning and deep learning models in the Ravenverse. You can import these loss functions from the Ravml library which also has several ML algorithms which will support these loss functions.

Loss functions in the RavML library are written using the RavOP library for distributing the associated computations through the Ravenverse framework.
The loss functions return the output in the form of a Ravop tensor on which you can perform further operations using the tensor operations present in the Ravop library.

Supported Loss functions, their parameters, and return values are mentioned below.

  1. Mean absolute error
Mean Absolute error

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

from ravml.losses import mean_absolute_error

2. Mean squared error

Mean squared error

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

from ravml.losses import mean_squared_error

3. Root mean squared error

Root mean squared error

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

4. One hot cross entropy

One hot cross entropy is denoted by the following equation:

cross entropy loss

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

with_logit : Boolean value denoting whether to add a softmax function on the predicted values.

Returns:

Ravop Tensor

5. Kullback - Leibler divergence loss

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

6. Poisson Loss

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

7. Huber Loss

Huber loss

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

8. Categorical Hinge Loss

categorical hinge loss

Parameters :

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

9. Log loss

Log loss

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

10. Root Mean squared Log error

Root mean squared log error

y_true : array-like of shape (n_samples,) or (n_samples, n_outputs).Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs). Estimated target values.

Returns:

Ravop Tensor

Check RavML’s GitHub Repository to learn more about these functions and their usage. If you have some functions in mind that you wish to contribute, fork the repository and raise a pull request.

Join Raven Protocol’s Discord and telegram group to connect with the Ravenverse community and contribute to the GitHub repository.

--

--

Pranit Abhinav
RavenProtocol
0 Followers
Writer for

Machine Learning Engineer at raven protocol