Skip to content

Commit

Permalink
add start of testing specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwolf committed Jul 4, 2024
1 parent fab6231 commit e9e4381
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions esda/tests/test_moran_local_mv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import numpy
import geodatasets
import geopandas
from libpysal.weights import Queen
from sklearn.linear_model import TheilSenRegressor
from esda.multivariate_moran import Partial_Moran_Local, Auxiliary_Moran_Local

df = geopandas.read_file(geodatasets.get_path("geoda.lansing1"))
df = df[df.FIPS.str.match("2606500[01234]...") | (df.FIPS == "26065006500")]

y = df.HH_INC.values
X = df.HSG_VAL.values
w = Queen.from_dataframe(df)

def test_partial_runs():
"""Check if the class computes successfully in a default configuration"""
m = Partial_Moran_Local(y,X,w, permutations=1)
# done, just check if it runs

def test_partial_accuracy():
"""Check if the class outputs expected results at a given seed"""
numpy.random.seed(111221)
m = Partial_Moran_Local(y,X,w, permutations=10)
# compute result by hand

def test_partial_unscaled():
"""Check if the variance scaling behaves as expected"""
m = Partial_Moran_Local(y,X,w, permutations=0, unit_scale=True)
m2 = Partial_Moran_Local(y,X,w, permutations=0, unit_scale=False)
# variance in the partials_ should be different

def test_partial_uvquads():
"""Check that the quadrant decisions vary correctly with the inputs"""
m = Partial_Moran_Local(y,X,w, permutations=0, mvquads=False)
...

def test_aux_runs():
"""Check that the class completes successfully in a default configuration"""
m = Auxiliary_Moran_Local(y,X,w, permutations=1)
...

def test_aux_accuracy():
"""Check that the class outputs expected values for a given seed"""
numpy.random.seed(111221)
m = Auxiliary_Moran_Local(y,X,w, permutations=10)
...

def test_aux_unscaled():
"""Check that the variance scaling behaves as expected"""
m = Auxiliary_Moran_Local(y,X,w, permutations=0, unit_scale=True)
m2 = Auxiliary_Moran_Local(y,X,w, permutations=0, unit_scale=False)
...

def test_aux_transformer():
"""Check that an alternative regressor can be used to calculate y|X"""
m = Auxiliary_Moran_Local(y,X,w, permutations=0, transformer=TheilSenRegressor)
...

0 comments on commit e9e4381

Please sign in to comment.