New in version 1.0.
Max p regionalization
Heuristically form the maximum number (p) of regions given a set of n areas and a floor constraint.
Try to find the maximum number of regions for a set of areas such that each region combines continguous areas that satisfy a given threshold constraint.
| Parameters: | w : W
z : array
floor : int
floor_variable : array
initial : int number of initial solutions to generate verbose : binary
seeds : list
|
|---|
Examples
>>> import random
>>> import numpy as np
>>> random.seed(100)
>>> np.random.seed(100)
>>> w=pysal.lat2W(10,10)
>>> z=np.random.random_sample((w.n,2))
>>> p=np.random.random(w.n)*100
>>> p=np.ones((w.n,1),float)
>>> floor=3
>>> solution=Maxp(w,z,floor,floor_variable=p,initial=100)
>>> solution.p
30
>>> solution.regions[0]
[49, 39, 29]
>>>
Attributes
| area2region | dict | mapping of areas to region. key is area id, value is region id |
| regions | list | list of lists of regions (each list has the ids of areas in that region) |
| swap_iterations | int | number of swap iterations |
| total_moves | int | number of moves into internal regions |
Methods
| check_floor | |
| cinference | |
| inference | |
| initial_solution | |
| objective_function | |
| swap |
Compare the within sum of squares for the solution against conditional simulated solutions where areas are randomly assigned to regions that maintain the cardinality of the original solution and respect contiguity relationships.
| Parameters: | nperm : int
maxiter : int
|
|---|
Notes
it is possible for the number of feasible solutions (feas_sols) to be less than the number of permutations requested (nperm); an exception is raised if this occurs.
Examples
>>> import random
>>> import numpy as np
>>> random.seed(100)
>>> np.random.seed(100)
>>> w=pysal.weights.lat2W(5,5)
>>> z=np.random.random_sample((w.n,2))
>>> p=np.random.random(w.n)*100
>>> p=np.ones((w.n,1),float)
>>> floor=3
>>> solution=Maxp(w,z,floor,floor_variable=p,initial=100)
>>> solution.cinference(nperm=9, maxiter=100)
>>> solution.cpvalue
0.10000000000000001
Attributes
| pvalue | float | pseudo p_value |
| feas_sols | int | number of feasible solutions found |
Compare the within sum of squares for the solution against simulated solutions where areas are randomly assigned to regions that maintain the cardinality of the original solution.
| Parameters: | nperm : int
|
|---|
Examples
>>> import random
>>> import numpy as np
>>> random.seed(100)
>>> np.random.seed(100)
>>> w=pysal.weights.lat2W(5,5)
>>> z=np.random.random_sample((w.n,2))
>>> p=np.random.random(w.n)*100
>>> p=np.ones((w.n,1),float)
>>> floor=3
>>> solution=Maxp(w,z,floor,floor_variable=p,initial=100)
>>> solution.inference(nperm=9)
>>> solution.pvalue
0.29999999999999999
Attributes
| pvalue | float | pseudo p_value |
Max-p regionalization using LISA seeds
| Parameters: | w : W
z : array
y : array
floor : float
floor_variable : array
initial : int
|
|---|
Notes
We sort the observations based on the value of the LISAs. This ordering then gives the priority for seeds forming the p regions. The initial priority seeds are not guaranteed to be separated in the final solution.
Examples
>>> import random
>>> import numpy as np
>>> random.seed(100)
>>> np.random.seed(100)
>>> w=pysal.lat2W(10,10)
>>> z=np.random.random_sample((w.n,2))
>>> y=np.arange(w.n)
>>> p=np.ones((w.n,1),float)
>>> mpl=Maxp_LISA(w,z,y,floor=3,floor_variable=p)
Note random components result is slightly different values across architectures so the results have been removed from doctests and will be moved into unittests that are conditional on architectures
Attributes
| area2region | dict | mapping of areas to region. key is area id, value is region id |
| regions | list | list of lists of regions (each list has the ids of areas in that region) |
| swap_iterations | int | number of swap iterations |
| total_moves | int | number of moves into internal regions |