Skip to content

Instantly share code, notes, and snippets.

@jainakshansh
Created December 25, 2018 05:31
Show Gist options
  • Save jainakshansh/204d2b6a10041cf491edaaa0d36de3ba to your computer and use it in GitHub Desktop.
Save jainakshansh/204d2b6a10041cf491edaaa0d36de3ba to your computer and use it in GitHub Desktop.
The Cross-Entropy Algorithm - Facebook Udacity PyTorch Challenge
import numpy as np
def cross_entropy(Y, P):
Y = np.float_(Y)
P = np.float_(P)
return -np.sum(Y * np.log(P) + (1 - Y) * np.log(1 - P))
Y = [1, 0, 1, 1]
P = [0.4, 0.6, 0.1, 0.5]
print(cross_entropy(Y, P))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment