LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MODE.VI - Is it wired wrong?

Well, I have a slight problem. The Mode.VI for LV5.1 and LV6.1 are, I believe, wired incorrectly. I am surprised not to be able to find a solution here since this vi is at least two full versions old. I don't know if it remained the same in LV7.1

Anyhow, here is what is happening.
As per the Mode.vi help, Mode is the value that occurs most often in a sequence of values. For example, if the input sequence is
X = {0, 1, 3, 3, 4, 4, 4, 5, 5, 7},
then the mode of X is 4 because that is the value that most often occurs in X.

So I decided to do a quick sanity check and test the vi with a very simple array set.
X = {0, 1, 2, 2, 2, 2, 3, 4, 5, 6},
array size is 10
Xmin = 0 and Xmax = 9
deltaX = 1
Interval = (9 - 0)/ 1

Using Mod
e.vi the result, using the data above, is 2.33.
Clearly incorrect just by looking at the array set. So after reading and making sure I was doing things right, I looked at the code the comprises the Mode.vi and found a little problem.
The array being used to select the mode was the output of the hystogram.vi called (X Values). The array used to select the mode should be the original array. This is the input array going to the hystogram not it's output. After taking the liberty of rewiring the arrays the vi worked great as it should've.
Please, anyone, correctme if I am wrong but do I see an improperly wired vi here?

Thanks, Wil
0 Kudos
Message 1 of 7
(3,164 Views)
It's not wired wrong because the function is not intended to return the true mode of the sequence. The on-line help states "However, instead of finding the true mode of the input sequence, this VI uses a histogram to divide the input sequence into bins, or intervals, and returns the center value of the bin containing the most values from the input sequence. The center value of the bin containing the most values from the input sequence generally is more useful than the true mode in real-world applications where the data sequence contains even a small amount of noise." As you noted, if you make some modifications, you'll get the true mode. I would suggest that you save the modified VI as a different name and in a different location.
Message 2 of 7
(3,162 Views)
The quote from the on-line help above is from LV 7. The one in 6.1 is a little different but it does say "The VI obtains mode by generating a discrete histogram h(x) with the specified number of intervals of the input sequence X and then scanning h(x) for the interval that has the maximum count. Once the VI identifies the interval, the VI selects the center value of the interval as the mode of the input sequence X." I would agree that the help in LV7 is a little clearer.
0 Kudos
Message 3 of 7
(3,163 Views)
For my own sanity I modified the Mode.vi to also include the "True Mode". I also changed the name for the control Mode to "Center Mode", not really knowing what to name it.

I agree with you. This shold've been documented better or better yet, the vi should give the option to choose from true or center mode. Up until know I only knew of only one Mode. Even MS Excel uses Mode as defined in math books. I've never heard of a "True Mode" until now.
I do not perform data analysis but the difference between the results in these two functions/operations could be slight to considerably different. For example, try using the "Periodic Random Noise Waveform.vi" and perform a Mode function. Get both the "True Mode" and the "Center Mode". Quite a difference
. I guess there has to be some value for the difference but the "Center Mode", as I've been defining it here, is no Mode at all.

Thank you for your response Dennis, It clarified a lot for me. And I hope this can help others in the future to determine the differences.

Wil
0 Kudos
Message 4 of 7
(3,162 Views)
Man I agree with you entirely about this. It is unsettling to get the center value of a bin when you are looking for the most frequently occurring value in a dataset. It's like the job was only half done when it was stopped. Attached is a VI (LV v6.1) that will do the complete job and return the most frequent value(s) in a dataset.

Message Edited by Warren Massey on 11-30-2005 04:18 AM

Message 5 of 7
(3,072 Views)
Warren,
I tried your VI.  It works when the range of numbers in the dataset is small.  However, when I try it with my dataset
{50, 50, 50, 50, 51, 51, 51, 51, 51, 100}
the modal value returned is 50, not 51.  I would assume that this is because of the way the intervals work for the histogram...  Perhaps if you add in some sort of factor that accounts for the range of values in the array instead of just looking at the array size you would get better results for datasets with large ranges.
 
Regards,
Michelle
0 Kudos
Message 6 of 7
(3,015 Views)


@mlloyd wrote:
Warren,
I tried your VI.  It works when the range of numbers in the dataset is small.  However, when I try it with my dataset
{50, 50, 50, 50, 51, 51, 51, 51, 51, 100}
the modal value returned is 50, not 51.  I would assume that this is because of the way the intervals work for the histogram...  Perhaps if you add in some sort of factor that accounts for the range of values in the array instead of just looking at the array size you would get better results for datasets with large ranges.
 
Regards,
Michelle


You are right that it does appear to be incorrectly sensitive to this type of data.
You are also correct that the problem lies with how the intervals are chosen.

My first thought on how to fix it was to just allow one interval for each integer value between the max & min values in the array but this can result in too many intervals if the separation is large.

My second thought was to dump the Histogram function and its problematic interval-picking problem and just count the occurrences of each value found in the array. That was the basis for the attached Modal_Value_I vi that is attached.

It then occurred to me that since the values being analyzed were floats, there really needed to be some tolerance associated with the part of the VI that searched for like values, and from that, Modal_Value_II was born.

There is no doubt still room for improvement since Modal_Value_II doesn't report out the center value within the intervals it develops (it instead reports out the first value it found in the array that was subsequently used to develop the new interval) but I'll leave that refinement for another day or another person.

The VI's are LV v7.1.1.

0 Kudos
Message 7 of 7
(2,998 Views)