[GRASS-user] About Matrix Weights

Hi everyone,

I hope someone can explain how works the option “matrix weights” of the r.neighbors program. I’ve been trying to find out for myself but I’m really confused. I’ve read the documentation but it’s no clear for me in this aspect.

What I’ve trying to do to find out how works it the next:

1st I’ve created a random matrix 5x5 with values from 1-25 randomly disposed.
2nd I’ve done four different matrix, 0, 1, 5, 10, for all the values in a 3x3 window,

for the first one (0), all the values are NULL.
for the rest I have the same result… :S Why?

I know i’m missing something, but I don’t know what is it. I would aprecciate some help in this point.

Thank you very much!!

···
-- 
Luís Miguel Royo Pérez

On Thu, Nov 14, 2013 at 12:45 PM, Luis Miguel Royo Perez <
luis.miguel.royo@gmail.com> wrote:

Hi everyone,

I hope someone can explain how works the option *"matrix weights" *of the
*r.neighbors* program. I've been trying to find out for myself but I'm
really confused. I've read the documentation but it's no clear for me in
this aspect.

What I've trying to do to find out how works it the next:

1st I've created a random matrix 5x5 with values from 1-25 randomly
disposed.
2nd I've done four different matrix, 0, 1, 5, 10, for all the values in a
3x3 window,

for the first one (0), all the values are NULL.
for the rest I have the same result... :S Why?

I know i'm missing something, but I don't know what is it. I would
aprecciate some help in this point.

Hi, can you please post also the exact commands you are using to make it

clear? (I mean just copy from it command line or using Copy button in
module dialog.)

Thanks,
Vaclav

Thank you very much!!

--
Luís Miguel Royo Pérez

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Of course!

here is the command I’m using:

r.neighbors --overwrite input=celdas.aleatorias.1-250@PERMANENT output=media1-250.pesos0 weight=/home/luismi/Escritorio/prueba_pesos0.txt

And the Matrix Weight is the next:

0 0 0
0 0 0
0 0 0

This matrix is the same for 1, 5 and 10 values. I’m putting spaces between the numbers… is this correct?

···

2013/11/14 Vaclav Petras <wenzeslaus@gmail.com>


Luís Miguel Royo Pérez.
Licenciado en Historia
Arqueólogo colegiado Nº 16218

Av. Blasco Ibañez nº 1. Manises (Valencia)
Teléfonos 679846103 y 961545792
email: luis.miguel.royo@gmail.com
web: www.inisig.com

On Thu, Nov 14, 2013 at 12:45 PM, Luis Miguel Royo Perez <luis.miguel.royo@gmail.com> wrote:

Hi everyone,

I hope someone can explain how works the option “matrix weights” of the r.neighbors program. I’ve been trying to find out for myself but I’m really confused. I’ve read the documentation but it’s no clear for me in this aspect.

What I’ve trying to do to find out how works it the next:

1st I’ve created a random matrix 5x5 with values from 1-25 randomly disposed.
2nd I’ve done four different matrix, 0, 1, 5, 10, for all the values in a 3x3 window,

for the first one (0), all the values are NULL.
for the rest I have the same result… :S Why?

I know i’m missing something, but I don’t know what is it. I would aprecciate some help in this point.

Hi, can you please post also the exact commands you are using to make it clear? (I mean just copy from it command line or using Copy button in module dialog.)

Thanks,
Vaclav

Thank you very much!!

-- 
Luís Miguel Royo Pérez


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

On Thu, Nov 14, 2013 at 1:42 PM, Luís Miguel Royo Pérez <
luis.miguel.royo@gmail.com> wrote:

Of course!

here is the command I'm using:

r.neighbors --overwrite input=celdas.aleatorias.1-250@PERMANENToutput=media1-250.pesos0 weight=/home/luismi/Escritorio/prueba_pesos0.txt

And the Matrix Weight is the next:

0 0 0
0 0 0
0 0 0

This matrix is the same for 1, 5 and 10 values. I'm putting spaces between
the numbers... is this correct?

Spaces between numbers are OK (and newline for rows). You may want to try

the analyze test map created by r.mapcalc:

r.mapcalc expression="a_test = row() - 1 + col() - 1"

0 1 2
1 2 3
2 3 4

r.neighbors input=a_test@PERMANENT output=a_neig method=sum weight=...

some weights:
1 10 1
10 1 1
1 1 1

method was sum (easy to count by hand), so result:

4 9 24
9 36 63
24 63 90

