Source code for bnelearn.mechanism.mechanism

# -*- coding: utf-8 -*-

"""
This module implements games such as matrix games and auctions.
"""

from abc import ABC, abstractmethod
from typing import Tuple

# pylint: disable=E1102
import torch


[docs]class Game(ABC): """ Base class for any kind of games """ def __init__(self, cuda: bool = True): self.cuda = cuda and torch.cuda.is_available() self.device = 'cuda' if self.cuda else 'cpu'
[docs] @abstractmethod def play(self, action_profile): """Play the game!""" # get actions from players and define outcome raise NotImplementedError()
[docs]class Mechanism(Game, ABC): """ Auction Mechanism - Interpreted as a Bayesian game. A Mechanism collects bids from all players, then allocates available items as well as payments for each of the players. """
[docs] def play(self, action_profile) -> Tuple[torch.Tensor, torch.Tensor]: return self.run(bids=action_profile)
[docs] @abstractmethod def run(self, bids) -> Tuple[torch.Tensor, torch.Tensor]: """Alias for play for auction mechanisms""" raise NotImplementedError()