From: Tristram Scott on 8 Feb 2010 09:26 darthshak <vishakadatta(a)gmail.com> wrote: > I was testing out the result that PDF of the sum of two RVs is the convolution of the individual RVs. I decided to test it with the Gaussian PDFs. > [snip] > > Where have I gone wrong? In a number of places, but I think the biggest mistake was to forget that normpdf takes a standard deviation, not a variance. I suggest you draw a plot. You might also find it easier to spot mistakes like this if you use parameters other than 1 for variances. >> x = linspace(-15,15,10000); >> dx = (x(end) - x(1)) / (length(x) - 1); >> f1 = normpdf(x,0,2); >> f2 = normpdf(x,0,3); >> f3c = conv(f1,f2) * dx; >> x3 = (2*x(1)):dx:(2*x(end)); >> f4 = normpdf(x3,0,sqrt(13)); >> plot(x3,f3c,x3,f4) >> sum((f3c-f4).^2)/2 ans = 3.7138e-12 >> As mentioned elsewhere in this thread, all of the vector returned from the conv is valid. The returned vector will be (length(f1)+length(f2)-1), spanning (min(x1) + min(x2)) to (max(x1) + max(x2)). The step size will be the same as it was for the input PDFs. To calculate the step size, use a denominator of (length(x) - 1). -- Dr Tristram J. Scott Energy Consultant
From: Tristram Scott on 8 Feb 2010 09:39 darthshak <vishakadatta(a)gmail.com> wrote: > What I mean by zero-padding is the extension scheme used by the conv > function when the boundaries of f1 are breached during convolution. The PDF of the sum is going to be wider than the two individual PDFs. >> min(randn(1,10000)) ans = -3.5562 >> min(sum(randn(2,10000))) ans = -5.7069 >> min(sum(randn(5,10000))) ans = -9.8824 The PDF returned from conv has expanded in length to cope with this. > > Also, my ultimate aim is to perform a convolution where the PDFs have > different means, so doing an ifft(fft(f1).^256) will be out of the > question. The point here is that you can stay on the frequency domain to do all of the multiplications, and then retunr to the time domain only at the end. Roughly twice as fast. And, if you stack your vectors nicely, you can calculate all of the ffts in one go by passing in a matrix. [snip] -- Dr Tristram J. Scott Energy Consultant
From: Matt J on 8 Feb 2010 10:14 > > Also, my ultimate aim is to perform a convolution where the PDFs have > > different means, so doing an ifft(fft(f1).^256) will be out of the > > question. ======== If the means are the only thing that is different among the PDFs, you could/should pre-center the PDFs so that they all correspond to i.i.d. variables. The book-keeping associated with the means can be done at the very end, i.e., by summing the means and shifting the final PDF accordingly.
From: Tristram Scott on 8 Feb 2010 12:06 Matt J <mattjacREMOVE(a)thisieee.spam> wrote: > >> > Also, my ultimate aim is to perform a convolution where the PDFs have >> > different means, so doing an ifft(fft(f1).^256) will be out of the >> > question. > ======== > > If the means are the only thing that is different among the PDFs, you > could/should pre-center the PDFs so that they all correspond to i.i.d. > variables. The book-keeping associated with the means can be done at the > very end, i.e., by summing the means and shifting the final PDF > accordingly. Good point. On that theme, since the ultimate aim is to calculate the PDF of the sum of 256 independent (are they?) distributions, the Central Limit Theorem should be quite applicable. Go for a Normal approximation with sum of means and sum of variances. -- Dr Tristram J. Scott Energy Consultant
From: darthshak on 8 Feb 2010 02:19 Thanks a lot Tristam! I overlooked the fact that the normpdf argument takes std. dev as an argument, and not variance. That said, thanks a lot for clearing up the stuff on the convolution. So essentially, if I am interested only in the convolution between min(x) and max(x), there is no harm in clipping right?
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: annotate grouped bar graph Next: importdata() inconsistency? |