Learn R Programming

rinform (version 1.0.2)

cross_entropy: Cross Entropy

Description

Compute the cross entropy between the "true" and "unnatural" distributions p and q from associated time series ps and qs, respectively. Cross entropy<U+2019>s local variant is equivalent to the self-information of q, and as such is implemented by the local block entropy.

Usage

cross_entropy(ps, qs)

Arguments

ps

Vector specifying a time series drawn from the true distribution.

qs

Vector specifying a time series drawn from the unnatural distribution.

Value

Numeric giving the cross entropy.

Examples

Run this code
# NOT RUN {
ps <- c(0, 1, 1, 0, 1, 0, 0, 1, 0, 0)
qs <- c(0, 0, 0, 0, 0, 1, 1, 0, 0, 1)
cross_entropy(ps, qs)      # 1.003530
cross_entropy(qs, ps)      # 0.912454
# }

Run the code above in your browser using DataLab