Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing median in map reduce

Can someone example the computation of median/quantiles in map reduce?

My understanding of Datafu's median is that the 'n' mappers sort the data and send the data to "1" reducer which is responsible for sorting all the data from n mappers and finding the median(middle value) Is my understanding correct?,

if so, does this approach scale for massive amounts of data as i can clearly see the one single reducer struggling to do the final task. Thanks

like image 613
learner Avatar asked Apr 11 '12 15:04

learner


People also ask

How do you find average in MapReduce?

Average is sum / size. If sum is something like sum = k1 + k2 + k3 + ... , you might divide by size after or during summing up. So the average is also k1 / size + k2 / size + k3 / size + ... So you first map each value of your elements in the list to double and then summing up via the reduce function.

What is MapReduce medium?

MapReduce is a programming framework that allows us to perform distributed and parallel processing on large data sets in a distributed environment. MapReduce consists of two distinct tasks — Map and Reduce. As the name MapReduce suggests, reducer phase takes place after the mapper phase has been completed.

What is MapReduce example?

Understanding the workflow of MapReduce with an Example In the above example Twitter data is an input, and MapReduce Training performs the actions like Tokenize, filter, count and aggregate counters. Tokenize: Tokenizes the tweets into maps of tokens and writes them as key-value pairs.

What is map reducing algorithm?

MapReduce implements various mathematical algorithms to divide a task into small parts and assign them to multiple systems. In technical terms, MapReduce algorithm helps in sending the Map & Reduce tasks to appropriate servers in a cluster. These mathematical algorithms may include the following − Sorting. Searching.


2 Answers

Trying to find the median (middle number) in a series is going to require that 1 reducer is passed the entire range of numbers to determine which is the 'middle' value.

Depending on the range and uniqueness of values in your input set, you could introduce a combiner to output the frequency of each value - reducing the number of map outputs sent to your single reducer. Your reducer can then consume the sort value / frequency pairs to identify the median.

Another way you could scale this (again if you know the range and rough distribution of values) is to use a custom partitioner that distributes the keys by range buckets (0-99 go to reducer 0, 100-199 to reducer 2, and so on). This will however require some secondary job to examine the reducer outputs and perform the final median calculation (knowing for example the number of keys in each reducer, you can calculate which reducer output will contain the median, and at which offset)

like image 186
Chris White Avatar answered Sep 30 '22 03:09

Chris White


Do you really need the exact median and quantiles?

A lot of the time, you are better off with just getting approximate values, and working with them, in particular if you use this for e.g. data partitioning.

In fact, you can use the approximate quantiles to speed up finding the exact quantiles (actually in O(n/p) time), here is a rough outline of the strategy:

  1. Have a mapper for each partition compute the desired quantiles, and output them to a new data set. This data set should be several order of magnitues smaller (unless you ask for too many quantiles!)
  2. Within this data set, compute the quantiles again, similar to "median of medians". These are your initial estimates.
  3. Repartition the data according to these quantiles (or even additional partitions obtained this way). The goal is that in the end, the true quantile is guaranteed to be in one partition, and there should be at most one of the desired quantiles in each partition
  4. Within each of the partitions, perform a QuickSelect (in O(n)) to find the true quantile.

Each of the steps is in linear time. The most costly step is part 3, as it will require the whole data set to be redistributed, so it generates O(n) network traffic. You can probably optimize the process by choosing "alternate" quantiles for the first iteration. Say, you want to find the global median. You can't find it in a linear process easily, but you can probably narrow it down to 1/kth of the data set, when it is split into k partitions. So instead of having each node report its median, have each node additionally report the objects at (k-1)/(2k) and (k+1)/(2k). This should allow you to narrow down the range of values where the true median must lie signficantly. So in the next step, you can each node send those objects that are within the desired range to a single master node, and choose the median within this range only.

like image 39
Has QUIT--Anony-Mousse Avatar answered Sep 30 '22 03:09

Has QUIT--Anony-Mousse