The center cell is
1*0 + 10*1 + 1*2 + 10*1 + 1*2 + 1*3 + 1*2 + 1*3 + 1*4 = 36

You are right, some example like this should be in the manual.

Zero weight really creates NULLs which is strange, I would expect zeros,
maybe bug.

Hope that helps, if not hopefully others can say something about it.

Vaclav

2013/11/14 Vaclav Petras <wenzeslaus@gmail.com>

On Thu, Nov 14, 2013 at 12:45 PM, Luis Miguel Royo Perez <
luis.miguel.royo@gmail.com> wrote:

Hi everyone,

I hope someone can explain how works the option *"matrix weights" *of
the *r.neighbors* program. I've been trying to find out for myself but
I'm really confused. I've read the documentation but it's no clear for me
in this aspect.

What I've trying to do to find out how works it the next:

1st I've created a random matrix 5x5 with values from 1-25 randomly
disposed.
2nd I've done four different matrix, 0, 1, 5, 10, for all the values in
a 3x3 window,

for the first one (0), all the values are NULL.
for the rest I have the same result... :S Why?

I know i'm missing something, but I don't know what is it. I would
aprecciate some help in this point.

Hi, can you please post also the exact commands you are using to make it

clear? (I mean just copy from it command line or using Copy button in
module dialog.)

Thanks,
Vaclav

Thank you very much!!

--
Luís Miguel Royo Pérez

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
Luís Miguel Royo Pérez.
Licenciado en Historia
Arqueólogo colegiado Nº 16218

Av. Blasco Ibañez nº 1. Manises (Valencia)
Teléfonos 679846103 y 961545792
email: luis.miguel.royo@gmail.com
web: www.inisig.com

Luís Miguel Royo Pérez wrote:

r.neighbors --overwrite

input=celdas.aleatorias.1-250@PERMANENT

output=media1-250.pesos0

weight=/home/luismi/Escritorio/prueba_pesos0.txt

Note, the default method is “average”.

And the Matrix Weight is the next:

0 0 0

0 0 0

0 0 0

This matrix is the same for 1, 5 and 10 values. I’m putting spaces between

the numbers… is this correct?

Just to be clear, you mean you have constructed, appart from the “0” matrix above:

1 1 1

1 1 1

1 1 1

5 5 5

5 5 5

5 5 5

10 10 10

10 10 10

10 10 10

?

And you ran them with the default method=average?

Nikos

Hi Nikos,

yes, these are the matrix I've been using.

And yes i ran them with the default method.

El 15/11/13 09:39, Nikos Alexandris escribió:

And you ran them with the default method=average?

--
Luís Miguel Royo Pérez

Luis Miguel Royo Perez wrote:

I hope someone can explain how works the option /"matrix weights" /of
the *r.neighbors* program. I've been trying to find out for myself but
I'm really confused. I've read the documentation but it's no clear for
me in this aspect.

What I've trying to do to find out how works it the next:

1st I've created a random matrix 5x5 with values from 1-25 randomly
disposed.
2nd I've done four different matrix, 0, 1, 5, 10, for all the values in
a 3x3 window,

    for the first one (0), all the values are NULL.
    for the rest I have the same result... :S Why?

I know i'm missing something, but I don't know what is it. I would
aprecciate some help in this point.

The way that weights are used depends upon the specific aggregate
(method) being used.

However, most of the aggregates have the property that multiplying all
of the weights by the same factor won't change the final result (an
exception is method=count).

Also, most (if not all) of them have the properties that an integer
weight of N is equivalent to N occurrences of the cell value, and
having all weights equal to one produces the same result as when
weights are not used.

When weights are used, the calculation for method=average is:

  sum(w[i]*x[i]) / sum(w[i])

In the case where all weights are zero, this will end up with both the
numerator and denominator to zero, which produces a null result.

--
Glynn Clements <glynn@gclements.plus.com>

On Fri, Nov 15, 2013 at 4:08 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:
...

The way that weights are used depends upon the specific aggregate
(method) being used.

However, most of the aggregates have the property that multiplying all
of the weights by the same factor won't change the final result (an
exception is method=count).

Also, most (if not all) of them have the properties that an integer
weight of N is equivalent to N occurrences of the cell value, and
having all weights equal to one produces the same result as when
weights are not used.

When weights are used, the calculation for method=average is:

        sum(w[i]*x[i]) / sum(w[i])

In the case where all weights are zero, this will end up with both the
numerator and denominator to zero, which produces a null result.

I have taken liberty to merge this into the manual in r58242.

TODO: add example...

Markus