Further slow progress.

This commit is contained in:
Jens True 2024-01-12 14:54:04 +00:00
parent e49f01cd68
commit 61e7b8dd49
8 changed files with 345 additions and 308 deletions

1
.gitignore vendored

@ -6,3 +6,4 @@ vendor
bin bin
.phpunit.cache .phpunit.cache
composer.phar composer.phar
output/

@ -24,7 +24,7 @@
}, },
"scripts": { "scripts": {
"test": "vendor/bin/phpunit tests --display-warnings", "test": "vendor/bin/phpunit tests --display-warnings",
"test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html --log-junit output/test.xml ", "test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --testdox-html output/test.html --log-junit output/test.xml",
"analyze": [ "analyze": [
"@analyze-phpstan", "@analyze-phpstan",
"@analyze-psalm", "@analyze-psalm",

574
composer.lock generated

File diff suppressed because it is too large Load Diff

41
examples/3teams.php Normal file

@ -0,0 +1,41 @@
<?php
require_once("vendor/autoload.php");
use DNW\Skills\TrueSkill\FactorGraphTrueSkillCalculator;
use DNW\Skills\GameInfo;
use DNW\Skills\Player;
use DNW\Skills\Team;
use DNW\Skills\Teams;
$gameInfo = new GameInfo();
$p1 = new Player("Winner");
$p2 = new Player("Average");
$p3 = new Player("Looser");
$team1 = new Team($p1, $gameInfo->getDefaultRating());
$team2 = new Team($p2, $gameInfo->getDefaultRating());
$team3 = new Team($p3, $gameInfo->getDefaultRating());
for($i = 0; $i < 5; $i++) {
echo "Iteration: $i\n";
$teams = Teams::concat($team1, $team2, $team3);
$calculator = new FactorGraphTrueSkillCalculator();
$newRatings = $calculator->calculateNewRatings($gameInfo, $teams, [1, 2, 3]);
$team1 = new Team($p1, $newRatings->getRating($p1));
$team2 = new Team($p2, $newRatings->getRating($p2));
$team3 = new Team($p3, $newRatings->getRating($p3));
echo "P1: ". $newRatings->getRating($p1)->getConservativeRating() . PHP_EOL;
echo "P2: ". $newRatings->getRating($p2)->getConservativeRating() . PHP_EOL;
echo "P3: ". $newRatings->getRating($p3)->getConservativeRating() . PHP_EOL;
}

@ -12,13 +12,13 @@ $gameInfo = new GameInfo();
$p1 = new Player("Winner"); $p1 = new Player("Winner");
$p2 = new Player("Average"); $p2 = new Player("Average");
$p3 = new Player("Looser");
$team1 = new Team($p1, $gameInfo->getDefaultRating()); $team1 = new Team($p1, $gameInfo->getDefaultRating());
$team2 = new Team($p2, $gameInfo->getDefaultRating()); $team2 = new Team($p2, $gameInfo->getDefaultRating());
for($i = 0; $i < 5; $i++) { for($i = 0; $i < 5; $i++) {
echo "Iteration: $i\n"; echo "Iteration: $i\n";
$teams = Teams::concat($team1, $team2); $teams = Teams::concat($team1, $team2);

@ -36,7 +36,7 @@ class GaussianWeightedSumFactor extends GaussianFactor
* @param Variable[] $variablesToSum * @param Variable[] $variablesToSum
* @param array<float> $variableWeights * @param array<float> $variableWeights
*/ */
public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights = null) public function __construct(Variable $sumVariable, array $variablesToSum, array $variableWeights)
{ {
parent::__construct(self::createName((string)$sumVariable, $variablesToSum, $variableWeights)); parent::__construct(self::createName((string)$sumVariable, $variablesToSum, $variableWeights));

27
tests/GuardTest.php Normal file

@ -0,0 +1,27 @@
<?php
namespace DNW\Skills\Tests;
use DNW\Skills\Guard;
use Exception;
class GuardTest extends TestCase
{
public function testArgumentNotNull(): void
{
$this->expectException(Exception::class);
Guard::argumentNotNull(null, "dummy");
}
public function testargumentIsValidIndex(): void
{
$this->expectException(Exception::class);
Guard::argumentIsValidIndex(25, 10, "dummy");
}
public function testargumentInRangeInclusive(): void
{
$this->expectException(Exception::class);
Guard::argumentInRangeInclusive(101, 0, 100, "dummy");
}
}