comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » majority voting
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: majority voting [message #65167 is a reply to message #65079] Wed, 11 February 2009 15:20 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
You're trying to compute the n-dimensional mode. For the 1D case,
see:

http://www.dfanning.com/code_tips/mode.html

You could of course use SORT_ND and a 2D version of the "find the
longest string of the same number" method on this page. This is very
safe against sparse input distributions -- notice the HISTOGRAM in
SORT_ND is of the sort indices, not the data themselves. It's also
easy to recognize a mode length of 1 as "no mode", and (if you like)
detect multiple modes in the data (aka "tie votes").

However, your problem is a special case, since (I presume) your vote
labels are always low contiguous integers, you don't have to worry
about sparseness. In this case, using HIST_ND directly without
sorting will likely be much faster:

n=n_elements(array)
s=size(array,/DIMENSIONS)
h=hist_nd([lindgen(1,n)/s[1],reform(transpose(array),1,n)],1 )
m=max(h,DIMENSION=2,mode) gt 1
mode=mode/s[0] * m + m - 1

All I'm doing here is forming a 2d space, with the first dimension the
integer ID of the vote (aka column number in your example), and the
second the actual votes cast.

Had you organized your array with the rows as your "vote items" you
could save the transpose. Also note I specifically test for and set
to -1 any mode with frequency of 1 (your "don't care"). I do not
check for multiple modes, but you could do this as well in a
straightforward way. The fact that the dimensions of the 2D histogram
are the same as the input array is incidental, by the way.

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Reading multiple ASCII files in as 2d arrays and putting them into a 3d array
Next Topic: Different issue

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:04:09 PDT 2025

Total time taken to generate the page: 0.00430 seconds