lczerolens.sampling#
Classes for playing.
Classes#
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
A class for generating games. |
Module Contents#
- class lczerolens.sampling.Sampler[source]#
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstract get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- choose_move(board, utility, legal_indices)[source]#
Choose the next moves.
- Parameters:
board (LczeroBoard) – The board.
utility (torch.Tensor) – The utility of the board.
legal_indices (torch.Tensor) – The legal indices.
- Returns:
The iterable over the moves.
- Return type:
Iterable[chess.Move]
- get_next_moves(boards, **kwargs)[source]#
Get the next move.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over the moves and log dictionaries.
- Return type:
Iterable[Tuple[chess.Move, Dict[str, float]]]
- class lczerolens.sampling.RandomSampler[source]#
Bases:
SamplerHelper class that provides a standard way to create an ABC using inheritance.
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.sampling.MCTSSampler(model, num_simulations=100, c_puct=1.0, use_argmax=False, use_q_values=False, _heuristic=None)[source]#
Bases:
SamplerHelper class that provides a standard way to create an ABC using inheritance.
- Parameters:
model (lczerolens.model.LczeroModel)
num_simulations (int)
c_puct (float)
use_argmax (bool)
use_q_values (bool)
_heuristic (Optional[Callable])
- choose_move(board, utility, legal_indices)[source]#
Choose the next moves.
- Parameters:
board (LczeroBoard) – The board.
utility (torch.Tensor) – The utility of the board.
legal_indices (torch.Tensor) – The legal indices.
- Returns:
The iterable over the moves.
- Return type:
Iterable[chess.Move]
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.sampling.ModelSampler[source]#
Bases:
SamplerHelper class that provides a standard way to create an ABC using inheritance.
- choose_move(board, utility, legal_indices)[source]#
Choose the next moves.
- Parameters:
board (LczeroBoard) – The board.
utility (torch.Tensor) – The utility of the board.
legal_indices (torch.Tensor) – The legal indices.
- Returns:
The iterable over the moves.
- Return type:
Iterable[chess.Move]
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.sampling.PolicySampler[source]#
Bases:
ModelSamplerHelper class that provides a standard way to create an ABC using inheritance.
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.sampling.SelfPlay[source]#
A class for generating games.
- play(board=None, max_moves=100, to_play=chess.WHITE, report_fn=None, white_kwargs=None, black_kwargs=None)[source]#
Plays a game.
- Parameters:
board (Optional[lczerolens.board.LczeroBoard])
max_moves (int)
to_play (chess.Color)
report_fn (Optional[Callable[[dict, chess.Color], None]])
white_kwargs (Optional[Dict])
black_kwargs (Optional[Dict])