Skip to content

Commit

Permalink
Make bootstrapping reproducible & add unit test
Browse files Browse the repository at this point in the history
Set random seed to make sampling of border units and subsequent
estimation of the spatial separation index (venables) reproducible.

Add unit test for calculating UCI with bootstrapping_border=True. The
goal of bootstrapping is to improve the estimate of the maximum spatial
separation index (venables) compared to the heuristic approach (of using
an equal distribution along the border of the area of interest). Test if
the bootstrapping approach succeeds in this regard.

Note that for small areas, e.g. the 3x3 polygon grid from the unit test,
this may not always be the case. For the given random seed it is though.
  • Loading branch information
FlorianNachtigall committed Sep 30, 2024
1 parent 625acd9 commit 9566aaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_uci.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ def test_uci_spatial_link_isolated(self):
np.testing.assert_equal(result['UCI'], np.nan)
np.testing.assert_equal(result['proximity_index'], np.nan)
self.assertAlmostEqual(result['location_coef'], 0.3809523, places=5)


def test_bootstrap_border(self):

result = uci(self.gdf, 'activities')
result_bootstrap = uci(self.gdf, 'activities', bootstrap_border=True)

self.assertGreater(result_bootstrap['spatial_separation_max'], result['spatial_separation_max']) # Bootstrapping should in most cases increase the maximum estimate of the spatial separation index
1 change: 1 addition & 0 deletions uci/uci.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def _simulate_border_values(length, n):
"""
Simulate equal value distributions along random subset of the border.
"""
np.random.seed(0)
positions = np.random.choice(range(length), size=n)
values = _create_weight_vector(length, positions)
return values
Expand Down

0 comments on commit 9566aaa

Please sign in to comment.