From: Roger Stafford on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i24i60$gfp$1(a)fred.mathworks.com>...
> Assuming he was, though, I'm still wondering if the following would do it. For larger numbers of variables, it would be good to have a way of doing this without using
> sort().
>
> A=cumsum(rand(1,6)); A=A/sum(A); A(end)=[];
- - - - - - - - -
Matt, I'm in agreement with John and Walter on this. Your two solutions are not good ones to give as an answer even if Jay did not give specific details as to the desired distribution.

For example in your second method with five variables it is impossible for the fifth one to exceed 1/2 even though doing so would easily be compatible with Jay's constraint.

However, just as important, the distribution within the domain which is used is exceedingly non-uniform. If you were to show Jay a plot for the two variable case, I am sure he would not be happy with it. The area used is actually less than half of that which would be allowed by the constraint, with everything having to lie below the line 3*a+2*b = 1 and the density drops off to zero at the [0,0] corner.

Roger Stafford
From: Matt J on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i24l9s$auq$1(a)fred.mathworks.com>...

> I don't even see the sort as more complex, nor does
> MATLAB. Try this:
===========

That's only because you're working in 2 dimensions. In higher dimensions, complexity theory of sorting vs. summation gaurantees that sorting will do worse. Try this modification:


n = 100;
data=rand(n,60000);
tic
A = cumsum(data,2);
A = bsxfun(@rdivide,A,sum(A,2));
A(:,end) = [];
toc
%Elapsed time is 0.141225 seconds.


data=rand(n,59999);
tic
B = sort(data,2);
toc
%Elapsed time is 0.493895 seconds.
From: Matt J on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i24nq0$oat$1(a)fred.mathworks.com>...

> - - - - - - - - -
> Matt, I'm in agreement with John and Walter on this. Your two solutions are not good ones to give as an answer even if Jay did not give specific details as to the desired distribution.
>
> For example in your second method with five variables it is impossible for the fifth one to exceed 1/2 even though doing so would easily be compatible with Jay's constraint.
=========

Roger- You're right. I had a mistake. What I really meant to give was this:

A=cumsum(rand(1,6)); A=A/A(end); A(end)=[];

I reran John's 2D test on this and find that it covers the correct triangular area, though slightly less uniformly than the sorting method.

Again, though, for me, this was all just an exercise in seeing if we could get something nearly as good using cheaper summations instead of sorting.
From: Roger Stafford on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i24oic$env$1(a)fred.mathworks.com>...
> "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i24l9s$auq$1(a)fred.mathworks.com>...
>
> > I don't even see the sort as more complex, nor does
> > MATLAB. Try this:
> ===========
>
> That's only because you're working in 2 dimensions. In higher dimensions, complexity theory of sorting vs. summation gaurantees that sorting will do worse. Try this modification:
>
>
> n = 100;
> data=rand(n,60000);
> tic
> A = cumsum(data,2);
> A = bsxfun(@rdivide,A,sum(A,2));
> A(:,end) = [];
> toc
> %Elapsed time is 0.141225 seconds.
>
>
> data=rand(n,59999);
> tic
> B = sort(data,2);
> toc
> %Elapsed time is 0.493895 seconds.
- - - - - - - - -
Matt, you shouldn't give people solutions that are distinctly inferior just because their code would run faster. That is putting too much emphasis on speed. Quality counts too. Both John and I have already shown you how far off the mark the plot of the two-variable case would be for your solution. It doesn't get any better as the number of variables increases where the speed difference would become significant.

Roger Stafford
From: John D'Errico on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i24oic$env$1(a)fred.mathworks.com>...
> "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i24l9s$auq$1(a)fred.mathworks.com>...
>
> > I don't even see the sort as more complex, nor does
> > MATLAB. Try this:
> ===========
>
> That's only because you're working in 2 dimensions. In higher dimensions, complexity theory of sorting vs. summation gaurantees that sorting will do worse. Try this modification:
>

No, if you bothered to look at my test, it was done
in 5 dimensions. Yes, if you solve a very different
problem from that which was asked about, the time
will be different.

John
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7
Prev: Speed bottleneck
Next: Error message for rayleighchan