Learn R Programming

rinform (version 1.0.2)

relative_entropy: Relative Entropy

Description

Compute the average or local relative entropy between two time series treating each as observations from a distribution.

Usage

relative_entropy(xs, ys, local = FALSE)

Arguments

xs

Vector or matrix specifying one or more time series.

ys

Vector or matrix specifying one or more time series.

local

Boolean specifying whether to compute the local relative entropy.

Value

Numeric giving the average relative entropy or a vector giving the local relative entropy.

Examples

Run this code
# NOT RUN {
xs <- c(0, 1, 0, 0, 0, 0, 0, 0, 0, 1)
ys <- c(0, 1, 1, 1, 1, 0, 0, 1, 0, 0)
relative_entropy(xs, ys)       # 0.2780719
relative_entropy(ys, xs)       # 0.3219281

# [1]  0.6780719 -1.3219281
relative_entropy(xs, ys, local = TRUE)

xs <- c(0, 0, 0, 0)
ys <- c(0, 1, 1, 0)
relative_entropy(xs, ys)       # 1.0
relative_entropy(ys, xs)       # NaN
# }

Run the code above in your browser using DataLab