From a480f4712f5e7cbcb86a46cc31c594c478d86ef1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 16 Aug 2024 04:09:29 +0200 Subject: [PATCH 1/3] added dice roll --- Math/Stochastic/Distribution/GeometricDistribution.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Math/Stochastic/Distribution/GeometricDistribution.php b/Math/Stochastic/Distribution/GeometricDistribution.php index df96ff874..fa5b8a7a4 100755 --- a/Math/Stochastic/Distribution/GeometricDistribution.php +++ b/Math/Stochastic/Distribution/GeometricDistribution.php @@ -27,6 +27,8 @@ final class GeometricDistribution /** * Constructor. * + * Example: dice roll + * * @since 1.0.0 * @codeCoverageIgnore */ @@ -34,6 +36,14 @@ final class GeometricDistribution { } + /** + * How often to roll to get a specific value with at least percent chance + */ + public static function getHowOften(float $p, float $percent) : float + { + return log(1.0 - $percent) / log(1 - $p); + } + /** * Get probability mass function. * From cb4c61fb5bb844c134886c8b1e03f348739bed39 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Nov 2024 22:57:12 +0100 Subject: [PATCH 2/3] spelling fix --- Stdlib/Base/Heap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stdlib/Base/Heap.php b/Stdlib/Base/Heap.php index 5185655b0..43d65457a 100755 --- a/Stdlib/Base/Heap.php +++ b/Stdlib/Base/Heap.php @@ -64,7 +64,7 @@ class Heap * * @since 1.0.0 */ - public function insort(HeapItemInterface $x, int $lo = 0) : void + public function insert(HeapItemInterface $x, int $lo = 0) : void { $hi = \count($this->nodes); From 6611f2bd52cf19775d50555cd2e80d5567d4f84d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 4 Aug 2026 16:21:13 +0200 Subject: [PATCH 3/3] update --- Algorithm/Rating/Elo.php | 20 ++++++++++++++++---- tests/Ai/Ocr/Tesseract/TesseractOcrTest.php | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Algorithm/Rating/Elo.php b/Algorithm/Rating/Elo.php index 114a68068..e9ff04a22 100644 --- a/Algorithm/Rating/Elo.php +++ b/Algorithm/Rating/Elo.php @@ -88,9 +88,15 @@ final class Elo */ public function winProbability(int $elo1, int $elo2, bool $canDraw = false) : float { - return $canDraw - ? -1.0 // @todo implement - : 1 / (1 + \pow(10, ($elo2 - $elo1) / 400)); + $expectedWin = 1 / (1 + \pow(10, ($elo2 - $elo1) / 400)); + + if (!$canDraw) { + return $expectedWin; + } + + $draw = $this->drawProbability($elo1, $elo2); + + return (1.0 - $draw) * $expectedWin; } /** @@ -105,6 +111,12 @@ final class Elo */ public function drawProbability(int $elo1, int $elo2) : float { - return -1.0; // @todo implement + $diff = \abs($elo1 - $elo2); + + // Approximate draw probability: highest when ratings are equal, + // decreasing smoothly as the rating difference increases. + $maxDraw = 0.30; + + return $maxDraw * \exp(-($diff ** 2) / (2 * (200 ** 2))); } } diff --git a/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php b/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php index d10cfd4ec..a42e0fa57 100755 --- a/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php +++ b/tests/Ai/Ocr/Tesseract/TesseractOcrTest.php @@ -98,7 +98,7 @@ final class TesseractOcrTest extends \PHPUnit\Framework\TestCase * @group framework */ /* - @todo somehow this suddenly takes a long time. + this takes a long time. Might be because a php version update resulting in float 32->64bit changes? Fix it, it was working with php 8.0 public function testOcrWithThresholdingRotating() : void