Sum of frequency distributions vs convolutions

67 Views Asked by At

From my understanding, the sum of independent random variables will be the same as the convolution of the input distributions.

However, when experimenting with it, I see the distribution of the sum of the variables do not match that of the convolution result.

For example: The sum of two independent random variables from uniform distribution should follow triangular distribution. But convolution does not. I tried using numpy.convolve.

Am I missing something?

import numpy as np
import matplotlib.pyplot as plt

# Generate two uniform distributions
uniform1 = np.random.uniform(0, 1, 100000)
uniform2 = np.random.uniform(0, 1, 100000)

# Convolution of two uniform distributions
convolution_result = np.convolve(uniform1, uniform2, mode='full')

# Plot the histograms
plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)
plt.hist(uniform1 + uniform2, bins=50, density=True, alpha=0.7)
plt.title('Sum of Uniform Distributions')

plt.subplot(1, 2, 2)
plt.hist(convolution_result, bins=50, density=True, alpha=0.7)
plt.title('Convolution of Uniform Distributions')

plt.show()

enter image description here

Context:

I have a state transition matrix (probabilities), where each transition is associated with rewards/cost like say latency, price, etc. Instead of a constant latency, each step can be associated with a probability distribution for the latency.

For now, assume there is a single starting state and a single final state, I want to find the distribution of the total costs.

In practice, there will a large number of transitions with different probabilities for each transition and the cost/rewards could have arbitrary frequency distributions and I should be able to find the histogram of the total cost/rewards.

1

There are 1 best solutions below

5
On

You're trying to prove that the sum of two random variables $X$ and $Y$ has the same distribution as the convolution (whatever that may be) of $X$ and $Y$.

But that's not true. Instead $X+Y$ has as its distribution the convolution of the distributions of $X$ and $Y$. If $X$ and $Y$ have densities, $X+Y$ has as density the convolution of the densities of $X$ and $Y$.

To verify this in your example, you only need the first plot plus the knowledge or some kind of verification that the plotted diagonal function is the convolution of the piecewise constant functions that are the densities of the uniform distributions.