[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Zero or not?
From: |
Przemek Klosowski |
Subject: |
Re: Zero or not? |
Date: |
Tue, 24 Jul 2007 10:47:06 -0400 (EDT) |
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))
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.
- Re: Zero or not?, (continued)
- Re: Zero or not?, Matthias Brennwald, 2007/07/21
- Re: Zero or not?, Ben Abbott, 2007/07/21
- Re: Zero or not?, Matthias Brennwald, 2007/07/22
- Re: Zero or not?, James Sherman Jr., 2007/07/22
- Re: Zero or not?, Matthias Brennwald, 2007/07/23
- Re: Zero or not?, Francesco Potorti`, 2007/07/23
- Re: Zero or not?, James Sherman Jr., 2007/07/23
- Re: Zero or not?, Miroslaw Kwasniak, 2007/07/23
- Re: Zero or not?, Francesco Potorti`, 2007/07/24
- Re: Zero or not?, kensmith, 2007/07/24
- Re: Zero or not?,
Przemek Klosowski <=
- Re: Zero or not?, kensmith, 2007/07/24
- Re: Zero or not?, Francesco Potorti`, 2007/07/22
- Re: Zero or not?, Miroslaw Kwasniak, 2007/07/23
- Re: Zero or not?, Francesco Potorti`, 2007/07/23
- Re: Zero or not?, kensmith, 2007/07/23
- Re: Zero or not?, Przemek Klosowski, 2007/07/23
- Re: Zero or not?, Robert A. Macy, 2007/07/21
Re: Zero or not?, Bob Weigel, 2007/07/21