卷积应该是可交换的——操作的顺序应该无关紧要。因此,此示例创建了三个 beta PDF,然后以三个不同的顺序对它们进行卷积。卷积 1 和 3 产生相同的结束函数。但是,卷积 2 会产生不同的结束函数。他们当然应该是一样的吗?
# Define beta distribution shape parameters.
s1a <- 3.52; s1b <- 65.35;
s2a <- 1.684; s2b <- 189.12;
s3a <- 5.696; s3b <- 32.34;
# Define quantiles and beta PDFs.
mQ <- matrix(data=seq(0,1,1/1000),ncol=1); # quantiles
mp1 <- matrix(dbeta(mQ,s1a,s1b),ncol=1);
mp2 <- matrix(dbeta(mQ,s2a,s2b),ncol=1);
mp3 <- matrix(dbeta(mQ,s3a,s3b),ncol=1);
# Convolution 1: mp1,mp2,mp3.
mC1 <- matrix(data=convolve(mp1,rev(mp2),type="open"),ncol=1L); # Convolve mp1, mp2 into MC1
mC1 <- matrix(data=mC1[seq(1, nrow(mC1), 2),],ncol=1L); # Halve the array to ensure consistency with quantiles.
mC1 <- 2L * mC1; # correct probailities for the halving above.
mC1 <- matrix(data=convolve(mC1,rev(mp3),type="open"),ncol=1L); # Convolve mC1, mp3
mC1 <- matrix(data=mC1[seq(1, nrow(mC1), 2),],ncol=1L);
mC1 <- 2L * mC1;
# Convolution 2: mp3,mp1,mp2.
mC2 <- matrix(data=convolve(mp3,rev(mp1),type="open"),ncol=1L); # Convolve mp3, mp2 into mC2
mC2 <- matrix(data=mC2[seq(1, nrow(mC2), 2),],ncol=1L);
mC2 <- 2L * mC2;
mC2 <- matrix(data=convolve(mC2,rev(mp2),type="open"),ncol=1L); # Convolve mC2, mp2
mC2 <- matrix(data=mC2[seq(1, nrow(mC2), 2),],ncol=1L);
mC2 <- 2L * mC2;
# Convolution 3: mp2,mp1,mp3.
mC3 <- matrix(data=convolve(mp2,rev(mp1),type="open"),ncol=1L); #Convolve mp2, mp1 into mC3
mC3 <- matrix(data=mC3[seq(1, nrow(mC3), 2),],ncol=1L);
mC3 <- 2L * mC3;
mC3 <- matrix(data=convolve(mC3,rev(mp3),type="open"),ncol=1L); # Convolve mC3, mp3
mC3 <- matrix(data=mC3[seq(1, nrow(mC3), 2),],ncol=1L);
mC3 <- 2L * mC3
# Plot them up.
maxP <- max(mC1,mC2,mC3);
plot(x=mQ,y=mC1,type="l",col="blue",lwd=2,ylim=c(0,maxP));
lines(x=mQ,y=mC2,col="black",lwd=2);
lines(x=mQ,y=mC3,col="red",lwd=2)