Learn R Programming

rinform (version 1.0.2)

shannon_cross_entropy: Shannon Cross Entropy

Description

Compute the base-b Shannon cross entropy between a true distribution p and an unnatural distribution q.

Usage

shannon_cross_entropy(p, q, b = 2)

Arguments

p

Dist specifying the true distribution.

q

Dist specifying the unnatural distribution.

b

Numeric giving the base of the logarithm.

Value

Numeric giving the Shannon cross entropy.

Examples

Run this code
# NOT RUN {
p <- Dist(c(1, 0, 0))
q <- Dist(c(2, 1, 1))
shannon_cross_entropy(p, q)               # 1.0000000
shannon_cross_entropy(q, p)               # Inf
shannon_cross_entropy(p, q, b = 3)        # 0.6309298
shannon_cross_entropy(q, p, b = 3)        # Inf


# }

Run the code above in your browser using DataLab