Skip to content

Commit d691538

Browse files
authored
Merge pull request #1 from harrismirza/master
Update categorical_test.py
2 parents eaf626a + 45347a7 commit d691538

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tensorflow_probability/python/distributions/categorical_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,19 @@ def testEntropyGradient(self):
338338
res["categorical_entropy"])
339339
self.assertAllClose(res["true_entropy_g"],
340340
res["categorical_entropy_g"])
341+
342+
343+
def testEntropyWithZeroProbabilities(self):
344+
probs = [[0, 0.5, 0.5], [0, 1, 0]]
345+
dist = categorical.Categorical(probs=probs)
346+
dist_entropy = dist.entropy()
347+
348+
with self.cached_session():
349+
self.assertAllClose(dist_entropy.eval(),
350+
[
351+
-(0.5*np.log(0.5) + 0.5*np.log(0.5)),
352+
-(np.log(1))
353+
])
341354

342355
def testSample(self):
343356
with self.cached_session():

0 commit comments

Comments
 (0)