{"id":20013752,"url":"https://github.com/gregorybchris/hlucb","last_synced_at":"2025-03-02T02:25:23.982Z","repository":{"id":62569357,"uuid":"438582622","full_name":"gregorybchris/hlucb","owner":"gregorybchris","description":"Implementation of Hamming-LUCB algorithm for approximate sorting","archived":false,"fork":false,"pushed_at":"2023-02-12T22:09:34.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-12T15:12:42.233Z","etag":null,"topics":["algorithm","approximate","confidence","hamming","lucb","sorting"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/hlucb/","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/gregorybchris.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}},"created_at":"2021-12-15T10:10:39.000Z","updated_at":"2024-09-25T03:55:11.000Z","dependencies_parsed_at":"2024-11-13T07:37:49.802Z","dependency_job_id":"24fa5093-a140-4f4c-afcb-00a10d56a55f","html_url":"https://github.com/gregorybchris/hlucb","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.4285714285714286,"last_synced_commit":"f9c95d155246ae7d34039c91210bd110c5fb7dc2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorybchris%2Fhlucb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorybchris%2Fhlucb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorybchris%2Fhlucb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorybchris%2Fhlucb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregorybchris","download_url":"https://codeload.github.com/gregorybchris/hlucb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241448396,"owners_count":19964462,"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","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":["algorithm","approximate","confidence","hamming","lucb","sorting"],"created_at":"2024-11-13T07:37:45.446Z","updated_at":"2025-03-02T02:25:23.952Z","avatar_url":"https://github.com/gregorybchris.png","language":"Python","readme":"# Hamming-LUCB\n\nThe `hlucb` package is a Python implementation of the paper [Approximate ranking from pairwise comparisons](http://proceedings.mlr.press/v84/heckel18a.html).\n\n\u003e Heckel, R., Simchowitz, M., Ramchandran, K., \u0026 Wainwright, M. (2018, March). Approximate ranking from pairwise comparisons. In International Conference on Artificial Intelligence and Statistics (pp. 1057-1066). PMLR.\n\n## Installation\n\n`hlucb` is installable with pip:\n\n```bash\n$ pip install hlucb\n```\n\n## Usage\n\n### Ranking with a comparator\n\n```python\nfrom hlucb import HammingLUCB\n\nitems = [4, 1, 2, 6, 5, 8, 9, 3]\nk = 5\nh = 2\ndelta = 0.9\n\ndef compare(item_a: int, item_b: int) -\u003e bool:\n    return item_a \u003e item_b\n\nscores, bounds = HammingLUCB.from_comparator(items, k, h, delta, compare, seed=42)\n\nprint(\"Scores: \", scores)\nprint(\"Bounds: \", bounds)\n```\n\n### Ranking with a generator\n\n```python\nfrom hlucb import HammingLUCB\n\nitems = [4, 1, 2, 6, 5, 8, 9, 3]\nn = len(items)\nk = 5\nh = 2\ndelta = 0.9\n\ngenerator = HammingLUCB.get_generator(n, k, h, delta, seed=42)\nscores = None\nbounds = None\nfor (i, j), (scores, bounds) in generator:\n    comparison = items[i] \u003e items[j]\n    generator.send(comparison)\n\nprint(\"Scores: \", scores)\nprint(\"Bounds: \", bounds)\n```\n\n## Intuition\n\nThe Hamming-LUCB algorithm approximately ranks $n$ items, estimates the score of each item, and provides confidence bounds for each score. The intuition behind the approximate ranking is that it's easier to compare items with very different scores, so it should be possible to separate high-scoring items from low-scoring items with few comparisons and high confidence even if the exact ranking is not discovered.\n\nThe sets of high- and low-scoring items are designated $S_1$ and $S_2$ respectively. Hamming-LUCB extracts $S_1$ and $S_2$ such that all items in $S_1$ are expected to have higher scores than all items in $S_2$.\n\nParameters:\n\n- $n$ - the total number of items\n- $k$ - the number of items to extract as high-scoring items\n- $h$ - half the margin between $S_1$ and $S_2$\n- $\\delta$ - confidence parameter for the probability of achieving $h$-Hamming accuracy\n\nDefinitions:\n\n- The Hamming distance between two sets: $D_H(S_1, S_2) = \\lvert (S_1 \\cup S_2) \\setminus (S_1 \\cap S_2) \\rvert$\n- A ranking $\\hat{S_1}$, $\\hat{S_2}$ is $h$-Hamming accurate if: $D_H(\\hat{S_l}, S_l) \\leq 2h$ for\n  - $\\lvert \\hat{S_l} \\rvert = \\lvert S_l \\rvert$\n  - $l \\in \\{1, 2\\}$\n- A ranking algorithm is $(h, \\delta)$-accurate if the ranking returned is $h$-Hamming accurate with probability at least $1 - \\delta$.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorybchris%2Fhlucb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregorybchris%2Fhlucb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorybchris%2Fhlucb/lists"}