jax-ml/jax · error · NotImplementedError
dynamically changing the bandwidth method is not supported
Error message
dynamically changing the bandwidth method is not supported
What it means
gaussian_kde.set_bandwidth is intentionally unimplemented in JAX: bandwidth is fixed at construction because KDE attributes are immutable (set through _setattr) to stay jit-compatible. Calling it always raises NotImplementedError.
Source
Thrown at jax/_src/scipy/stats/kde.py:229
def logpdf(self, x):
"""Log probability density function"""
check_arraylike("logpdf", x)
x = self._reshape_points(x)
result = _gaussian_kernel_eval(True, self.dataset.T, self.weights[:, None],
x.T, self.inv_cov)
return result[:, 0]
def integrate_box(self, low_bounds, high_bounds, maxpts=None):
"""This method is not implemented in the JAX interface."""
del low_bounds, high_bounds, maxpts
raise NotImplementedError(
"only 1D box integrations are supported; use `integrate_box_1d`")
def set_bandwidth(self, bw_method=None):
"""This method is not implemented in the JAX interface."""
del bw_method
raise NotImplementedError(
"dynamically changing the bandwidth method is not supported")
def _reshape_points(self, points):
if dtypes.issubdtype(lax.dtype(points), np.complexfloating):
raise NotImplementedError(
"gaussian_kde does not support complex coordinates")
points = jnp.atleast_2d(points)
d, m = points.shape
if d != self.d:
if d == 1 and m == self.d:
points = jnp.reshape(points, (self.d, 1))
else:
raise ValueError(
"points have dimension {}, dataset has dimension {}".format(
d, self.d))
return points
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Create a new gaussian_kde with the new bw_method: kde = gaussian_kde(kde.dataset, bw_method=new_bw, weights=kde.weights)
- Structure CV loops to construct a fresh KDE per bandwidth candidate
- Cache datasets/weights and reuse them when re-instantiating to keep the cost low
Example fix
// before kde.set_bandwidth(0.2) // after kde = gaussian_kde(data, bw_method=0.2, weights=w)
Defensive patterns
Strategy: fallback
Try / catch
try:
kde.set_bandwidth(bw)
except NotImplementedError:
kde = gaussian_kde(kde.dataset, bw_method=bw, weights=kde.weights) Prevention
- Treat gaussian_kde as immutable: rebuild with a new bw_method
- Write CV loops to construct fresh KDEs
- Cache dataset/weights to make re-instantiation cheap
When it happens
Trigger: Calling kde.set_bandwidth('silverman') or kde.set_bandwidth(0.3) on a JAX gaussian_kde instance.
Common situations: Porting scipy workflows that retune bandwidth after fitting; cross-validation loops that reuse a fitted KDE and only update bw_method.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- only 1D box integrations are supported; use `integrate_box_1
- gaussian_kde does not support complex coordinates
- convolve2d() only supports boundary='fill', fillvalue=0
- correlate2d() only supports boundary='fill', fillvalue=0
- overwrite_data argument not implemented.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/55d1dbfcbf7ca000.
Report an issue: GitHub.