Learn R Programming

RateDistortion (version 1.01)

Sample: Generate random samples from a channel distribution.

Description

For a given information channel and input, draw random samples of the conditional probability distribution over the channel output.

Usage

Sample(channel, n, index, show.progress = FALSE)

Arguments

channel
An information channel, as returned by BlahutAlgorithm, FindOptimalChannel, or FindRate.
n
The number of random samples to generate.
index
The channel input, specified as its index in the source alphabet.
show.progress
Logical value. Show a progress bar during sampling?

Value

A list with two elements:
x
A matrix with n rows containing the channel input.
y
A matrix containing random samples of the channel output for the given index.

See Also

BlahutAlgorithm, FindOptimalChannel, FindRate

Examples

Run this code
# Define a discretized Gaussian information source
x <- seq(from = -10, to = 10, length.out = 100)
Px <- dnorm(x, mean = 0, sd = 3)
Px <- Px / sum(Px) # Ensure that probability sums to 1
y <- x # The destination alphabet is the same as the source

# Define a quadratic cost function
cost.function <- function(x, y) {
    (y - x)^2
}

# Slope of the rate-distortion curve
s <- -1

# Compute the rate-distortion value at the given point s
channel <- BlahutAlgorithm(x, Px, y, cost.function, s)

# Draw random samples from the output of this channel, for a given input
samples <- Sample(channel, 1000, 50, show.progress = TRUE)

# Plot a histogram of the output
hist(samples$y)

Run the code above in your browser using DataLab