google-code-export / pysal

Automatically exported from code.google.com/p/pysal
Other
1 stars 1 forks source link

Logic Bug in arcgis_txt #179

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There appears to be a logic bug in the arcgis_text weights reader.

The reader produces weights in which polygons are neighbors of themselves 
(albeit with a weight value of 0).

From the doc_string....
>>> w = pysal.open('../../examples/arcgis_txt.txt','r','arcgis_text').read()
>>> w[1]
{1: 0.0, 2: 0.10000000000000001, 3: 0.14285999999999999}

The problem with this, if the user applies a binary transform, the weight value 
becomes one...

>>> w.transform='B'
>>> w[1]
{1: 1.0, 3: 1.0, 6: 1.0, 7: 1.0}

This could be considered a bug in the transform as well, since a value of 0 
should not be considered a neighbor.  However, the reader shouldn't add 
non-neighbors for the neighbors dictionary because even without the transform, 
the neighbors dictionary would identify 1 as a neighbor of 1

>>> w.neighbors[1]
[1, 2, 3]

Original issue reported on code.google.com by schmi...@gmail.com on 7 Nov 2011 at 7:28

GoogleCodeExporter commented 9 years ago
I am updating arcgis_txt.py so that it ignores self-neighbors. 
However, I have two questions. 
1) To my knowledge, Kernel weights include self-neighbors. What happens to 
Kernel weights when any transform operation is applied?
2) What if users have some weights for self-neighbors in the source text file? 
Is it correct to ignore them? 

I think maybe we need to decide our policy for self-neighbors.

Original comment by mhwa...@gmail.com on 23 Nov 2011 at 6:06

GoogleCodeExporter commented 9 years ago
Self neighbors are ok if they are intentional. In the case of arcgis_txt, it 
appears the weights on the diagonal are zero. This indicates they should not be 
added to the neighbors dictionary.  In the case of Kernel weights, the diagonal 
is non-zero.

Original comment by schmi...@gmail.com on 23 Nov 2011 at 6:26

GoogleCodeExporter commented 9 years ago
Ok. Got your point. The code is fixed. 

Original comment by mhwa...@gmail.com on 23 Nov 2011 at 7:19

GoogleCodeExporter commented 9 years ago

Original comment by mhwa...@gmail.com on 23 Nov 2011 at 8:54