libpysal.weights.
DistanceBand
(data, threshold, p=2, alpha=-1.0, binary=True, ids=None, build_sp=True, silence_warnings=False, distance_metric='euclidean', radius=None)[source]¶Spatial weights based on distance band.
(n,k) or KDTree where KDtree.data is array (n,k) n observations on k characteristics used to measure distances between the n objects
distance band
Minkowski p-norm distance metric parameter: 1<=p<=infinity 2: Euclidean distance 1: Manhattan distance
If true w_{ij}=1 if d_{i,j}<=threshold, otherwise w_{i,j}=0 If false wij=dij^{alpha}
distance decay parameter for weight (default -1.0) if alpha is positive the weights will not decline with distance. If binary is True, alpha is ignored
values to use for keys of the neighbors and weights dicts
True to build sparse distance matrix and false to build dense distance matrix; significant speed gains may be obtained dending on the sparsity of the of distance_matrix and threshold that is applied
By default libpysal will print a warning if the dataset contains any disconnected observations or islands. To silence this warning set this parameter to True.
Notes
This was initially implemented running scipy 0.8.0dev (in epd 6.1). earlier versions of scipy (0.7.0) have a logic bug in scipy/sparse/dok.py so serge changed line 221 of that file on sal-dev to fix the logic bug.
Examples
>>> import libpysal
>>> points=[(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
>>> wcheck = libpysal.weights.W({0: [1, 3], 1: [0, 3], 2: [], 3: [0, 1], 4: [5], 5: [4]})
WARNING: there is one disconnected observation (no neighbors) Island id: [2] >>> w=libpysal.weights.DistanceBand(points,threshold=11.2)
WARNING: there is one disconnected observation (no neighbors) Island id: [2] >>> libpysal.weights.util.neighbor_equality(w, wcheck) True >>> w=libpysal.weights.DistanceBand(points,threshold=14.2) >>> wcheck = libpysal.weights.W({0: [1, 3], 1: [0, 3, 4], 2: [4], 3: [1, 0], 4: [5, 2, 1], 5: [4]}) >>> libpysal.weights.util.neighbor_equality(w, wcheck) True
inverse distance weights
>>> w=libpysal.weights.DistanceBand(points,threshold=11.2,binary=False)
WARNING: there is one disconnected observation (no neighbors) Island id: [2] >>> w.weights[0] [0.1, 0.08944271909999159] >>> w.neighbors[0].tolist() [1, 3]
gravity weights
>>> w=libpysal.weights.DistanceBand(points,threshold=11.2,binary=False,alpha=-2.)
WARNING: there is one disconnected observation (no neighbors) Island id: [2] >>> w.weights[0] [0.01, 0.007999999999999998]
of neighbor weights keyed by observation id
of neighbors keyed by observation id
Methods
|
Asymmetry check. |
|
Return an adjacency list representation of a weights object. |
|
Construct a DistanceBand weights from an array. |
|
Make DistanceBand weights from a dataframe. |
|
Convert a networkx graph to a PySAL W object. |
|
Distance-band based weights from shapefile |
|
Generate a full numpy array. |
|
Getter for transform property. |
|
Plot spatial weights objects. |
|
In place modification throughout W of id values from w.id_order to new_ids in all |
|
Adding meta data for writing headers of gal and gwt files. |
|
Transformations of weights. |
|
Construct a symmetric KNN weight. |
|
Generate a WSP object. |
|
Compute an adjacency list representation of a weights object. |
|
Convert a weights object to a networkx graph |
from_WSP |
|
from_file |
__init__
(self, data, threshold, p=2, alpha=-1.0, binary=True, ids=None, build_sp=True, silence_warnings=False, distance_metric='euclidean', radius=None)[source]¶Casting to floats is a work around for a bug in scipy.spatial. See detail in pysal issue #126.
Methods
|
Casting to floats is a work around for a bug in scipy.spatial. |
|
Asymmetry check. |
|
|
|
Return an adjacency list representation of a weights object. |
|
Construct a DistanceBand weights from an array. |
|
Make DistanceBand weights from a dataframe. |
|
|
|
Convert a networkx graph to a PySAL W object. |
|
Distance-band based weights from shapefile |
|
Generate a full numpy array. |
|
Getter for transform property. |
|
Plot spatial weights objects. |
|
In place modification throughout W of id values from w.id_order to new_ids in all |
|
Adding meta data for writing headers of gal and gwt files. |
|
Transformations of weights. |
|
Construct a symmetric KNN weight. |
|
Generate a WSP object. |
|
Compute an adjacency list representation of a weights object. |
|
Convert a weights object to a networkx graph |
Attributes
|
List of id pairs with asymmetric weights. |
|
Number of neighbors for each observation. |
|
Store the graph component in which each observation falls. |
|
Diagonal of \(WW\). |
|
Diagonal of \(W^{'}W\). |
|
Diagonal of \(W^{'}W + WW\). |
|
Cardinality histogram as a dictionary where key is the id and value is the number of neighbors for that unit. |
|
Dictionary where the key is an ID and the value is that ID’s index in W.id_order. |
|
Returns the ids for the observations in the order in which they would be encountered if iterating over the weights. |
|
Returns True if user has set id_order, False if not. |
|
List of ids without any neighbors. |
|
Largest number of neighbors. |
|
Average number of neighbors. |
|
Minimum number of neighbors. |
|
Number of units. |
|
Store whether the adjacency matrix is fully connected. |
|
Given the current id_order, neighbor_offsets[id] is the offsets of the id’s neighbors in id_order. |
|
Number of nonzero weights. |
|
Percentage of nonzero weights. |
|
s0 is defined as |
|
s1 is defined as |
|
s2 is defined as |
|
Individual elements comprising s2. |
|
Standard deviation of number of neighbors. |
|
Sparse matrix object. |
|
Getter for transform property. |
|
Trace of \(WW\). |
|
Trace of \(W^{'}W\). |
|
Trace of \(W^{'}W + WW\). |