|
"leo nidas" <bleonidas25@yahoo.gr> wrote in message <j11amh$o12$1@newscl02ah.mathworks.com>...
> Given three column vectors x,y,z I want to calculate the probabilities:
> P(X<Y<Z), P(X=Y<Z), P(X<Y=Z), P(X=Y=Z).
> ........
- - - - - - - - - - -
I claim that with large nx, ny, and nz, if you initially sort your three vectors, the total number of required floating point operations can be dramatically reduced in spite of the larger number of lines of code needed. Try the following for large size vectors and see if it isn't faster.
nx = length(x); ny = length(y); nz = length(z);
X = [sort(x);inf]; Y = [sort(y);inf]; Z = [sort(z);inf];
p1 = 0; p2 = 0; p3 = 0; p4 = 0;
ix = 1; xd = 0; iz = 1; zg = nz;
f = true;
for iy = 1:ny
Y0 = Y(iy);
if f
xe = 0;
while X(ix) <= Y0
xd = xd + 1;
if X(ix) == Y0, xe = xe + 1; end
ix = ix + 1;
end
ze = 0;
while Z(iz) <= Y0
zg = zg - 1;
if Z(iz) == Y0, ze = ze + 1; end
iz = iz + 1;
end
end
p1 = p1 + (xd-xe)*zg; p2 = p2 + xe*zg;
p3 = p3 + (xd-xe)*ze; p4 = p4 + xe*ze;
f = Y0 < Y(iy+1);
end
n = nx*ny*nz;
p1 = p1/n; p2 = p2/n; p3 = p3/n; p4 = p4/n;
Note: My p1, p2, p3, and p4 are your pith1, pith2, pith3, and pith4, resp.
Roger Stafford
|