Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
MapReduce >> mail # user >> CompateTo() in WritableComparable


Copy link to this message
-
Re: CompateTo() in WritableComparable
ie key ----->  A*Atrans--------->after multiplication the result will
be a 2D array which is declared as double (matrix) lets say the result
be Matrix "Ekey"(double[][] Ekey)

value ------>  Atrans*D ---------> after multiplication the result
will be Matrix "Eval" (double[][] Eval).

After tat i need to emit these matrix to reducer for further calculations.

so in mapper
       context.write(Ekey,Eval);

reducer
      i need to do further calculations with these Ekey nd Eval.ie
calculate (I/v + Ekey)*Eval. where I/v is a matrix with order of Ekey

public int compareTo(MatrixWritable o) {
    // TODO Auto-generated method stub

boolean ret = Arrays.equals(values, o.values);





}

I am really confused what to check, as i dnt get a complete idea of
compareTo() while relating it to mapreduce.

my input will be a file wit numerical data  say 'A' . from that i am
calculating Ekey and Eval in mapper.

                    context.write(new MatrixWritable(Ekey),new
MatrixWritable(Eval));

so what to compare. whether keys?if same key is coming...some thing
like that or?
On Mon, Nov 4, 2013 at 5:07 PM, Mirko Kämpf <[EMAIL PROTECTED]> wrote:

> You just have to implement the WritableComparable interface. This might be
> straight forward for any simple data type. Have look on:
>
> public int compareTo(MyWritableComparable o) {
>       int thisValue = this.value
>
>       int thatValue = o.value;
>
>       return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0 : 1)); ...
>
> But a matrix is something different.
>
> Now its your turn. Find out how to order your matrix objects. This can be any type of order which makes sense. Maybe the total sum or the total average of all values or whatever. It has to calc only -1, 0 or 1, depending on the given matrixes. I would assume that 0 will be given back if all pairs of elements from both matrizes with the same indexes are equal.
>
> But why do you need the Matrix one as the KEY in your reducer?
>
> Maybe it is better to use Custom object only as the Value, together with an arbitrary Key, which is WritableComparable ... but this depends on, what you want to calc in your reducer.
>
> If you share the description of the problem and the algorithm which solves it, we will find out whats the best way.
>
> What does you algorithm calculate?
>
>
> Best wishes
>
> Mirko
>
>
>
>
> 2013/11/4 unmesha sreeveni <[EMAIL PROTECTED]>
>
>> I am trying to emit a matrix(2D double array) as key and another matrix
>> as value.
>>
>> ie context.write(new myclass(matrixa),new myclass(matrixb));
>>  * so how to compare them
>>
>>
>> On Mon, Nov 4, 2013 at 4:16 PM, unmesha sreeveni <[EMAIL PROTECTED]>wrote:
>>
>>> Thanks Dieter De Witte
>>>
>>>
>>> On Mon, Nov 4, 2013 at 4:11 PM, Dieter De Witte <[EMAIL PROTECTED]>wrote:
>>>
>>>> A writableComparable is an interface. A key in mapreduce needs to
>>>> implement it, since the keys need to be compared for equality. So it has
>>>> nothing to do with key value pairs as such.
>>>>
>>>> Regards, Dieter
>>>>
>>>>
>>>> 2013/11/4 unmesha sreeveni <[EMAIL PROTECTED]>
>>>>
>>>>>
>>>>> what is CompateTo() in WritableComparable?
>>>>> Is that comparing a key and value or comparing key and key,value and
>>>>> value
>>>>>
>>>>> --
>>>>> *Thanks & Regards*
>>>>>
>>>>> Unmesha Sreeveni U.B
>>>>>
>>>>> *Junior Developer*
>>>>>
>>>>> *Amrita Center For Cyber Security *
>>>>>
>>>>>
>>>>> * Amritapuri.www.amrita.edu/cyber/ <http://www.amrita.edu/cyber/>*
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> *Thanks & Regards*
>>>
>>> Unmesha Sreeveni U.B
>>>
>>> *Junior Developer*
>>>
>>> *Amrita Center For Cyber Security *
>>>
>>>
>>> * Amritapuri.www.amrita.edu/cyber/ <http://www.amrita.edu/cyber/>*
>>>
>>
>>
>>
>> --
>> *Thanks & Regards*
>>
>> Unmesha Sreeveni U.B
>>
>> *Junior Developer*
>>
>> *Amrita Center For Cyber Security *
>>
>>
>> * Amritapuri.www.amrita.edu/cyber/ <http://www.amrita.edu/cyber/>*
>>
>
>
--
*Thanks & Regards*

Unmesha Sreeveni U.B

*Junior Developer*

*Amrita Center For Cyber Security*
* Amritapuri.www.amrita.edu/cyber/ <http://www.amrita.edu/cyber/>*