Question

I have two rows of numbers ...

1) 2 2 1 0 0 1

2) 1.5 1 0 .5 1 2

Each column is compared to each other. Lower values are better. For example Column 1, row 2's value (1.5) is more accurate than row 1 (2)

In normal comparison I would take to the sum of each row and compare to the other row to find the lowest sum (most accurate). In this case both would be equal.

I want to create two other comparison methods When values ascend from column 1 they should be weighted more (col 2 should hold more weight than 1, 3 than 2 and so on)

Also the opposite

Originally I thought it would be best to divide the value by its position but that doesn't work correctly.

What would be the best way to do this for a row?

Thanks!

Was it helpful?

Solution

So all you're really doing is computing the product of your matrix with a weighting vector. See this page for more info on matrix multiplication.

I.e. your vector M is

M = | 2.0 2.0 1.0 0.0 0.0 1.0 |
    | 1.5 1.0 0.0 0.5 1.0 2.0 |

and in your first case the weighting vector w is:

w = (1, 1, 1, 1, 1, 1)

the product of which gives you:

M x w = (6, 6)

which are the two scores for the two rows.

For an ascending weighting use something like :

w = (1, 2, 3, 4, 5, 6)

which gives you:

M x w = (15, 22.5)

and for a descending weight you could use either:

w = (6, 5, 4, 3, 2, 1)

or

w = (1, 1/2, 1/3, 1/4, 1/5, 1/6)

(Note vectors are transposed for readability).

OTHER TIPS

Originally, all values have the same weight, so your factors for n values are all 1/n, so your sum is:

S = 1 * v_1 + 1 * v_2 + ... + 1 * v_n

Your try to divide the value by its position would be:

S = 1/1 * v_1 + 1/2 * v_2 + ... + 1/n * v_n

Which is still a valid approach, but does the opposite of what you want (column 1 gets most weight).

What you want is something like this:

S = 1/n * v_1 + 1/n-1 * v_2 + ... + 1/1 * v_n

You might also consider to start with 1/n+1 and end with 1/2 so the last value will be a bit less important.

I don't know if I have understood what you wanna do, but maybe it's this:

for (i=0, i<length, i++)
  difference += (a[i] - b[i]) * w[i];

w[] would be an array with the weights by column (e.g.: w={1,2,3,4,5}), although could well be any other value/function.

So in the end, if difference is higher than 0, a[] is better, and if it's lower than 0 is worse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top