pombreda / pysal

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

Add option for row-standardization to ps.weights.util.lat2SW #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some spatial econometrics methods require row-standardized weights (or some of 
the conditions are easily met if W is row-standardized). It would be nice to 
have an option in lat2SW with which you could create a sparse W that is 
row-standardized.

Original issue reported on code.google.com by dreamessence on 1 Dec 2011 at 7:06

GoogleCodeExporter commented 9 years ago
I asked this question on stackoverflow to find an easy to to row standardize a 
matrix....
http://stackoverflow.com/questions/8358962/efficiently-row-standardize-a-matrix/
8359856#8359856

You can row standardize lat2SW as follows,
>>> W = pysal.weights.lat2SW()
>>> Wrs = scipy.sparse.spdiags(1./W.sum(1).T, 0, *W.shape) * W

This should be pretty efficient, but there is a way to do this on 
construction... Instead of putting 1's on the diagonals put 1/max(cardinality) 
and go back and fix the edge cases.

For now lets try the former.  Does this need to be an option of lat2SW? A 
method in util? or can we just put the snippet in the user guide?

Original comment by schmi...@gmail.com on 2 Dec 2011 at 5:40

GoogleCodeExporter commented 9 years ago
Implemented SO idea on r1077. If we need more sophisticated ways, we can always 
re-open but this works fine.

Original comment by dreamessence on 16 Jan 2012 at 8:06