Announcement

Collapse
No announcement yet.

PAC Suite STA (MEDIAN)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PAC Suite STA (MEDIAN)

    How does PAC determine the median of a population?

    On some populations, PAC returns a different result than Excel - the baseline calculator in my world.
    For this run, the Voltage sample set, pac returns the same value as Excel for volt Median.
    I do have another EVEN numbered set that returns volt and current Median values spot-on with Excel.
    It seems that for this population set, 762 and 790 should be averaged together to return 776

    'Current' sample set (unsorted)
    1 930
    2 842
    3 670
    4 730
    5 840
    6 733
    7 720
    8 891
    9 850
    10 762
    11 690
    12 790
    13 910
    14 900
    15 910
    16 760
    17 891
    18 752
    19 760
    20 700

    Sample set (sorted)
    1 670
    2 690
    3 700
    4 720
    5 730
    6 733
    7 752
    8 760
    9 760
    10 762
    11 790
    12 840
    13 842
    14 850
    15 891
    16 891
    17 900
    18 910
    19 910
    20 930


    Excel 776
    PAC 762

    Background info - in case you are interested
    I am measuring multiples of 100 capacitor voltages and currents. I put these values into MEAS_V and MEAS_I arrays (scaled and *calibration* offsets applied.)
    I then loop through the arrays. If the looped cap is not failed, I copy its voltage to the VoltPopulation and its current to the CurrentPopulation arrays. I count each WorkingPass (WPCount).
    I then do STA-Median using '1' as the start column and the WPCount as the end column. I also do a Min and Max.
    I do this on a 2-second interval. The MEASured and the MinMaxMed values are made available for the HMI.

  • #2
    It seems to be doing exactly what it says in the help file. It returns the "Lower middle value" not the median between the two values.
    "
    Returns the Middle value found in the set of numbers within the specified indices of the Array. If the set of numbers is Odd, the instruction returns the Middle value. For example: If there are 5 Input values of 3, 4, 6, 21 and 45, the Median calculation will return the value of 6. If the set of numbers is Even, the instruction returns the Lower Middle value. If there are 4 Input values of 1, 2, 4 and 38, the Median calculation will return the value 2

    Comment


    • #3
      Note to self: rt#m
      not quite the standard, but what can I do?

      thanks IMNCTRL!

      Comment


      • #4
        Do you know whether the number is going to be even or odd? (looks like maybe not) But you could look at the lowest bit for WPcount and when it is not true do the following:
        1) find the Lower Median value
        2) Use a shift/rotate array to start shifting values in an array that contains the values and compare to the lower median until it finds one greater than the lower median value
        3) Save it to another location
        4) Add the values together and divide by 2 or avg the two to get your true median

        Comment


        • #5
          Yes WPct mod 2 = 0 means even (or no pop)
          i could sort, let pac get median, look back one position, get that value. Average the two values to get the REAL median.

          im being salty now

          maybe the devs could use the standard MEDIAN definition.
          Last edited by kewakl; 03-31-2020, 08:21 PM.

          Comment


          • #6
            Btw, i did look at several sorting routines, thinking maybe I would implement one just for this purpose.
            With this small population Big O is not critical, so most any sort routine would suffice.


            Pac has some great math tools and some rather anemic tools--- im looking at you DATA/standard deviation on a population of 16 iirc.
            Last edited by kewakl; 04-01-2020, 03:48 AM.

            Comment


            • #7
              Another hack. When it's even, add another value that equals the MAX value (to shift the median to the "higher" median value), get THAT median, take the average between the two medians, then "remove" that MAX value. ? ? ?
              There are 10 kinds of people in this world, those who know binary, and those who do not.

              Comment


              • #8
                Originally posted by franji1 View Post
                Another hack. When it's even, add another value that equals the MAX value (to shift the median to the "higher" median value), get THAT median, take the average between the two medians, then "remove" that MAX value. ? ? ?
                Interesting idea. I really don't need to remove it afterwards. It gets recalculated 2 seconds later anyway!
                If my 'Numbers Engineer' can accept the current MEDIAN methodology, I will leave it as is. If not, franji1, I will go this way!

                Thank you

                Comment


                • #9
                  Originally posted by kewakl View Post
                  If my 'Numbers Engineer' can accept the current MEDIAN methodology, I will leave it as is. If not, franji1, I will go this way!
                  Another possibility, see if the "numbers guy" can accept a sample size of 21.

                  There are 10 kinds of people in this world, those who know binary, and those who do not.

                  Comment


                  • #10
                    Originally posted by franji1 View Post
                    Another possibility, see if the "numbers guy" can accept a sample size of 21.
                    Sample size changes dynamically - based on number of parts that have not faulted.
                    I (roughly) describe the routine for building the population at the bottom of the first post.

                    Comment


                    • #11
                      I have a working (not polished) example that sorts and calcs median. (single point for odd-numbered and averaged for even-numbered populations)
                      the sort routine is here
                      The getmedian routine is here (I named it 'Find' - short and sweet naming.)
                      (as usual, open in another tab for clear image)

                      Click image for larger version

Name:	median.png
Views:	82
Size:	107.5 KB
ID:	130126

                      Comment


                      • #12
                        Not sure why you are sorting the values. The STA instruction will find the "Lower Median" value without sorting. When the number of samples are even you can run the following 5 rungs of logic to find the next larger value ( without sorting) and add the lower median and next larger value and divide by 2 to get true median.

                        Click image for larger version

Name:	Median.PNG
Views:	58
Size:	20.7 KB
ID:	130218

                        Comment


                        • #13
                          You did it in 5 rungs. I did it in 5 rungs.
                          Win Win

                          I also now have a bubble sort routine for PAC. I have a better understanding of HOW to find median in a plc that has no advanced math skills.
                          I like the :1 for determining odd/even. For this part of the project I am using 1.9.2.0 and do not remember if I have enabled BitOfWord. (1.9.2.0 because I have an older *similar* project running on 1.9.2.0 and I want to stay there until I learn te eastereggs of the latest versions.)
                          Last edited by kewakl; 04-09-2020, 08:28 PM.

                          Comment

                          Working...
                          X