Median vs. Average

Hi all

Just out of curiosity, recently we have some profiling of our code and found that getting median is much slower than getting average, will there any reason behind?

 

you need to sort to get the median?

2014-11-10 15:24 GMT+01:00 Carfield Yim <carfield@gmail.com>:

Hi all

Just out of curiosity, recently we have some profiling of our code and found that getting median is much slower than getting average, will there any reason behind?


--

Submitted via Google Groups

Yes,  and this is the reason?

If speed matters, you can use the median function from the boost library:<o:p></o:p>

<o:p> </o:p>

C++ code:<o:p></o:p>

<o:p> </o:p>

include <k.h><o:p></o:p>

include <boost/accumulators/accumulators.hpp><o:p></o:p>

include <boost/accumulators/statistics.hpp><o:p></o:p>

<o:p> </o:p>

namespace acc = boost::accumulators;<o:p></o:p>

<o:p> </o:p>

kx::K median(kx::K x)<o:p></o:p>

{<o:p></o:p>

       acc::accumulator_set<double, acc::stats<acc::tag::median(acc::with_p_square_quantile)> >a;<o:p></o:p>

       double* b = (double*) (x)->G0;for(double* e = b + x->n;b!=e;++b){a(*b);}<o:p></o:p>

       return kx::kf(acc::median(a));<o:p></o:p>

}<o:p></o:p>

<o:p> </o:p>

q code:<o:p></o:p>

<o:p> </o:p>

q)median: :boost 2: (median;1)<o:p></o:p>

<o:p> </o:p>

q)x:10000000?1.0<o:p></o:p>

<o:p> </o:p>

q)\t med x<o:p></o:p>

1536<o:p></o:p>

<o:p> </o:p>

q)\t median x<o:p></o:p>

502<o:p></o:p>

<o:p> </o:p>

Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Carfield Yim
Gesendet: Montag, 10. November 2014 23:06
An: personal-kdbplus@googlegroups.com
Betreff: Re: [personal kdb+] Median vs. Average<o:p></o:p>

<o:p> </o:p>

Yes,  and this is the reason? <o:p></o:p>

On Nov 10, 2014 10:55 PM, “Michael Wittig” <michael.wittig@tullius-walden.com> wrote:<o:p></o:p>

you need to sort to get the median?<o:p></o:p>

<o:p> </o:p>

2014-11-10 15:24 GMT+01:00 Carfield Yim <carfield@gmail.com>:<o:p></o:p>

Hi all<o:p></o:p>

<o:p> </o:p>

Just out of curiosity, recently we have some profiling of our code and found that getting median is much slower than getting average, will there any reason behind?<o:p></o:p>

<o:p> </o:p>

 <o:p></o:p>


Submitted via Google Groups

I see, thanks!