Learn R Programming

partitionComparison (version 0.2.5)

entropy: Entropy

Description

Compute the Shannon entropy $$-\sum_{i} p_i \log_b p_i$$

Usage

entropy(x, log_base)

# S4 method for numeric,numeric entropy(x, log_base)

# S4 method for Partition,numeric entropy(x, log_base)

# S4 method for ANY,missing entropy(x, log_base = exp(1))

Arguments

x

A probability distribution

log_base

Optional base of the logarithm (default: \(e\))

Methods (by class)

  • x = Partition,log_base = numeric: Entropy of a partition represented by x

Hint

This method is used internally for measures based on information theory

Author

Fabian Ball fabian.ball@kit.edu

Examples

Run this code
isTRUE(all.equal(entropy(c(.5, .5)), log(2)))
isTRUE(all.equal(entropy(c(.5, .5), 2), 1))
isTRUE(all.equal(entropy(c(.5, .5), 4), .5))

# Entropy of a partition
isTRUE(all.equal(entropy(new("Partition", c(0, 0, 1, 1, 1))), entropy(c(2/5, 3/5))))

Run the code above in your browser using DataLab