根据 MA​​TLAB 中预先指定的规则,从两个现有概率矩阵创建新的概率矩阵

发布于 2025-01-05 17:06:49 字数 1094 浏览 6 评论 0原文

我的 MATLAB 代码有问题。首先让我对这个问题做一些解释。我有两个矩阵代表事件特定结果的概率。第一个称为 DemandProbabilityMatrix 或简称 DemandP。条目 (i,j) 显示项目 i 被需求 j 次的概率。类似地,我们有一个ReturnProbabilityMatrix,即ReturnP。 (i,j) 类型的元素存储项目 i 被返回 j 次的概率。 我们想要计算这两个矩阵的净需求概率。举个例子:

需求P=[ .4 .5 .1] 返回P=[ .2 .3 .5]

在这种情况下,我们有 1 件物品,并且在给定的概率下可以要求或返回 1,2 或 3 次。更具体地说,该物品仅被需求一次,概率为 0.4 。

然后我们需要计算净需求。在这种情况下,净需求可以是 -2、-1、0、1 或 2。例如,为了获得 -1 的净需求,我们可以要求 1 并返回 2,或者要求 2 并返回的 3. 因此我们有

净需求P(1,2)=需求P(1,1)*收益P(1,2)+需求P(1,2)*收益P(1,3)。

因此 NetDemandP 应如下所示:

NetDemandP=[.20 .37 .28 .13 .02]

我可以使用嵌套 for 循环来完成此操作,但我正在尝试想出一种更快的方法。如果它有帮助,我有以下 for 循环解决方案,其中 I 表示 ReturnPDemandP 中的行数, J+1 表示这些矩阵中的列数。

NetDemandP=zeros(I,2*J+1);
    for i=1:I
        for j=1:J+1
            for k=1:J+1
                NetDemandP(i,j-k+J+1)=NetDemandP(i,j-k+J+1)+DemandP(i,j)*ReturnP(i,k);
            end
        end
    end

提前致谢

I have a problem in my MATLAB code. Let me first give you some explanation about the issue. I have two matrices which represent probabilities of specific outcomes of events. The first one is called DemandProbabilityMatrix or in short DemandP. Entry (i,j) shows the probability that item i is demanded j many times. Similarly, we have a ReturnProbabilityMatrix, i.e. ReturnP. An element of type (i,j) stores the probability that item i is returned j many times.
We want to compute the net demand probability out of these two matrices. For an example:

DemandP=[ .4 .5 .1]
ReturnP=[ .2 .3 .5]

In this case we have 1 item and it can be demanded or returned either 1,2 or 3 times with the given probabilities. To be more specific That item will be demanded just for once with probability .4 .

Then we need to compute the net demand. In this case, net demand can be -2,-1,0,1 or 2. For instance in order to get a net demand of -1 we can either have a demand of 1 and return of 2 or demand of 2 and return of 3. Thus we have

NetDemandP(1,2)= DemandP(1,1)*ReturnP(1,2)+DemandP(1,2)*ReturnP(1,3).

Thus the NetDemandP should look as:

NetDemandP=[.20 .37 .28 .13 .02]

I can do this with nested for loops but I'm trying to come up with a faster way. In case it helps I have the following for loops solutions where I denotes the number of rows in ReturnP and DemandP, J+1 denotes the number of columns in those matrices.

NetDemandP=zeros(I,2*J+1);
    for i=1:I
        for j=1:J+1
            for k=1:J+1
                NetDemandP(i,j-k+J+1)=NetDemandP(i,j-k+J+1)+DemandP(i,j)*ReturnP(i,k);
            end
        end
    end

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2025-01-12 17:06:49

您想要的是概率密度函数的卷积。或者,更具体地说,您希望将需求密度与返回密度的反向进行卷积。这在 Matlab 中很容易实现。例如:

DemandP = [.4 .5 .1];
ReturnP = [.2 .3 .5];
NetDemandP = conv(DemandP,fliplr(ReturnP))

如果您有矩阵而不是向量,则只需迭代行:

for i = 1:size(DemandP,1)
    NetDemandP(i,:) = conv(DemandP(i,:),fliplr(ReturnP(i,:)))
end

What you want is the convolution of your probability density functions. Or, more specifically, you want the convolution of the demand density with the reverse of the return density. This is easily achieved in Matlab. For example:

DemandP = [.4 .5 .1];
ReturnP = [.2 .3 .5];
NetDemandP = conv(DemandP,fliplr(ReturnP))

If you have matrices instead of vectors, then just iterate through the rows:

for i = 1:size(DemandP,1)
    NetDemandP(i,:) = conv(DemandP(i,:),fliplr(ReturnP(i,:)))
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文