unirating 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unirating-0.1.0/.gitignore +51 -0
- unirating-0.1.0/CHANGELOG.md +21 -0
- unirating-0.1.0/LICENSE +21 -0
- unirating-0.1.0/PKG-INFO +236 -0
- unirating-0.1.0/README.md +174 -0
- unirating-0.1.0/docs/citations.md +126 -0
- unirating-0.1.0/docs/derivation.md +317 -0
- unirating-0.1.0/examples/basic_usage.py +31 -0
- unirating-0.1.0/examples/missing_ratings.py +69 -0
- unirating-0.1.0/pyproject.toml +117 -0
- unirating-0.1.0/src/unirating/__init__.py +35 -0
- unirating-0.1.0/src/unirating/_version.py +1 -0
- unirating-0.1.0/src/unirating/calibration.py +103 -0
- unirating-0.1.0/src/unirating/cli.py +113 -0
- unirating-0.1.0/src/unirating/exceptions.py +35 -0
- unirating-0.1.0/src/unirating/fusion.py +161 -0
- unirating-0.1.0/src/unirating/models.py +143 -0
- unirating-0.1.0/src/unirating/py.typed +0 -0
- unirating-0.1.0/tests/__init__.py +0 -0
- unirating-0.1.0/tests/test_calibration.py +74 -0
- unirating-0.1.0/tests/test_cli.py +66 -0
- unirating-0.1.0/tests/test_fusion.py +277 -0
- unirating-0.1.0/tests/test_models.py +97 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
.Python
|
|
8
|
+
build/
|
|
9
|
+
develop-eggs/
|
|
10
|
+
dist/
|
|
11
|
+
downloads/
|
|
12
|
+
eggs/
|
|
13
|
+
.eggs/
|
|
14
|
+
lib/
|
|
15
|
+
lib64/
|
|
16
|
+
parts/
|
|
17
|
+
sdist/
|
|
18
|
+
var/
|
|
19
|
+
wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
*.egg
|
|
22
|
+
MANIFEST
|
|
23
|
+
|
|
24
|
+
# Unit test / coverage reports
|
|
25
|
+
htmlcov/
|
|
26
|
+
.tox/
|
|
27
|
+
.coverage
|
|
28
|
+
.coverage.*
|
|
29
|
+
.cache
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
.hypothesis/
|
|
32
|
+
coverage.xml
|
|
33
|
+
*.cover
|
|
34
|
+
|
|
35
|
+
# mypy / ruff
|
|
36
|
+
.mypy_cache/
|
|
37
|
+
.ruff_cache/
|
|
38
|
+
|
|
39
|
+
# Editors
|
|
40
|
+
.vscode/
|
|
41
|
+
.idea/
|
|
42
|
+
*.swp
|
|
43
|
+
|
|
44
|
+
# OS
|
|
45
|
+
.DS_Store
|
|
46
|
+
Thumbs.db
|
|
47
|
+
|
|
48
|
+
# Virtual envs
|
|
49
|
+
.venv/
|
|
50
|
+
venv/
|
|
51
|
+
env/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-06-13
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Initial release.
|
|
11
|
+
- Bayesian inverse-variance fusion of FIDE, Chess.com and Lichess ratings.
|
|
12
|
+
- `Rating`, `Prior`, `Calibration`, `TimeControl`, `FusionResult` data models.
|
|
13
|
+
- `fuse()` entry point with full edge-case coverage:
|
|
14
|
+
no ratings, single rating, missing sigma, provisional ratings,
|
|
15
|
+
invalid inputs, custom priors, custom calibration.
|
|
16
|
+
- Default per-time-control calibration constants
|
|
17
|
+
(Bullet / Blitz / Rapid / Classical).
|
|
18
|
+
- Command-line interface (`unirating`).
|
|
19
|
+
- Full mathematical derivation with proof (MLE, Gauss–Markov, Bayes).
|
|
20
|
+
- Citations document.
|
|
21
|
+
- Test suite (unit + property-based via Hypothesis).
|
unirating-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sourav Sahu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
unirating-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unirating
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bayesian inverse-variance fusion of FIDE, Chess.com and Lichess ratings into a single FIDE-scale rating.
|
|
5
|
+
Project-URL: Homepage, https://github.com/souravsahums/unirating
|
|
6
|
+
Project-URL: Documentation, https://github.com/souravsahums/unirating#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/souravsahums/unirating/issues
|
|
8
|
+
Project-URL: Source, https://github.com/souravsahums/unirating
|
|
9
|
+
Author-email: Sourav Sahu <souravsahu@duck.com>
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 Sourav Sahu
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: bayesian,chess,chess.com,elo,fide,glicko,lichess,meta-analysis,rating,sensor-fusion
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Intended Audience :: Science/Research
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
45
|
+
Classifier: Topic :: Games/Entertainment :: Board Games
|
|
46
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
47
|
+
Classifier: Typing :: Typed
|
|
48
|
+
Requires-Python: >=3.9
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
51
|
+
Requires-Dist: hypothesis>=6; extra == 'dev'
|
|
52
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
53
|
+
Requires-Dist: pytest-cov>=4; extra == 'dev'
|
|
54
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
55
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
56
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
57
|
+
Provides-Extra: test
|
|
58
|
+
Requires-Dist: hypothesis>=6; extra == 'test'
|
|
59
|
+
Requires-Dist: pytest-cov>=4; extra == 'test'
|
|
60
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
61
|
+
Description-Content-Type: text/markdown
|
|
62
|
+
|
|
63
|
+
# unirating
|
|
64
|
+
|
|
65
|
+
[](https://www.python.org/downloads/)
|
|
66
|
+
[](LICENSE)
|
|
67
|
+
|
|
68
|
+
> Author: **Sourav Sahu** ([@souravsahums](https://github.com/souravsahums))
|
|
69
|
+
|
|
70
|
+
Bayesian inverse-variance **fusion** of a player's **FIDE**, **Chess.com** and **Lichess** ratings into a single number on the **FIDE scale**, with proper handling of missing ratings, calibrated per time control.
|
|
71
|
+
|
|
72
|
+
The estimator is the **maximum-likelihood / Best Linear Unbiased Estimator** (Gauss–Markov) when all sources are present, and the **posterior mean of a Gaussian–Gaussian Bayesian model** when one or more sources are missing — so a player with no ratings at all gracefully degrades to the population prior (the "base rating") rather than crashing.
|
|
73
|
+
|
|
74
|
+
Full mathematical derivation with proof: [docs/derivation.md](docs/derivation.md).
|
|
75
|
+
Citations: [docs/citations.md](docs/citations.md).
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Install
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install unirating
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Zero runtime dependencies. Python 3.9+.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Quick start
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from unirating import Rating, TimeControl, fuse
|
|
93
|
+
|
|
94
|
+
result = fuse(
|
|
95
|
+
fide = Rating(value=1820, sigma=60), # FIDE Rapid, settled
|
|
96
|
+
chesscom = Rating(value=1950, sigma=55), # Chess.com Rapid, RD=55
|
|
97
|
+
lichess = Rating(value=2100, sigma=50), # Lichess Rapid, RD=50
|
|
98
|
+
time_control = TimeControl.RAPID,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
print(result.rating) # 1838.95 (FIDE scale)
|
|
102
|
+
print(result.sigma) # 31.36 (1-sigma uncertainty)
|
|
103
|
+
print(result.ci95) # (1777.5, 1900.4)
|
|
104
|
+
print(result.contributions) # per-source weight share, sums to 1.0
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A player with no ratings at all:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from unirating import fuse, TimeControl
|
|
111
|
+
|
|
112
|
+
result = fuse(time_control=TimeControl.RAPID)
|
|
113
|
+
print(result.rating) # 1500.0 (prior mean — the "base rating")
|
|
114
|
+
print(result.sigma) # 350.0 (prior std-dev — full uncertainty)
|
|
115
|
+
print(result.is_prior_only) # True
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Lichess gives you the RD directly via API — pass it in. If you only have the rating number, the package will use a sensible default $\sigma$ but you should treat the result as approximate:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from unirating import Rating, TimeControl, fuse
|
|
122
|
+
|
|
123
|
+
result = fuse(
|
|
124
|
+
lichess = Rating(value=1850), # sigma=None → default used + warning
|
|
125
|
+
time_control = TimeControl.RAPID,
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## What's in the box
|
|
132
|
+
|
|
133
|
+
| Module | Purpose |
|
|
134
|
+
|---|---|
|
|
135
|
+
| [`unirating.fuse`](src/unirating/fusion.py) | The main entry point — call this. |
|
|
136
|
+
| [`unirating.Rating`](src/unirating/models.py) | Immutable `(value, sigma)` measurement. |
|
|
137
|
+
| [`unirating.Prior`](src/unirating/models.py) | Gaussian prior over latent skill. Defaults to $\mathcal N(1500, 350^2)$. |
|
|
138
|
+
| [`unirating.Calibration`](src/unirating/calibration.py) | Affine map source ↔ FIDE. Defaults per time control. |
|
|
139
|
+
| [`unirating.TimeControl`](src/unirating/calibration.py) | `BULLET`, `BLITZ`, `RAPID`, `CLASSICAL`. |
|
|
140
|
+
| [`unirating.FusionResult`](src/unirating/models.py) | `(rating, sigma, ci95, contributions, used_sources, …)`. |
|
|
141
|
+
| `unirating` (CLI) | One-shot fusion from the shell. |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## CLI
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
unirating \
|
|
149
|
+
--fide 1820 --fide-sigma 60 \
|
|
150
|
+
--chesscom 1950 --chesscom-rd 55 \
|
|
151
|
+
--lichess 2100 --lichess-rd 50 \
|
|
152
|
+
--time-control rapid
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Output:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
Unified rating (FIDE scale): 1839 ± 31
|
|
159
|
+
95% CI: [1778, 1900]
|
|
160
|
+
Sources used: fide, chesscom, lichess
|
|
161
|
+
Contributions: prior=1% fide=27% chesscom=33% lichess=39%
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## How the math works (one paragraph)
|
|
167
|
+
|
|
168
|
+
Each rating is treated as a noisy linear measurement $R_i = \alpha_i + \beta_i \theta + \varepsilon_i$, $\varepsilon_i \sim \mathcal N(0, \sigma_i^2)$, of the latent FIDE-equivalent skill $\theta$. After inverting each measurement to a FIDE-scale estimate $\hat\theta_i$ with variance $\tau_i^2 = \sigma_i^2/\beta_i^2$, the **posterior mean of $\theta$** given a Gaussian prior $\mathcal N(\mu_0, \sigma_0^2)$ is the precision-weighted average
|
|
169
|
+
|
|
170
|
+
$$
|
|
171
|
+
\hat\theta = \frac{\mu_0/\sigma_0^2 + \sum_{i \in S} \hat\theta_i/\tau_i^2}{1/\sigma_0^2 + \sum_{i \in S} 1/\tau_i^2}
|
|
172
|
+
$$
|
|
173
|
+
|
|
174
|
+
over whatever subset $S$ of sources is present. With no sources, the formula collapses to $\mu_0$. The full proof (MLE + Gauss–Markov + Bayes), the choice of constants, and a worked example are in [docs/derivation.md](docs/derivation.md).
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Calibration constants (defaults)
|
|
179
|
+
|
|
180
|
+
| Time control | Chess.com $\alpha,\beta$ | Lichess $\alpha,\beta$ |
|
|
181
|
+
|---|---|---|
|
|
182
|
+
| `BULLET` | 150, 1.0 | 400, 1.0 |
|
|
183
|
+
| `BLITZ` | 120, 1.0 | 350, 1.0 |
|
|
184
|
+
| `RAPID` | 100, 1.0 | 250, 1.0 |
|
|
185
|
+
| `CLASSICAL` | 50, 1.0 | 200, 1.0 |
|
|
186
|
+
|
|
187
|
+
Source: published community regressions (see [docs/citations.md](docs/citations.md)). You can override per call:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from unirating import Calibration, fuse
|
|
191
|
+
|
|
192
|
+
custom = Calibration(chesscom_alpha=80, lichess_alpha=300)
|
|
193
|
+
result = fuse(..., calibration=custom)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Edge cases handled
|
|
199
|
+
|
|
200
|
+
- **No ratings** → returns prior, `is_prior_only=True`.
|
|
201
|
+
- **One rating** → posterior shrinks toward prior; weight reported.
|
|
202
|
+
- **Missing $\sigma_i$** → fills with conservative default, emits `MissingSigmaWarning`.
|
|
203
|
+
- **Provisional rating** (large RD, Lichess `?`) → naturally down-weighted; warns if RD > 110.
|
|
204
|
+
- **Zero / negative $\sigma_i$** → raises `InvalidRatingError`.
|
|
205
|
+
- **Non-finite values** (`nan`, `inf`) → raises `InvalidRatingError`.
|
|
206
|
+
- **Out-of-range ratings** → raises `InvalidRatingError` (configurable bounds).
|
|
207
|
+
- **Mixed time controls** → only one `TimeControl` per call; the calibration enforces consistency.
|
|
208
|
+
- **Custom prior** → pass any `Prior(mu, sigma)` (e.g. for juniors, titled players).
|
|
209
|
+
- **Numerical stability** → all sums computed in precision-space then inverted at the end.
|
|
210
|
+
|
|
211
|
+
See [tests/](tests/) for the formal coverage.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Citation
|
|
216
|
+
|
|
217
|
+
If you use this package in academic work, please cite:
|
|
218
|
+
|
|
219
|
+
```bibtex
|
|
220
|
+
@software{sahu_unirating_2026,
|
|
221
|
+
author = {Sahu, Sourav},
|
|
222
|
+
title = {unirating: Bayesian inverse-variance fusion of FIDE,
|
|
223
|
+
Chess.com and Lichess ratings},
|
|
224
|
+
year = {2026},
|
|
225
|
+
url = {https://github.com/souravsahums/unirating},
|
|
226
|
+
version = {0.1.0},
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Plain text: Sahu, S. (2026). *unirating: Bayesian inverse-variance fusion of FIDE, Chess.com and Lichess ratings* (v0.1.0) [Computer software]. https://github.com/souravsahums/unirating
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT — see [LICENSE](LICENSE). Copyright © 2026 Sourav Sahu.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# unirating
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/downloads/)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
> Author: **Sourav Sahu** ([@souravsahums](https://github.com/souravsahums))
|
|
7
|
+
|
|
8
|
+
Bayesian inverse-variance **fusion** of a player's **FIDE**, **Chess.com** and **Lichess** ratings into a single number on the **FIDE scale**, with proper handling of missing ratings, calibrated per time control.
|
|
9
|
+
|
|
10
|
+
The estimator is the **maximum-likelihood / Best Linear Unbiased Estimator** (Gauss–Markov) when all sources are present, and the **posterior mean of a Gaussian–Gaussian Bayesian model** when one or more sources are missing — so a player with no ratings at all gracefully degrades to the population prior (the "base rating") rather than crashing.
|
|
11
|
+
|
|
12
|
+
Full mathematical derivation with proof: [docs/derivation.md](docs/derivation.md).
|
|
13
|
+
Citations: [docs/citations.md](docs/citations.md).
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install unirating
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Zero runtime dependencies. Python 3.9+.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from unirating import Rating, TimeControl, fuse
|
|
31
|
+
|
|
32
|
+
result = fuse(
|
|
33
|
+
fide = Rating(value=1820, sigma=60), # FIDE Rapid, settled
|
|
34
|
+
chesscom = Rating(value=1950, sigma=55), # Chess.com Rapid, RD=55
|
|
35
|
+
lichess = Rating(value=2100, sigma=50), # Lichess Rapid, RD=50
|
|
36
|
+
time_control = TimeControl.RAPID,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
print(result.rating) # 1838.95 (FIDE scale)
|
|
40
|
+
print(result.sigma) # 31.36 (1-sigma uncertainty)
|
|
41
|
+
print(result.ci95) # (1777.5, 1900.4)
|
|
42
|
+
print(result.contributions) # per-source weight share, sums to 1.0
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A player with no ratings at all:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from unirating import fuse, TimeControl
|
|
49
|
+
|
|
50
|
+
result = fuse(time_control=TimeControl.RAPID)
|
|
51
|
+
print(result.rating) # 1500.0 (prior mean — the "base rating")
|
|
52
|
+
print(result.sigma) # 350.0 (prior std-dev — full uncertainty)
|
|
53
|
+
print(result.is_prior_only) # True
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Lichess gives you the RD directly via API — pass it in. If you only have the rating number, the package will use a sensible default $\sigma$ but you should treat the result as approximate:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from unirating import Rating, TimeControl, fuse
|
|
60
|
+
|
|
61
|
+
result = fuse(
|
|
62
|
+
lichess = Rating(value=1850), # sigma=None → default used + warning
|
|
63
|
+
time_control = TimeControl.RAPID,
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## What's in the box
|
|
70
|
+
|
|
71
|
+
| Module | Purpose |
|
|
72
|
+
|---|---|
|
|
73
|
+
| [`unirating.fuse`](src/unirating/fusion.py) | The main entry point — call this. |
|
|
74
|
+
| [`unirating.Rating`](src/unirating/models.py) | Immutable `(value, sigma)` measurement. |
|
|
75
|
+
| [`unirating.Prior`](src/unirating/models.py) | Gaussian prior over latent skill. Defaults to $\mathcal N(1500, 350^2)$. |
|
|
76
|
+
| [`unirating.Calibration`](src/unirating/calibration.py) | Affine map source ↔ FIDE. Defaults per time control. |
|
|
77
|
+
| [`unirating.TimeControl`](src/unirating/calibration.py) | `BULLET`, `BLITZ`, `RAPID`, `CLASSICAL`. |
|
|
78
|
+
| [`unirating.FusionResult`](src/unirating/models.py) | `(rating, sigma, ci95, contributions, used_sources, …)`. |
|
|
79
|
+
| `unirating` (CLI) | One-shot fusion from the shell. |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## CLI
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
unirating \
|
|
87
|
+
--fide 1820 --fide-sigma 60 \
|
|
88
|
+
--chesscom 1950 --chesscom-rd 55 \
|
|
89
|
+
--lichess 2100 --lichess-rd 50 \
|
|
90
|
+
--time-control rapid
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Output:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
Unified rating (FIDE scale): 1839 ± 31
|
|
97
|
+
95% CI: [1778, 1900]
|
|
98
|
+
Sources used: fide, chesscom, lichess
|
|
99
|
+
Contributions: prior=1% fide=27% chesscom=33% lichess=39%
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## How the math works (one paragraph)
|
|
105
|
+
|
|
106
|
+
Each rating is treated as a noisy linear measurement $R_i = \alpha_i + \beta_i \theta + \varepsilon_i$, $\varepsilon_i \sim \mathcal N(0, \sigma_i^2)$, of the latent FIDE-equivalent skill $\theta$. After inverting each measurement to a FIDE-scale estimate $\hat\theta_i$ with variance $\tau_i^2 = \sigma_i^2/\beta_i^2$, the **posterior mean of $\theta$** given a Gaussian prior $\mathcal N(\mu_0, \sigma_0^2)$ is the precision-weighted average
|
|
107
|
+
|
|
108
|
+
$$
|
|
109
|
+
\hat\theta = \frac{\mu_0/\sigma_0^2 + \sum_{i \in S} \hat\theta_i/\tau_i^2}{1/\sigma_0^2 + \sum_{i \in S} 1/\tau_i^2}
|
|
110
|
+
$$
|
|
111
|
+
|
|
112
|
+
over whatever subset $S$ of sources is present. With no sources, the formula collapses to $\mu_0$. The full proof (MLE + Gauss–Markov + Bayes), the choice of constants, and a worked example are in [docs/derivation.md](docs/derivation.md).
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Calibration constants (defaults)
|
|
117
|
+
|
|
118
|
+
| Time control | Chess.com $\alpha,\beta$ | Lichess $\alpha,\beta$ |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `BULLET` | 150, 1.0 | 400, 1.0 |
|
|
121
|
+
| `BLITZ` | 120, 1.0 | 350, 1.0 |
|
|
122
|
+
| `RAPID` | 100, 1.0 | 250, 1.0 |
|
|
123
|
+
| `CLASSICAL` | 50, 1.0 | 200, 1.0 |
|
|
124
|
+
|
|
125
|
+
Source: published community regressions (see [docs/citations.md](docs/citations.md)). You can override per call:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from unirating import Calibration, fuse
|
|
129
|
+
|
|
130
|
+
custom = Calibration(chesscom_alpha=80, lichess_alpha=300)
|
|
131
|
+
result = fuse(..., calibration=custom)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Edge cases handled
|
|
137
|
+
|
|
138
|
+
- **No ratings** → returns prior, `is_prior_only=True`.
|
|
139
|
+
- **One rating** → posterior shrinks toward prior; weight reported.
|
|
140
|
+
- **Missing $\sigma_i$** → fills with conservative default, emits `MissingSigmaWarning`.
|
|
141
|
+
- **Provisional rating** (large RD, Lichess `?`) → naturally down-weighted; warns if RD > 110.
|
|
142
|
+
- **Zero / negative $\sigma_i$** → raises `InvalidRatingError`.
|
|
143
|
+
- **Non-finite values** (`nan`, `inf`) → raises `InvalidRatingError`.
|
|
144
|
+
- **Out-of-range ratings** → raises `InvalidRatingError` (configurable bounds).
|
|
145
|
+
- **Mixed time controls** → only one `TimeControl` per call; the calibration enforces consistency.
|
|
146
|
+
- **Custom prior** → pass any `Prior(mu, sigma)` (e.g. for juniors, titled players).
|
|
147
|
+
- **Numerical stability** → all sums computed in precision-space then inverted at the end.
|
|
148
|
+
|
|
149
|
+
See [tests/](tests/) for the formal coverage.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Citation
|
|
154
|
+
|
|
155
|
+
If you use this package in academic work, please cite:
|
|
156
|
+
|
|
157
|
+
```bibtex
|
|
158
|
+
@software{sahu_unirating_2026,
|
|
159
|
+
author = {Sahu, Sourav},
|
|
160
|
+
title = {unirating: Bayesian inverse-variance fusion of FIDE,
|
|
161
|
+
Chess.com and Lichess ratings},
|
|
162
|
+
year = {2026},
|
|
163
|
+
url = {https://github.com/souravsahums/unirating},
|
|
164
|
+
version = {0.1.0},
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Plain text: Sahu, S. (2026). *unirating: Bayesian inverse-variance fusion of FIDE, Chess.com and Lichess ratings* (v0.1.0) [Computer software]. https://github.com/souravsahums/unirating
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT — see [LICENSE](LICENSE). Copyright © 2026 Sourav Sahu.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Citations
|
|
2
|
+
|
|
3
|
+
The math in this package is classical; what is novel is the application to chess rating fusion across platforms. Below are the primary sources for each component of the derivation, plus the empirical sources for the default calibration constants.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Rating systems
|
|
8
|
+
|
|
9
|
+
### FIDE Elo
|
|
10
|
+
- **FIDE Handbook B.02 — FIDE Rating Regulations** (current edition).
|
|
11
|
+
<https://handbook.fide.com/chapter/B022017>
|
|
12
|
+
- **Elo, A. E.** (1978). *The Rating of Chessplayers, Past and Present.* Arco Publishing.
|
|
13
|
+
|
|
14
|
+
### Glicko / Glicko-2
|
|
15
|
+
- **Glickman, M. E.** (1995). The Glicko system. Boston University.
|
|
16
|
+
<http://www.glicko.net/glicko/glicko.pdf>
|
|
17
|
+
- **Glickman, M. E.** (2012). Example of the Glicko-2 system. Boston University.
|
|
18
|
+
<http://www.glicko.net/glicko/glicko2.pdf>
|
|
19
|
+
- **Glickman, M. E.** (1999). Parameter estimation in large dynamic paired comparison experiments. *Journal of the Royal Statistical Society: Series C (Applied Statistics)*, 48(3), 377–394.
|
|
20
|
+
|
|
21
|
+
### Chess.com rating system
|
|
22
|
+
- Chess.com — *Chess.com Ratings.* <https://support.chess.com/en/articles/8569091-chess-com-ratings>
|
|
23
|
+
(States that Chess.com Live uses Glicko, Daily uses Glicko-2.)
|
|
24
|
+
|
|
25
|
+
### Lichess rating system
|
|
26
|
+
- Lichess — *Lichess Ratings.* <https://lichess.org/page/rating-systems>
|
|
27
|
+
(States that all Lichess ratings are Glicko-2, with the RD shown on every profile and exposed by the API.)
|
|
28
|
+
- Lichess API reference. <https://lichess.org/api>
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 2. Cross-platform rating comparisons (defaults for $\alpha, \beta$)
|
|
33
|
+
|
|
34
|
+
There is no single authoritative regression. The defaults in `unirating/calibration.py` are consensus values from the following long-running community sources, cross-checked against each other:
|
|
35
|
+
|
|
36
|
+
- **Lichess FAQ** — *"What about my Lichess rating compared to others?"*
|
|
37
|
+
<https://lichess.org/faq#rating-comparison>
|
|
38
|
+
(Notes that Lichess ratings run hotter than FIDE; the gap widens at faster time controls.)
|
|
39
|
+
- **Chess.com Forums & Help — Rating comparison threads** (community-maintained
|
|
40
|
+
conversion tables, e.g. <https://www.chess.com/article/view/chess-ratings---how-they-work>).
|
|
41
|
+
- **r/chess rating-comparison megathreads**, regularly updated, e.g.
|
|
42
|
+
<https://www.reddit.com/r/chess/comments/qewqtq/the_difference_between_fide_chesscom_and_lichess/>
|
|
43
|
+
(typical values: FIDE Rapid ≈ Chess.com Rapid − 100, FIDE Rapid ≈ Lichess Rapid − 250).
|
|
44
|
+
- **Sonas, J.** (2002). *The Sonas Rating Formula — Better than Elo?* ChessBase.
|
|
45
|
+
<https://en.chessbase.com/post/the-sonas-rating-formula-better-than-elo->
|
|
46
|
+
- **Universal Rating System (URS)** — Maxime Rischard & Jeff Sonas, used by the
|
|
47
|
+
Grand Chess Tour. Combines a player's Classical / Rapid / Blitz FIDE ratings
|
|
48
|
+
into one. Spirit-precursor to this package, but stays inside FIDE.
|
|
49
|
+
<https://universalrating.com/>
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 3. Inverse-variance weighting / meta-analysis
|
|
54
|
+
|
|
55
|
+
The §3.1 formula is textbook **fixed-effect meta-analysis**:
|
|
56
|
+
|
|
57
|
+
- **Cochran, W. G.** (1937). Problems arising in the analysis of a series of similar experiments. *Journal of the Royal Statistical Society*, 4(1), 102–118.
|
|
58
|
+
(Earliest formal statement of the inverse-variance weighted mean.)
|
|
59
|
+
- **DerSimonian, R., & Laird, N.** (1986). Meta-analysis in clinical trials. *Controlled Clinical Trials*, 7(3), 177–188.
|
|
60
|
+
(The standard reference for inverse-variance combination of independent estimates.)
|
|
61
|
+
- **Hartung, J., Knapp, G., & Sinha, B. K.** (2008). *Statistical Meta-Analysis with Applications.* Wiley.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 4. Gauss–Markov / BLUE optimality
|
|
66
|
+
|
|
67
|
+
The §3.1 proof that inverse-variance weights minimise variance among linear unbiased combinations is a special case of the Gauss–Markov theorem:
|
|
68
|
+
|
|
69
|
+
- **Gauss, C. F.** (1823). *Theoria combinationis observationum erroribus minimis obnoxiae.* (Reprinted in *Werke*, vol. 4.)
|
|
70
|
+
- **Markov, A. A.** (1900). *Wahrscheinlichkeitsrechnung.* (German translation, Teubner.)
|
|
71
|
+
- **Rao, C. R.** (1973). *Linear Statistical Inference and Its Applications* (2nd ed.). Wiley. (§4a — Gauss–Markov; §5a — Cramér–Rao bound for the Gaussian case.)
|
|
72
|
+
- **Lehmann, E. L., & Casella, G.** (1998). *Theory of Point Estimation* (2nd ed.). Springer. (§4.1 — MMSE estimators.)
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 5. Gaussian–Gaussian conjugacy (the Bayesian extension, §3.2)
|
|
77
|
+
|
|
78
|
+
The closed-form posterior for a Gaussian likelihood with a Gaussian prior is one of the oldest results in Bayesian statistics:
|
|
79
|
+
|
|
80
|
+
- **DeGroot, M. H.** (1970). *Optimal Statistical Decisions.* McGraw-Hill. (§9.5 — Gaussian–Gaussian updates in precision form.)
|
|
81
|
+
- **Murphy, K. P.** (2007). *Conjugate Bayesian analysis of the Gaussian distribution.* Technical note, University of British Columbia.
|
|
82
|
+
<https://www.cs.ubc.ca/~murphyk/Papers/bayesGauss.pdf>
|
|
83
|
+
- **Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., & Rubin, D. B.** (2013). *Bayesian Data Analysis* (3rd ed.). CRC Press. (§2.5 — normal model with known variance.)
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 6. Related work — latent-skill rating models
|
|
88
|
+
|
|
89
|
+
While this package fuses *existing* ratings rather than computing ratings from games directly, the latent-skill philosophy is shared with:
|
|
90
|
+
|
|
91
|
+
- **Herbrich, R., Minka, T., & Graepel, T.** (2007). *TrueSkill™: A Bayesian Skill Rating System.* In *Advances in Neural Information Processing Systems 19* (pp. 569–576). MIT Press.
|
|
92
|
+
- **Coulom, R.** (2008). Whole-history rating: A Bayesian rating system for players of time-varying strength. In *Computers and Games* (Lecture Notes in Computer Science, vol. 5131, pp. 113–124). Springer.
|
|
93
|
+
- **Weng, R. C., & Lin, C.-J.** (2011). A Bayesian approximation method for online ranking. *Journal of Machine Learning Research*, 12, 267–300.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 7. Robustness / heavy-tailed alternatives (§9 caveats)
|
|
98
|
+
|
|
99
|
+
If you suspect the Gaussian-noise assumption is too tight (e.g. one source is clearly wrong), swap it for one of:
|
|
100
|
+
|
|
101
|
+
- **Huber, P. J.** (1964). Robust estimation of a location parameter. *Annals of Mathematical Statistics*, 35(1), 73–101.
|
|
102
|
+
- **Lange, K. L., Little, R. J. A., & Taylor, J. M. G.** (1989). Robust statistical modeling using the t distribution. *Journal of the American Statistical Association*, 84(408), 881–896.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 8. Software references
|
|
107
|
+
|
|
108
|
+
- **NumPy / SciPy** — the formula is closed-form so no numerical libraries are needed at runtime. For dataset-level fitting of $(\alpha, \beta)$ a least-squares regression from `numpy.polyfit` or `scipy.stats.linregress` is sufficient.
|
|
109
|
+
- **Hypothesis** — Maclver, D. R., et al. <https://hypothesis.readthedocs.io/> (used for the property-based tests).
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Citation of this package
|
|
114
|
+
|
|
115
|
+
If you use `unirating` in academic work, please cite:
|
|
116
|
+
|
|
117
|
+
```bibtex
|
|
118
|
+
@software{sahu_unirating_2026,
|
|
119
|
+
author = {Sahu, Sourav},
|
|
120
|
+
title = {unirating: Bayesian inverse-variance fusion of FIDE,
|
|
121
|
+
Chess.com and Lichess ratings},
|
|
122
|
+
year = {2026},
|
|
123
|
+
url = {https://github.com/souravsahums/unirating},
|
|
124
|
+
version= {0.1.0},
|
|
125
|
+
}
|
|
126
|
+
```
|