|
| 1 | +// Copyright © 2025 Rak Laptudirm <[email protected]> |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +use super::{BayesianElo, Wdl}; |
| 15 | + |
| 16 | +pub fn llr(ws: usize, ds: usize, ls: usize, elo0: f64, elo1: f64) -> f64 { |
| 17 | + let w = ws as f64 + 0.5; |
| 18 | + let d = ds as f64 + 0.5; |
| 19 | + let l = ls as f64 + 0.5; |
| 20 | + |
| 21 | + let n = w + d + l; |
| 22 | + |
| 23 | + let elo: BayesianElo = Wdl(w / n, l / n).into(); |
| 24 | + |
| 25 | + let wdl0 = Wdl::from(BayesianElo(elo0, elo.dlo())); |
| 26 | + let wdl1 = Wdl::from(BayesianElo(elo1, elo.dlo())); |
| 27 | + |
| 28 | + w * (wdl1.w() / wdl0.w()).ln() + d * (wdl1.d() / wdl0.d()).ln() + l * (wdl1.l() / wdl0.l()).ln() |
| 29 | +} |
| 30 | + |
| 31 | +pub fn elo(ws: usize, ds: usize, ls: usize) -> (f64, f64, f64) { |
| 32 | + let n = (ws + ds + ls) as f64 + 1.5; |
| 33 | + |
| 34 | + let w = ws as f64 + 0.5; |
| 35 | + let d = ds as f64 + 0.5; |
| 36 | + let l = ls as f64 + 0.5; |
| 37 | + |
| 38 | + let mu = w + d / 2.0; |
| 39 | + |
| 40 | + let sigma = f64::sqrt( |
| 41 | + w * f64::powi(1.0 - mu, 2) + d * f64::powi(0.5 - mu, 2) + l * f64::powi(0.0 - mu, 2), |
| 42 | + ) / n.sqrt(); |
| 43 | + |
| 44 | + let mu_max = mu; |
| 45 | + |
| 46 | + (0.0, 0.0, 0.0) |
| 47 | +} |
0 commit comments