Skip to content

Commit

Permalink
comment out unused WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Jul 18, 2023
1 parent 30bca0b commit 88fb4b6
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 169 deletions.
179 changes: 89 additions & 90 deletions libpysal/weights/experimental/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,92 @@
- check two tree types
- scikit/no scikit
"""
import pandas, geopandas, geodatasets, pytest, shapely, numpy
from libpysal.weights.experimental._kernel import (
kernel,
knn,
_optimize_bandwidth,
_kernel_functions
)

grocs = geopandas.read_file(
geodatasets.get_path("geoda groceries")
)[['OBJECTID', 'geometry']]
grocs['strID'] = grocs.OBJECTID.astype(str)
grocs['intID'] = grocs.OBJECTID.values

kernel_functions = list(_kernel_functions.keys())

def my_kernel(distances, bandwidth):
output = numpy.cos(distances/distances.max())
output[distances < bandwidth] = 0
return output

kernel_functions.append(my_kernel)

metrics = ("euclidean", "haversine")

# optimal, small, and larger than largest distance.
# the optimal bandwidth should be smaller than the
# max distance for all kernels except identity
bandwidth = [None, .05, .4]

numpy.random.seed(6301)
# create a 2-d laplace distribution as a "degenerate"
# over-concentrated distribution
# and rescale to match the lenght-scale in groceries
lap_coords = numpy.random.laplace(size=(200,2)) / 50

# create a 2-d cauchy as a "degenerate"
# spatial outlier-y distribution
# cau_coords = numpy.random.standard_cauchy(size=(200,2))

data = (
grocs,
lap_coords
)

parametrize_ids = pytest.mark.parametrize("ids", [None, "strID", "intID"])
parametrize_data = pytest.mark.parametrize("data", [grocs, lap_coords, cau_coords], ["groceries", "coords: 2d-laplacian"])
parametrize_kernelfunctions = pytest.mark.parametrize(
"kernel",
kernel_functions,
kernel_functions[:-2] + ['None', 'custom callable']
)
parametrize_metrics = pytest.mark.parametrize(
"metric",
metrics,
metrics
)
parametrize_bw = pytest.mark.parametrize(
"bandwidth",
bandwidth,
['optimal', 'small', 'large']
)

# how do we parameterize conditional on sklearn in env?

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@parametrize_metrics
@paramterize_bw
def test_kernel(data, ids, kernel, metric, bandwidth):
raise NotImplementedError()

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@parametrize_metrics
@paramterize_bw
def test_knn(data, ids, kernel, metric, bandwidth):
raise NotImplementedError()

@parametrize_ids
@parametrize_data
def test_precomputed(data, ids):
raise NotImplementedError()

@parametrize_data
def test_coincident(data):
raise NotImplementedError()

# import pandas, geopandas, geodatasets, pytest, shapely, numpy
# from libpysal.weights.experimental._kernel import (
# kernel,
# knn,
# _optimize_bandwidth,
# _kernel_functions
# )

# grocs = geopandas.read_file(
# geodatasets.get_path("geoda groceries")
# )[['OBJECTID', 'geometry']]
# grocs['strID'] = grocs.OBJECTID.astype(str)
# grocs['intID'] = grocs.OBJECTID.values

# kernel_functions = list(_kernel_functions.keys())

# def my_kernel(distances, bandwidth):
# output = numpy.cos(distances/distances.max())
# output[distances < bandwidth] = 0
# return output

# kernel_functions.append(my_kernel)

# metrics = ("euclidean", "haversine")

# # optimal, small, and larger than largest distance.
# # the optimal bandwidth should be smaller than the
# # max distance for all kernels except identity
# bandwidth = [None, .05, .4]

# numpy.random.seed(6301)
# # create a 2-d laplace distribution as a "degenerate"
# # over-concentrated distribution
# # and rescale to match the lenght-scale in groceries
# lap_coords = numpy.random.laplace(size=(200,2)) / 50

# # create a 2-d cauchy as a "degenerate"
# # spatial outlier-y distribution
# # cau_coords = numpy.random.standard_cauchy(size=(200,2))

# data = (
# grocs,
# lap_coords
# )

# parametrize_ids = pytest.mark.parametrize("ids", [None, "strID", "intID"])
# parametrize_data = pytest.mark.parametrize("data", [grocs, lap_coords, cau_coords], ["groceries", "coords: 2d-laplacian"])
# parametrize_kernelfunctions = pytest.mark.parametrize(
# "kernel",
# kernel_functions,
# kernel_functions[:-2] + ['None', 'custom callable']
# )
# parametrize_metrics = pytest.mark.parametrize(
# "metric",
# metrics,
# metrics
# )
# parametrize_bw = pytest.mark.parametrize(
# "bandwidth",
# bandwidth,
# ['optimal', 'small', 'large']
# )

# # how do we parameterize conditional on sklearn in env?

# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @parametrize_metrics
# @paramterize_bw
# def test_kernel(data, ids, kernel, metric, bandwidth):
# raise NotImplementedError()

# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @parametrize_metrics
# @paramterize_bw
# def test_knn(data, ids, kernel, metric, bandwidth):
# raise NotImplementedError()

# @parametrize_ids
# @parametrize_data
# def test_precomputed(data, ids):
# raise NotImplementedError()

# @parametrize_data
# def test_coincident(data):
# raise NotImplementedError()
158 changes: 79 additions & 79 deletions libpysal/weights/experimental/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,101 @@
- point dataframe
- coordinates
- check two kernel functions
- numba/nonumba
- numba/nonumba
"""
import pandas, geopandas, geodatasets, pytest, shapely, numpy
from libpysal.weights.experimental._triangulation import (
delaunay,
gabriel,
relative_neighborhood,
voronoi
delaunay,
gabriel,
relative_neighborhood,
voronoi,
)

