Skip to content

Commit e9e4381

Browse files
committed
add start of testing specifications
1 parent fab6231 commit e9e4381

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

esda/tests/test_moran_local_mv.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import numpy
2+
import geodatasets
3+
import geopandas
4+
from libpysal.weights import Queen
5+
from sklearn.linear_model import TheilSenRegressor
6+
from esda.multivariate_moran import Partial_Moran_Local, Auxiliary_Moran_Local
7+
8+
df = geopandas.read_file(geodatasets.get_path("geoda.lansing1"))
9+
df = df[df.FIPS.str.match("2606500[01234]...") | (df.FIPS == "26065006500")]
10+
11+
y = df.HH_INC.values
12+
X = df.HSG_VAL.values
13+
w = Queen.from_dataframe(df)
14+
15+
def test_partial_runs():
16+
"""Check if the class computes successfully in a default configuration"""
17+
m = Partial_Moran_Local(y,X,w, permutations=1)
18+
# done, just check if it runs
19+
20+
def test_partial_accuracy():
21+
"""Check if the class outputs expected results at a given seed"""
22+
numpy.random.seed(111221)
23+
m = Partial_Moran_Local(y,X,w, permutations=10)
24+
# compute result by hand
25+
26+
def test_partial_unscaled():
27+
"""Check if the variance scaling behaves as expected"""
28+
m = Partial_Moran_Local(y,X,w, permutations=0, unit_scale=True)
29+
m2 = Partial_Moran_Local(y,X,w, permutations=0, unit_scale=False)
30+
# variance in the partials_ should be different
31+
32+
def test_partial_uvquads():
33+
"""Check that the quadrant decisions vary correctly with the inputs"""
34+
m = Partial_Moran_Local(y,X,w, permutations=0, mvquads=False)
35+
...
36+
37+
def test_aux_runs():
38+
"""Check that the class completes successfully in a default configuration"""
39+
m = Auxiliary_Moran_Local(y,X,w, permutations=1)
40+
...
41+
42+
def test_aux_accuracy():
43+
"""Check that the class outputs expected values for a given seed"""
44+
numpy.random.seed(111221)
45+
m = Auxiliary_Moran_Local(y,X,w, permutations=10)
46+
...
47+
48+
def test_aux_unscaled():
49+
"""Check that the variance scaling behaves as expected"""
50+
m = Auxiliary_Moran_Local(y,X,w, permutations=0, unit_scale=True)
51+
m2 = Auxiliary_Moran_Local(y,X,w, permutations=0, unit_scale=False)
52+
...
53+
54+
def test_aux_transformer():
55+
"""Check that an alternative regressor can be used to calculate y|X"""
56+
m = Auxiliary_Moran_Local(y,X,w, permutations=0, transformer=TheilSenRegressor)
57+
...

0 commit comments

Comments
 (0)