Skip to content

Elo

evalica.elo(xs, ys, ws, index=None, initial=1000.0, base=10.0, scale=400.0, k=4.0, solver='pyo3')

Compute the Elo scores.

Quote

Elo, A.E.: The rating of chessplayers, past and present. Arco Pub, New York (1978).

Parameters:

Name Type Description Default
xs Collection[T]

The left-hand side elements.

required
ys Collection[T]

The right-hand side elements.

required
ws Collection[Winner]

The winner elements.

required
index dict[T, int] | None

The index.

None
initial float

The initial score of each element.

1000.0
base float

The base of the exponent.

10.0
scale float

The scale factor.

400.0
k float

The K-factor.

4.0
solver Literal['naive', 'pyo3']

The solver.

'pyo3'

Returns:

Type Description
EloResult[T]

The Elo result.

Source code in evalica/__init__.py
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
def elo(
        xs: Collection[T],
        ys: Collection[T],
        ws: Collection[Winner],
        index: dict[T, int] | None = None,
        initial: float = 1000.,
        base: float = 10.,
        scale: float = 400.,
        k: float = 4.,
        solver: Literal["naive", "pyo3"] = "pyo3",
) -> EloResult[T]:
    """
    Compute the Elo scores.

    Quote:
        Elo, A.E.: The rating of chessplayers, past and present. Arco Pub, New York (1978).

    Args:
        xs: The left-hand side elements.
        ys: The right-hand side elements.
        ws: The winner elements.
        index: The index.
        initial: The initial score of each element.
        base: The base of the exponent.
        scale: The scale factor.
        k: The K-factor.
        solver: The solver.

    Returns:
        The Elo result.

    """
    xs_indexed, ys_indexed, index = indexing(xs, ys, index)

    assert index is not None, "index is None"

    if solver == "pyo3":
        scores = elo_pyo3(xs_indexed, ys_indexed, ws, len(index), initial, base, scale, k)
    else:
        scores = elo_naive(xs_indexed, ys_indexed, ws, len(index), initial, base, scale, k)

    return EloResult(
        scores=pd.Series(scores, index=index, name=elo.__name__).sort_values(ascending=False, kind="stable"),
        index=index,
        initial=initial,
        base=base,
        scale=scale,
        k=k,
        solver=solver,
    )

evalica.EloResult dataclass

Bases: Generic[T]

The Elo result.

Attributes:

Name Type Description
scores Series[float]

The element scores.

index dict[T, int]

The index.

initial float

The initial score of each element.

base float

The base of the exponent.

scale float

The scale factor.

k float

The K-factor.

solver str

The solver.

Source code in evalica/__init__.py
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
@dataclass(frozen=True)
class EloResult(Generic[T]):
    """
    The Elo result.

    Attributes:
        scores: The element scores.
        index: The index.
        initial: The initial score of each element.
        base: The base of the exponent.
        scale: The scale factor.
        k: The K-factor.
        solver: The solver.

    """

    scores: pd.Series[float]
    index: dict[T, int]
    initial: float
    base: float
    scale: float
    k: float
    solver: str