ML

Machine learning modules for analyzing 17lands data.

Model

Machine learning model architectures.

class mtga_ml.ml.model.PickAdvisor(model, card_names)

Abstract class for advising a pick in a given a draft state.

This class can be used for predicting human picks, recommending a pick that maximizes expected winrate, predicting whether a card will wheel, or predicting whether a card will be maindecked if picked, among other things.

Parameters
  • model (nn.Module) – Module that takes a draft state as input and outputs a tensor of shape (num_cards) of scores for each card in the format.

  • card_names (list[str]) – A list of the names of all cards in the target format.

num_cards

Length of card_names.

Type

int

forward(draft_state)

Computes differentiable pick scores given a draft state.

Used for training self.model.

Parameters

draft_state (dict) – The state of the draft up until the pick under consideration.

Returns

A tensor of shape (num_cards) of pick scores.

pick(draft_state)

Computes human-readable pick scores.

Parameters

draft_state (dict) – The state of the draft up until the pick under consideration.

Returns

A tensor of shape (num_cards) of pick scores.

class mtga_ml.ml.model.PoolPackPickPredictor(model, card_names, not_in_pack_val=- 1000.0)

Class for predicting human picks from the pool and pack of the draft state.

Parameters
  • model (nn.Module) – Takes a draft state pool as input and outputs a pick prediction logit for each card in the format.

  • card_names (list[str]) – A list of the names of all cards in the target format.

  • not_in_pack_val (float) – Logits for cards not in the pack are set to this value. Should be a large negative number.

forward(draft_state)

Compute pick prediction logits for each card in the format.

Parameters

draft_state (dict) – The state of the draft up until the pick under consideration.

Returns

Pick prediction logits for each card in the format.

pick(draft_state)

Computes human-readable pick prediction probabilities.

Parameters

draft_state (dict) – The state of the draft up until the pick under consideration.

Returns

A tensor of shape (num_cards) of pick prediction probabilities.

mtga_ml.ml.model.mlp(dims, activation_function, use_batchnorm=False, dropout_rate=0.0)

Multi-layer perceptron.

Parameters
  • dims (list[int]) – Number of neurons to use in each hidden layer. The first and last int of dims are the MLP input and output dimensions, respectively.

  • activation_function (nn.Module) – Non-linear activation function to apply in each layer.

  • use_batchnorm (bool) – If true, uses batch normalization in each hidden layer.

  • dropout_rate (float) – If not zero, uses dropout with the specified rate.

Returns

MLP model as an nn.Module.

Examples

>>> # Deck classifier. `num_cards` is the number of cards in the target format.
>>> h_dims = [50, 50]
>>> model = mlp([num_cards] + h_dims + [1], nn.ReLU())