The probability density function of the sum of a Gaussian variable and a uniform variable is the convolution of their densities. Let's compute that convolution symbolically, and compare it with a numerical approximation.
Constructing the symbolic convolution
First let's define the Gaussian density g and the uniform density U. These depend on some parameters.
I've defined the general uniform density in terms of a unit uniform density U1 defined on the interval [0, 1). (Maxima doesn't have a built-in notion of a unit step or boxcar function so I'll do this part myself.) I'll make U1 a simplifying function in order to prevent it from being evaluated except when the argument is a number.
Now let's construct the convolution integral. In general the convolution conv(f, g) = integral f(r - s) g(s) ds. I'll quote g and U so that they are not evaluated; that makes it easier to work with the integral in this case.
⇒ |
Simplifying and evaluating the convolution integral
The convolution integrand contains a function which is nonzero only on an interval, and constant there, so we can pull out the constant factor and change the limits of integration. I'll define a simplification rule for that.
First step toward evaluation is to let Maxima apply the simplification rule I just defined.
⇒ |
Terrific, now it's just a Gaussian density in the integrand. It's a noun (i.e., quoted function), so verbify it. Then 'integrate' can compute its integral.
⇒ |
Rearrange it somewhat, just to make it nicer to look at.
⇒ |
I'll pick out some typical values for the parameters, and bake them into a function to evaluate the convolution.
⇒ |
Let's make a plot. The convolution of a Gaussian and a uniform looks like a softened boxcar. Each end of the boxcar is a shifted and rescaled erf.
Numerical approximation to the convolution via FFT
Here I'll just paste in the discrete convolution via FFT which was the subject of a recent blog post.
Comparing the symbolic and numerical results
I'll create a grid of values and evaluate the Gaussian and uniform densities on the grid. The parameters for the densities are the same as what were baked into conv_symbolic.
Then I'll compute the convolution of those discretized densities.
Finally I'll plot both the discretized approximation and the symbolic density. The agreement is pretty close. That's comforting.
No comments:
Post a Comment