help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zero or not?


From: kensmith
Subject: Re: Zero or not?
Date: Tue, 24 Jul 2007 08:03:49 -0700
User-agent: KMail/1.9.1

On Tuesday 24 July 2007 07:47, Przemek Klosowski wrote:
>    I'm new to "octave".  I'm translating from a method I use in
> "pascal"
>
>    Avg = sum(abs(X))/(size(X)(2));     # Figure a dividing line
>
> Or you could just say Avg=mean(X);
>
>    Gate = Avg < abs(X);                      # Classify X
>
>    Total = sum(X .* Gate) + sum(X .* !Gate);
>
> Or, simpler,  avg=mean(x); sum(x(x>=avg)) + sum(x(x<avg))
Make that:
avg = mean(abs(x))

You may be working with different signed values.

>
> I must say that this method is surprisingly good: twice as fast
> as the full sort, while getting most of the accuracy:
>
> x=exp(100*rand(1,1000000));
>
> tic; avg=mean(x); sum(x(x>=avg)) + sum(x(x<avg))-sum(x), toc
>   ans =  7.3219e+34
>                      Elapsed time is 0.308838 seconds.
> tic; sum(sort(x))-sum(x), toc
>   ans =  7.0664e+34
>                      Elapsed time is 0.689682 seconds.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave

-- 
address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]