{"id":29830822,"url":"https://github.com/finite-sample/hessband","last_synced_at":"2025-07-29T10:11:47.763Z","repository":{"id":305447518,"uuid":"1022912495","full_name":"finite-sample/hessband","owner":"finite-sample","description":"Analytics BW selector for univariate NW and KDE (more coming!)","archived":false,"fork":false,"pushed_at":"2025-07-20T05:54:16.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-20T07:31:26.113Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/finite-sample.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-20T05:43:56.000Z","updated_at":"2025-07-20T05:55:16.000Z","dependencies_parsed_at":"2025-07-20T07:31:32.569Z","dependency_job_id":"45bb28bd-c5a6-45bb-b7d5-d1191e74d737","html_url":"https://github.com/finite-sample/hessband","commit_stats":null,"previous_names":["finite-sample/hessband"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/finite-sample/hessband","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finite-sample%2Fhessband","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finite-sample%2Fhessband/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finite-sample%2Fhessband/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finite-sample%2Fhessband/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/finite-sample","download_url":"https://codeload.github.com/finite-sample/hessband/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finite-sample%2Fhessband/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267668843,"owners_count":24124972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-29T10:11:38.881Z","updated_at":"2025-07-29T10:11:47.751Z","avatar_url":"https://github.com/finite-sample.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hessband: Analytic Bandwidth Selector\n\n[![PyPI version](https://img.shields.io/pypi/v/hessband.svg)](https://pypi.org/project/hessband/)\n[![PyPI Downloads](https://static.pepy.tech/badge/hessband)](https://pepy.tech/projects/hessband)\n\nHessband is a Python package for selecting bandwidths in univariate smoothing.  It provides analytic gradients and Hessians of the leave‑one‑out cross‑validation (LOOCV) risk for Nadaraya–Watson regression and least‑squares cross‑validation (LSCV) for kernel density estimation (KDE).  Bandwidth selectors include grid search, plug‑in rules, finite‑difference Newton, analytic Newton, golden‑section search, and Bayesian optimisation.\n\n## Installation\n\nTo install from source, navigate to the directory containing `hessband` and run:\n\n```bash\npip install hessband-0.1.0.tar.gz\n```\n\nAlternatively, you can unpack the tarball and install using `setup.py`:\n\n```bash\ntar -xzvf hessband-0.1.0.tar.gz\ncd hessband\npip install .\n```\n\n## Usage Example\n\n```python\nimport numpy as np\nfrom hessband import select_nw_bandwidth, nw_predict\n\n# Generate synthetic data\nX = np.linspace(0, 1, 200)\ny = np.sin(2 * np.pi * X) + 0.1 * np.random.randn(200)\n\n# Select the optimal bandwidth via the analytic-Hessian method\nh_opt = select_nw_bandwidth(X, y, method='analytic', kernel='gaussian')\n\n# Predict on the original points\ny_pred = nw_predict(X, y, X, h_opt)\n\nprint(\"Selected bandwidth:\", h_opt)\nprint(\"Mean squared error:\", np.mean((y_pred - np.sin(2 * np.pi * X)) ** 2))\n```\n\nWhen running the example above, you should see a selected bandwidth around `0.16` and a mean squared error close to `8e-4`. Results may vary slightly due to randomness in the synthetic data.\n\n### KDE Example\n\nThe package also supports bandwidth selection for univariate kernel density estimation using least‑squares cross‑validation (LSCV).  For example:\n\n```python\nimport numpy as np\nfrom hessband import select_kde_bandwidth\n\n# Sample data from a bimodal distribution\nx = np.concatenate([\n    np.random.normal(-2, 0.5, 200),\n    np.random.normal(2, 1.0, 200),\n])\n\n# Select bandwidth using analytic Newton for the Gaussian kernel\nh_kde = select_kde_bandwidth(x, kernel='gauss', method='analytic')\nprint(\"Selected KDE bandwidth:\", h_kde)\n```\n\nThe `select_kde_bandwidth` function also supports Epanechnikov kernels (`kernel='epan'`), grid search (`method='grid'`) and golden‑section optimisation (`method='golden'`).\n\n## Simulation Results\n\nIn the accompanying paper, we compared several bandwidth selectors using simulated data from a bimodal mixture regression model. A subset of the results for the Gaussian kernel with noise level `0.1` and sample size `200` is given below:\n\n| Method               | MSE (×10⁻³)       | CV evaluations |\n|----------------------|-------------------|---------------|\n| Grid                 | 0.87 ± 0.12       | 150 ± 0       |\n| Plug-in              | 6.31 ± 0.57       | 5 ± 0         |\n| Finite-diff Newton   | 6.31 ± 0.57       | 20 ± 0        |\n| **Analytic Newton**  | **0.86 ± 0.13**   | **0 ± 0**     |\n| Golden               | 0.86 ± 0.13       | 85 ± 0        |\n| Bayes                | 0.87 ± 0.14       | 75 ± 0        |\n\nThe analytic-Hessian method matches the accuracy of exhaustive grid search while requiring essentially no cross-validation evaluations.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinite-sample%2Fhessband","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinite-sample%2Fhessband","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinite-sample%2Fhessband/lists"}