sublee / trueskill

An implementation of the TrueSkill rating system for Python
https://trueskill.org/
Other
742 stars 112 forks source link

Weightings not respected when supplied as dictionary #9

Closed bernd-wechner closed 9 years ago

bernd-wechner commented 9 years ago

In this sample:

    # Multi Player example
    print("\nMultiplayer example")

    class Player(object):
        def __init__(self, name, rating, team):
            self.name = name
            self.rating = rating
            self.team = team

    p1 = Player('Player A', Rating(), 0)
    p2 = Player('Player B', Rating(), 0)
    p3 = Player('Player C', Rating(), 1)

    print(p1.rating, p2.rating, p3.rating)

    teams = [{p1: p1.rating, p2: p2.rating}, {p3: p3.rating}]
    ranks = [1, 2]
    weights = {(0, p1): 1, (0, p2): 1, (1, p3): 1}

    rated = trueskill.rate(teams, ranks, weights=weights)

    p1.rating = rated[p1.team][p1]
    p2.rating = rated[p2.team][p2]
    p3.rating = rated[p3.team][p3]

    print(p1.rating, p2.rating, p3.rating)

The result is:

    Multiplayer example
    trueskill.Rating(mu=25.000, sigma=8.333) trueskill.Rating(mu=25.000, sigma=8.333) trueskill.Rating(mu=25.000, sigma=8.333)
    trueskill.Rating(mu=25.604, sigma=8.075) trueskill.Rating(mu=25.604, sigma=8.075) trueskill.Rating(mu=24.396, sigma=8.075)

All the weights were 1. Now give p2 a weight of 0.5:

    weights = {(0, p1): 1, (0, p2): 0.5, (1, p3): 1}

The result is identical:

If the weights are supplied as a list of tuples instead:

    weights = weights = [(1, 0.5), (1,)]    # for p1, p2, p3 respectively

Then the results reflect the weights:

    Multiplayer example
    trueskill.Rating(mu=25.000, sigma=8.333) trueskill.Rating(mu=25.000, sigma=8.333) trueskill.Rating(mu=25.000, sigma=8.333)
    trueskill.Rating(mu=26.764, sigma=7.685) trueskill.Rating(mu=25.882, sigma=8.176) trueskill.Rating(mu=23.236, sigma=7.685)
sublee commented 9 years ago

Thanks to report. I fixed this error. Upgrade the package by:

$ pip install -U trueskill

If your problem has been gone, please close this issue.

bernd-wechner commented 9 years ago

Thanks enormously!

Heungsub Lee wrote:

|pip install -U trueskill|

sublee commented 9 years ago

@bernd-wechner Is this issue fixed? Then I'll or you'll close it.

bernd-wechner commented 9 years ago

Heungsub,

Yep, it's fixed. Thanks heaps!. You can close it. Have not looked at code most week, but will get back into it some time in coming month.

Regards,

Bernd.

Heungsub Lee wrote:

@bernd-wechner https://github.com/bernd-wechner Is this issue fixed? Then I'll or you'll close it.

— Reply to this email directly or view it on GitHub https://github.com/sublee/trueskill/issues/9#issuecomment-55267868.