1

卷积应该是可交换的——操作的顺序应该无关紧要。因此,此示例创建了三个 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)
4

1 回答 1

3

您的代码设置方式,“卷积和子样本”运算符对于不同长度的向量是不可交换的

cc <- function(x,y) convolve(x, rev(y), type="open")
cch <- function(x,y) cc(x,y)[seq(1,length(x),by=2)]*2

(看起来您可能来自 Matlab;R 将向量视为适当的行/列向量很草率,因此您可以跳过所有将结果转换回矩阵的东西......)

set.seed(101); x <- rnorm(20); y <- rnorm(40)
all.equal(cc(x,y), cc(y,x))   ## TRUE
all.equal(cch(x,y),cch(y,x))  ## lengths differ

的结果cch(x,y)比 长z,所以我们有一个不等长向量的卷积,得到的算子不再可交换。

于 2020-10-31T23:25:57.100 回答