{"record":{"id":"55d1dbfcbf7ca000","repo":"jax-ml/jax","slug":"dynamically-changing-the-bandwidth-method-is-not-s","errorCode":null,"errorMessage":"dynamically changing the bandwidth method is not supported","messagePattern":"dynamically changing the bandwidth method is not supported","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/stats/kde.py","lineNumber":229,"sourceCode":"\n  def logpdf(self, x):\n    \"\"\"Log probability density function\"\"\"\n    check_arraylike(\"logpdf\", x)\n    x = self._reshape_points(x)\n    result = _gaussian_kernel_eval(True, self.dataset.T, self.weights[:, None],\n                                   x.T, self.inv_cov)\n    return result[:, 0]\n\n  def integrate_box(self, low_bounds, high_bounds, maxpts=None):\n    \"\"\"This method is not implemented in the JAX interface.\"\"\"\n    del low_bounds, high_bounds, maxpts\n    raise NotImplementedError(\n        \"only 1D box integrations are supported; use `integrate_box_1d`\")\n\n  def set_bandwidth(self, bw_method=None):\n    \"\"\"This method is not implemented in the JAX interface.\"\"\"\n    del bw_method\n    raise NotImplementedError(\n        \"dynamically changing the bandwidth method is not supported\")\n\n  def _reshape_points(self, points):\n    if dtypes.issubdtype(lax.dtype(points), np.complexfloating):\n      raise NotImplementedError(\n          \"gaussian_kde does not support complex coordinates\")\n    points = jnp.atleast_2d(points)\n    d, m = points.shape\n    if d != self.d:\n      if d == 1 and m == self.d:\n        points = jnp.reshape(points, (self.d, 1))\n      else:\n        raise ValueError(\n            \"points have dimension {}, dataset has dimension {}\".format(\n                d, self.d))\n    return points\n\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/stats/kde.py#L211-L247","documentation":"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.","triggerScenarios":"Calling kde.set_bandwidth('silverman') or kde.set_bandwidth(0.3) on a JAX gaussian_kde instance.","commonSituations":"Porting scipy workflows that retune bandwidth after fitting; cross-validation loops that reuse a fitted KDE and only update bw_method.","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"],"exampleFix":"// before\nkde.set_bandwidth(0.2)\n// after\nkde = gaussian_kde(data, bw_method=0.2, weights=w)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    kde.set_bandwidth(bw)\nexcept NotImplementedError:\n    kde = gaussian_kde(kde.dataset, bw_method=bw, weights=kde.weights)","preventionTips":["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"],"tags":["jax","scipy","kde","not-implemented","api-parity"],"backgroundTag":"unsupported-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}