> For the complete documentation index, see [llms.txt](https://ncxlib.gitbook.io/ncxlib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ncxlib.gitbook.io/ncxlib/getting-started/api-documentation/overview/lossfunction/binarycrossentropy.md).

# BinaryCrossEntropy

```python
class BinaryCrossEntropy(LossFunction):

    @staticmethod
    def compute_loss(y_true: np.ndarray, y_pred: np.ndarray):
        epsilon = 1e-12
        y_pred = np.clip(y_pred, epsilon, 1. - epsilon)
        return -np.sum(y_true * np.log(y_pred))

    @staticmethod
    def compute_gradient(y_true: np.ndarray, y_pred: np.ndarray):
        return (y_pred - y_true) / (y_pred * (1 - y_pred)) 
```
