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 に答える