The science of suckiness
June 8, 2009 10:07 AM   Subscribe

I want to calculate the mean of a matrix, but I don't want a value, I want co-ordinates. The following math question has lots of terminology that I'm not qualified to use i.e. most of it is wrong. I hope you can see through this and help me. I will be using the words matrix, mean and transformation without fully understanding them. For this I apologize.

Imagine a 10x10 matrix of integers, I wish to find the 'point of balance'. That is, if the integers were weights and the matrix a sheet of plywood, it is where I would place a pivot for the sheet to remain in balance (assume the plywood has no weight).

I don't want to work it our mechanically (using trig and moments and things of that ilk, besides the weight thing is an analogy, I'm looking at luminosity), I want to apply a matrix transformation if possible.

However my knowledge doesn't even let me begin to search on the type of transformation I need.

I have played with the mean of the rows and cols. In a 2x2 matrix for example

10,20
4,200

x = ((1 * 10) + (2 * 20) + (1 * 4) + (2 * 200)) / (10 + 20 + 4 + 200) = 1.94017094
y = ((1 * 10) + (2 * 4) + (1 * 20) + (2 * 200)) / (10 + 20 + 4 + 200) = 1.87179487

which looks right, but doesn't feel right. I'm sure we are missing something.

Any pointers/equations/corrections are very appreciated.

(The 'suckiness' in the title refers to the larger integers "sucking" the balance point towards them, not that I suck at science, which I do)
posted by handybitesize to Science & Nature (6 answers total) 1 user marked this as a favorite
 
Best answer: What you're talking about is a weighted mean, and, in your example, you're doing it correctly. I'm not sure why your example doesn't feel right to you, but the 200 "sucks" a lot (it's around a factor of 10 larger than the other entries, and the coordinates you realize are only about 10% away from its location). Note that this answer is preserved by rotating the matrix or reflecting it over its axes (x' = 1.05982906, y' = 1.12820513). Also note some extreme cases... for any x, the "center" of the matrix

x x
x x

is [1*x + 2*x]/2x for both coordinates, or (1.5,1.5) as you'd expect. Also, the "center" of

x 0
0 0

or any reflection/rotation thereof will be the location of x.
posted by 7segment at 10:21 AM on June 8, 2009


The center of mass formula should work here (which is what you are implementing). I think you have it right. There might be something more sophisticated you can do but I don't know what that would be without knowing the type of pattern you are looking for.

So, without knowing more, I'd say you are right. Watch your coordinates though, you want to make sure that you keep careful track of your row and column indexes!
posted by milqman at 10:28 AM on June 8, 2009


Yeah you've got it right. You'll find it a bit easier in a 10x10 case to use the sum of the columns when finding the x-coord and use the sum of the rows when finding the y-coord.

So if you had:

x00 x01 ... x09
x10 x11 ... x19
.
.
x90x91 ... x991

You'd want xmiddle = [1*(x00 + x10 + ... + x90) + 2*(x01...) + ...]/SUM.
It'll be a lot easier for you to work with. But you've definitely got it.

1: starting at 0 for consistent formatting.
posted by Lemurrhea at 10:35 AM on June 8, 2009


See also Center of mass on Wikipedia, which agrees with everything above.
posted by mbrubeck at 10:54 AM on June 8, 2009


Response by poster: Oh wow - multiple "ur doing it right" replies before I got home. Thanks all. I'll run it against some edge cases now, because maybe my its my eyes that's misinterpreting the expected result
posted by handybitesize at 10:58 AM on June 8, 2009


Having done a lot of image processing and computer vision...

Since your math is right, but you say "maybe my its my eyes that's misinterpreting the expected result", it's possible that you're just barking up the wrong tree. I've definitely spent the better part of a couple days working out a particularly tricky convolution, only to find that the visual result is nothing like what I was imagining.
posted by Netzapper at 11:24 AM on June 8, 2009


« Older Excel is getting "E"xcited...   |   Name of 20th Century Philosopher? Newer »
This thread is closed to new comments.