### TODO: is there any way to remove this duplication
### btw. test_triangulation and test_kernel using the
### conftests.py? We need the same data/kernel combos
### and also need to parameterize on numba existing,
### and also have to test coincident points.
# ### TODO: is there any way to remove this duplication
# ### btw. test_triangulation and test_kernel using the
# ### conftests.py? We need the same data/kernel combos
# ### and also need to parameterize on numba existing,
# ### and also have to test coincident points.

grocs = geopandas.read_file(
geodatasets.get_path("geoda groceries")
)[['OBJECTID', 'geometry']]
grocs['strID'] = grocs.OBJECTID.astype(str)
grocs['intID'] = grocs.OBJECTID.values
# grocs = geopandas.read_file(
# geodatasets.get_path("geoda groceries")
# )[['OBJECTID', 'geometry']]
# grocs['strID'] = grocs.OBJECTID.astype(str)
# grocs['intID'] = grocs.OBJECTID.values

kernel_functions = list(_kernel_functions.keys())
# kernel_functions = list(_kernel_functions.keys())

def my_kernel(distances, bandwidth):
output = numpy.cos(distances/distances.max())
output[distances < bandwidth] = 0
return output
# def my_kernel(distances, bandwidth):
# output = numpy.cos(distances/distances.max())
# output[distances < bandwidth] = 0
# return output

kernel_functions.append(my_kernel)
# kernel_functions.append(my_kernel)

# optimal, small, and larger than largest distance.
# the optimal bandwidth should be smaller than the
# max distance for all kernels except identity
bandwidths = [None, .05, .4]
# # optimal, small, and larger than largest distance.
# # the optimal bandwidth should be smaller than the
# # max distance for all kernels except identity
# bandwidths = [None, .05, .4]

numpy.random.seed(6301)
# create a 2-d laplace distribution as a "degenerate"
# over-concentrated distribution
lap_coords = numpy.random.laplace(size=(200,2))
# numpy.random.seed(6301)
# # create a 2-d laplace distribution as a "degenerate"
# # over-concentrated distribution
# lap_coords = numpy.random.laplace(size=(200,2))

# create a 2-d cauchy as a "degenerate"
# spatial outlier-y distribution
# cau_coords = numpy.random.standard_cauchy(size=(200,2))
# # create a 2-d cauchy as a "degenerate"
# # spatial outlier-y distribution
# # cau_coords = numpy.random.standard_cauchy(size=(200,2))

data = (
grocs,
lap_coords
)
# data = (
# grocs,
# lap_coords
# )

parametrize_ids = pytest.mark.parametrize("ids", [None, "strID", "intID"])
parametrize_data = pytest.mark.parametrize("data", [grocs, lap_coords, cau_coords], ["groceries", "coords: 2d-laplacian"])
parametrize_kernelfunctions = pytest.mark.parametrize(
"kernel",
kernel_functions,
kernel_functions[:-2] + ['None', 'custom callable']
)
parametrize_bw = pytest.mark.parametrize(
"bandwidth",
bandwidth,
['optimal', 'small', 'large']
)
paramterize_graphs = pytest.mark.parametrize(
"graphtype",
(delaunay, gabriel, relative_neighborhood, voronoi),
['delaunay', 'gabriel' 'relative_neighborhood', 'voronoi']
)
# parametrize_ids = pytest.mark.parametrize("ids", [None, "strID", "intID"])
# parametrize_data = pytest.mark.parametrize("data", [grocs, lap_coords, cau_coords], ["groceries", "coords: 2d-laplacian"])
# parametrize_kernelfunctions = pytest.mark.parametrize(
# "kernel",
# kernel_functions,
# kernel_functions[:-2] + ['None', 'custom callable']
# )
# parametrize_bw = pytest.mark.parametrize(
# "bandwidth",
# bandwidth,
# ['optimal', 'small', 'large']
# )
# paramterize_graphs = pytest.mark.parametrize(
# "graphtype",
# (delaunay, gabriel, relative_neighborhood, voronoi),
# ['delaunay', 'gabriel' 'relative_neighborhood', 'voronoi']
# )

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@paramterize_bw
def test_voronoi(data, ids, kernel, bandwidth):
raise NotImplementedError()
# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @paramterize_bw
# def test_voronoi(data, ids, kernel, bandwidth):
# raise NotImplementedError()

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@paramterize_bw
def test_delaunay(data, ids, kernel, bandwidth):
raise NotImplementedError()
# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @paramterize_bw
# def test_delaunay(data, ids, kernel, bandwidth):
# raise NotImplementedError()

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@paramterize_bw
def test_gabriel(data, ids, kernel, bandwidth):
raise NotImplementedError()
# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @paramterize_bw
# def test_gabriel(data, ids, kernel, bandwidth):
# raise NotImplementedError()

@parametrize_ids
@parametrize_data
@parametrize_kernelfunctions
@paramterize_bw
def test_relative_neighborhood(data, ids, kernel, bandwidth):
raise NotImplementedError()
# @parametrize_ids
# @parametrize_data
# @parametrize_kernelfunctions
# @paramterize_bw
# def test_relative_neighborhood(data, ids, kernel, bandwidth):
# raise NotImplementedError()

@paramterize_graphs
def test_collinear()
# @paramterize_graphs
# def test_collinear()

0 comments on commit 88fb4b6

Please sign in to comment.