0

I am doing calculations that involves too many for-loops. I would appreciate any idea that could eliminates some of the loops to make the algorithm more efficient. Here is the mathematical expression I want to get: A discrete distribution of random variable Y.

Pr(Y=y )=
∑_Pr(Z=z) ∙∑_Pr((X=x) ∑_Pr(W=w) ∙∑_Pr(R=r│W=w) ∙Pr(S=z+y-x-r|W=w) Y,Z,X,W,R,S are discrete random variable, they are dependent. I know the expression for each term, but there are just probability calculations – not close-form distributions.

    array Y[max_Y+1];  % store the distribution of Y
temp1=0, temp2=0, temp3=0, temp4=0; % summation for partial distributions
for y = 0 max_Y
    temp1=0;
    for z = 0 : 5- y
        temp2=0;
        for x=0:5
            temp3=0;
            for w=0:5
                temp4=0
                for r=0:w
                    temp4=temp4+Pr(R=r│W=w)∙Pr(S=z+y-x-r|W=w);
                    end
                temp3=temp3+temp4*Pr(W=w);
                end
            temp2= temp2+temp3*Pr(X=x);
            end
       temp1=temp1+temp2* P(Z=z);
       end
   Y[y]=temp1;
   end

Thanks a lot! Ester

4

1 回答 1

0

从我在每次迭代中注意到的情况来看,只有该术语Pr(S=z+y-x-r|W=w) & Pr(Z=z)取决于您的函数输入变量 Y,因此可以使用单独的 for 循环预先计算所有其他值,然后只计算Pr(S=z+y-x-r|W=w)*Pr(Z=z)*precomputed

于 2013-11-14T07:49:35.163 回答