Skip to content

Commit

Permalink
added a blended competitor prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Will McGinnis committed Dec 9, 2017
1 parent 8eb3842 commit 2530eab
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from elote.competitors.glicko import GlickoCompetitor
from elote.competitors.ecf import ECFCompetitor
from elote.competitors.dwz import DWZCompetitor
from elote.competitors.ensemble import BlendedCompetitor

from elote.arenas.lambda_arena import LambdaArena

Expand All @@ -11,5 +12,6 @@
"ECFCompetitor",
"DWZCompetitor",
"GlickoCompetitor",
"LambdaArena"
"LambdaArena",
"BlendedCompetitor"
]
55 changes: 55 additions & 0 deletions elote/competitors/ensemble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from elote.competitors.base import BaseCompetitor
from elote import EloCompetitor, ECFCompetitor, DWZCompetitor, GlickoCompetitor

competitor_types = {
"EloCompetitor": EloCompetitor,
"ECFCompetitor": ECFCompetitor,
"DWZCompetitor": DWZCompetitor,
"GlickoCompetitor": GlickoCompetitor
}


class BlendedCompetitor(BaseCompetitor):
def __init__(self, competitors, blend_mode="mean"):
self._sub_competitors = []
for competitor in competitors:
comp_type = competitor_types.get(competitor.get('type', 'EloCompetitor'))
comp_kwargs = competitor.get('competitor_kwargs', {})
self._sub_competitors.append(comp_type(**comp_kwargs))

self.blend_mode = blend_mode

def __repr__(self):
return '<BlendedCompetitor: %s>' % (self.__hash__())

def __str__(self):
return '<BlendedCompetitor>'

def export_state(self):
return {
"blend_mode": self.blend_mode,
"competitors": [
{
"type": x.__name__,
"competitor_kwargs": x.export_state()
}
for x in self._sub_competitors
]
}

def expected_score(self, competitor):
if self.blend_mode == 'mean':
return sum([x.expected_score(competitor) for x in self._sub_competitors]) / len(self._sub_competitors)
else:
raise NotImplementedError('Blend mode %s not supported' % (self.blend_mode, ))

def beat(self, competitor):
"""
takes in a competitor object that lost, updates both's scores.
"""
for c in self._sub_competitors:
c.beat(competitor)

def tied(self, competitor):
for c in self._sub_competitors:
c.tied(competitor)

0 comments on commit 2530eab

Please sign in to comment.