Skills icon indicating copy to clipboard operation
Skills copied to clipboard

(JSkill) Some calculations produce NaN

Open micheljung opened this issue 6 years ago • 3 comments

Hi, I'm a Java developer so I'm using the fork/port of this project, JSkills.

Unfortunately, the project doesn't seem to be active anymore and I ran into a blocker (nsp/JSkills#9) so my question is; does the same thing happen in Skills? Do you have any idea what could cause it?

I tried debugging the code but it's too complicated for my limited brain capacity. Any help is much appreciated.

micheljung avatar Apr 16 '18 13:04 micheljung

Hi @micheljung , I'm not a developer on the project, and considering that it was last updated in 2013 I would assume this project is not active anymore either.

I was able to reproduce the results of the issue you linked from JSkills:

private static void TestOK()
{
    var gameInfo = new GameInfo(1500, 500, 240, 10, 0.1);

    var player1 = new Player(1);
    var player1Rating = new Rating(3453, 74);

    var team1 = new Team();
    team1.AddPlayer(player1, player1Rating);

    var player2 = new Player(2);
    var player2Rating = new Rating(38, 181);

    var team2 = new Team();
    team2.AddPlayer(player2, player2Rating);

    IEnumerable<IDictionary<Player, Rating>> teams = new List<IDictionary<Player, Rating>>()
    {
        team1.AsDictionary(),
        team2.AsDictionary()
    };

    var newRatings = TrueSkillCalculator.CalculateNewRatings(gameInfo, teams, 1, 2);

    foreach (var newRating in newRatings)
    {
        Console.WriteLine(newRating);
    }
}

This method produced this output:

[1, µ=3453.0000, σ=74.6726]
[2, µ=38.0000, σ=181.2760]

Here is the NaN function:

private static void TestNaN()
{
    GameInfo gameInfo = new GameInfo(1500, 500, 240, 10, 0.1);

    var player1 = new Player(1);
    var player1Rating = new Rating(3453, 74);

    var team1 = new Team();
    team1.AddPlayer(player1, player1Rating);

    var player2 = new Player(2);
    var player2Rating = new Rating(38, 180);

    var team2 = new Team();
    team2.AddPlayer(player2, player2Rating);

    IEnumerable<IDictionary<Player, Rating>> teams = new List<IDictionary<Player, Rating>>()
    {
        team1.AsDictionary(),
        team2.AsDictionary()
    };

    var newRatings = TrueSkillCalculator.CalculateNewRatings(gameInfo, teams, 1, 2);

    foreach (var newRating in newRatings)
    {
        Console.WriteLine(newRating);
    }
}

And it produces the NaN result like you were seeing:

[1, µ=NaN, σ=74.6726]
[2, µ=38.0000, σ=180.2776]

I won't be able to provide any help beyond this, but the problem seems to be with the calculations in Skills and the fact that JSkills is a direct fork means they reproduced the problem there too. Good luck in your investigations and hope you can get your issue resolved.

jmichalc avatar Apr 16 '18 20:04 jmichalc

Hi @jmichalc thanks a lot! It's a good start to know that it's not just a problem of the port :-)

micheljung avatar Apr 17 '18 08:04 micheljung

@jmichalc @moserware Issue nsp/JSkills#9 got resolved, in case you want to apply the fix to this project as well :)

micheljung avatar May 16 '18 18:05 micheljung