Skip to content

Commit fe90f44

Browse files
committed
Fix rendering issues and depencies
1 parent ad56b1d commit fe90f44

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The rules for CHANGELOG file:
1313

1414
0.3.0 (XXXX/XX/XX)
1515
------------------
16+
- Fixed moved function import from scipy and bump scipy dependency to 1.15.0 (#???)
17+
- Fix rendering issues for `SparseKDE` and `QuickShift` (#???)
1618
- Updating ``FPS`` to allow a numpy array of ints as an initialize parameter (#145)
1719
- Supported Python versions are now ranging from 3.9 - 3.12.
1820
- Updating ``skmatter.datasets`` submodule to support sklearn 1.5.0 (#229)

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ classifiers = [
3939
]
4040
dependencies = [
4141
"scikit-learn>=1.1.0",
42+
"scipy >= 1.15.0", # explicit here since need a newer version as scikit-learn
4243
]
4344
dynamic = ["version"]
4445

src/skmatter/clustering/_quick_shift.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from typing import Callable, Union
1+
from typing import Callable, Optional
22

33
import numpy as np
4-
from numpy.typing import ArrayLike
54
from sklearn.base import BaseEstimator
65
from tqdm import tqdm
76

@@ -34,19 +33,19 @@ class QuickShift(BaseEstimator):
3433
scale : float, default=1.0
3534
Distance cutoff scaling factor used during the QS clustering. It will be squared
3635
since the squared distance is used in this class.
37-
metric : Callable[[ArrayLike, ArrayLike, bool, dict], ArrayLike], \
38-
default= :func:`skmatter.metrics.pairwise_euclidean_distances()`
36+
metric : Callable, default=None
3937
The metric to use. Your metric should be able to take at least three arguments
4038
in secquence: `X`, `Y`, and `squared=True`. Here, `X` and `Y` are two array-like
4139
of shape (n_samples, n_components). The return of the metric is an array-like of
4240
shape (n_samples, n_samples). If you want to use periodic boundary
4341
conditions, be sure to provide the cell length in the ``metric_params`` and
44-
provide a metric that can take the cell argument.
42+
provide a metric that can take the cell argument. If :obj:`None`, the
43+
:func:`skmatter.metrics.periodic_pairwise_euclidean_distances()` is used.
4544
metric_params : dict, default=None
4645
Additional parameters to be passed to the use of
4746
metric. i.e. the dimension of a rectangular cell of side length :math:`a_i`
48-
for :func:`skmatter.metrics.pairwise_euclidean_distances()`
49-
`{'cell_length': [a_1, a_2, ..., a_n]}`
47+
for :func:`skmatter.metrics.periodic_pairwise_euclidean_distances()`
48+
``{'cell_length': [a_1, a_2, ..., a_n]}``
5049
5150
Attributes
5251
----------
@@ -97,13 +96,11 @@ class QuickShift(BaseEstimator):
9796

9897
def __init__(
9998
self,
100-
dist_cutoff_sq: Union[float, None] = None,
101-
gabriel_shell: Union[int, None] = None,
99+
dist_cutoff_sq: Optional[float] = None,
100+
gabriel_shell: Optional[int] = None,
102101
scale: float = 1.0,
103-
metric: Callable[
104-
[ArrayLike, ArrayLike, bool, dict], ArrayLike
105-
] = periodic_pairwise_euclidean_distances,
106-
metric_params: Union[dict, None] = None,
102+
metric: Optional[Callable] = None,
103+
metric_params: Optional[dict] = None,
107104
):
108105
if (dist_cutoff_sq is None) and (gabriel_shell is None):
109106
raise ValueError("Either dist_cutoff or gabriel_depth must be set.")
@@ -115,6 +112,10 @@ def __init__(
115112
self.metric_params = (
116113
metric_params if metric_params is not None else {"cell_length": None}
117114
)
115+
116+
if metric is None:
117+
metric = periodic_pairwise_euclidean_distances
118+
118119
self.metric = lambda X, Y: metric(X, Y, squared=True, **self.metric_params)
119120
if isinstance(self.metric_params, dict):
120121
self.cell = self.metric_params["cell_length"]

src/skmatter/neighbors/_sparsekde.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import warnings
2-
from typing import Callable, Union
2+
from typing import Callable, Optional, Union
33

44
import numpy as np
5-
from numpy.typing import ArrayLike
65
from scipy.special import logsumexp as LSE
76
from sklearn.base import BaseEstimator
87
from sklearn.utils.validation import check_is_fitted, check_random_state
@@ -33,19 +32,18 @@ class SparseKDE(BaseEstimator):
3332
weights: numpy.ndarray, default=None
3433
Weights of the descriptors.
3534
If None, all weights are set to `1/n_descriptors`.
36-
metric : Callable[[ArrayLike, ArrayLike, bool, dict], ArrayLike],
37-
default=:func:`skmatter.metrics.pairwise_euclidean_distances()`
35+
metric : Callable, default=None
3836
The metric to use. Your metric should be able to take at least three arguments
3937
in secquence: `X`, `Y`, and `squared=True`. Here, `X` and `Y` are two array-like
4038
of shape (n_samples, n_components). The return of the metric is an array-like of
41-
shape (n_samples, n_samples). If you want to use periodic boundary
42-
conditions, be sure to provide the cell size in the metric_params and
43-
provide a metric that can take the cell argument.
39+
shape (n_samples, n_samples). If you want to use periodic boundary conditions,
40+
be sure to provide the cell size in the metric_params and provide a metric that
41+
can take the cell argument. If :obj:`None`, the
42+
:func:`skmatter.metrics.periodic_pairwise_euclidean_distances()` is used.
4443
metric_params : dict, default=None
45-
Additional parameters to be passed to the use of
46-
metric. i.e. the cell dimension for
47-
:func:`skmatter.metrics.pairwise_euclidean_distances()`
48-
`{'cell_length': [side_length_1, ..., side_length_n]}`
44+
Additional parameters to be passed to the use of metric. i.e. the cell
45+
dimension for :func:`skmatter.metrics.periodic_pairwise_euclidean_distances()`
46+
``{'cell_length': [side_length_1, ..., side_length_n]}``
4947
fspread : float, default=-1.0
5048
The fractional "space" occupied by the voronoi cell of each grid. Use this when
5149
each cell is of a similar size.
@@ -106,11 +104,9 @@ class SparseKDE(BaseEstimator):
106104
def __init__(
107105
self,
108106
descriptors: np.ndarray,
109-
weights: Union[np.ndarray, None] = None,
110-
metric: Callable[
111-
[ArrayLike, ArrayLike, bool, dict], ArrayLike
112-
] = periodic_pairwise_euclidean_distances,
113-
metric_params: Union[dict, None] = None,
107+
weights: Optional[np.ndarray] = None,
108+
metric: Optional[Callable] = None,
109+
metric_params: Optional[dict] = None,
114110
fspread: float = -1.0,
115111
fpoints: float = 0.15,
116112
kernel: str = "gaussian",
@@ -119,6 +115,10 @@ def __init__(
119115
self.metric_params = (
120116
metric_params if metric_params is not None else {"cell_length": None}
121117
)
118+
119+
if metric is None:
120+
metric = periodic_pairwise_euclidean_distances
121+
122122
self.metric = lambda X, Y: metric(X, Y, squared=True, **self.metric_params)
123123
self.cell = metric_params["cell_length"] if metric_params is not None else None
124124
self._check_dimension(descriptors)

src/skmatter/sample_selection/_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
from scipy.interpolate import LinearNDInterpolator, interp1d
7-
from scipy.interpolate.interpnd import _ndim_coords_from_arrays
7+
from scipy.interpolate._interpnd import _ndim_coords_from_arrays
88
from scipy.spatial import ConvexHull
99
from sklearn.utils.validation import check_array, check_is_fitted, check_X_y
1010

0 commit comments

Comments
 (0)