chipiron.players.boardevaluators.datasets package

Submodules

chipiron.players.boardevaluators.datasets.datasets module

This module contains classes for handling datasets used in board evaluation tasks.

Classes: - MyDataSet: A custom dataset class that loads and preprocesses data. - FenAndValueDataSet: A subclass of MyDataSet that processes raw rows into input and target value tensors.

Functions: - process_stockfish_value: A function that processes the stockfish value for a given board and row.

class chipiron.players.boardevaluators.datasets.datasets.DataSetArgs(train_file_name: str | PathLike[str], test_file_name: str | PathLike[str] | None = None, preprocessing_data_set: bool = False)[source]

Bases: object

Arguments for the dataset.

preprocessing_data_set: bool = False
test_file_name: str | PathLike[str] | None = None
train_file_name: str | PathLike[str]
class chipiron.players.boardevaluators.datasets.datasets.FenAndValueData(fen_tensor: torch.Tensor, value_tensor: torch.Tensor, is_batch: bool = False)[source]

Bases: object

fen_tensor: Tensor
get_input_layer() Tensor[source]

Returns the input layer tensor.

get_target_value() Tensor[source]

Returns the target value tensor.

is_batch: bool = False
value_tensor: Tensor
class chipiron.players.boardevaluators.datasets.datasets.FenAndValueDataSet(file_name: str | PathLike[str], transform_white_value_to_model_output_function: Callable[[float, IBoard], Tensor], transform_dataset_value_to_white_value_function: Callable[[Series], float], transform_board_function: BoardToInputFunction, preprocessing: bool = False)[source]

Bases: MyDataSet[FenAndValueData]

A subclass of MyDataSet that processes raw rows into input and target value tensors.

Attributes: - transform_board_function (BoardToInputFunction): The function to transform the board into input tensor. - transform_value_function (callable): The function to transform the value for a given board and row.

Methods: - process_raw_row(row: pandas.Series) -> tuple[torch.Tensor, torch.Tensor]: Processes a raw row into input and target tensors. - process_raw_rows(dataframe: pandas.DataFrame) -> list[tuple[torch.Tensor, torch.Tensor]]: Processes raw rows into input and target tensors.

process_raw_row(row: Series) FenAndValueData[source]

Processes a raw row into input and target tensors.

Args: - row (pandas.Series): The raw row from the dataset.

Returns: - tuple[torch.Tensor, torch.Tensor]: The input and target tensors.

process_raw_rows(dataframe: DataFrame) list[chipiron.players.boardevaluators.datasets.datasets.FenAndValueData][source]

Processes raw rows into input and target tensors.

Args: - dataframe (pandas.DataFrame): The raw rows from the dataset.

Returns: - list[FenAndValueData]: The processed input and target tensors.

transform_board_function: BoardToInputFunction
transform_dataset_value_to_white_value_function: Callable[[Series], float]
transform_white_value_to_model_output_function: Callable[[float, IBoard], Tensor]
class chipiron.players.boardevaluators.datasets.datasets.MyDataSet(file_name: str | PathLike[str], preprocessing: bool)[source]

Bases: Dataset[Union[ProcessedSample, RawSample]], ABC, Generic

A custom dataset class that loads and preprocesses data.

Attributes: - file_name (str): The file name of the dataset. - preprocessing (bool): Flag indicating whether to preprocess the dataset. - data (pandas.DataFrame | list[tuple[torch.Tensor, torch.Tensor]] | None): The loaded and processed data. - len (int | None): The length of the dataset.

Methods: - load(): Loads the dataset from the file. - process_raw_row(row: pandas.Series) -> tuple[torch.Tensor, torch.Tensor]: Processes a raw row into input and target tensors.

__getitem__(idx: int) ProcessedSample | RawSample[source]

Returns the item at the given index.

Args: - idx (int): The index of the item.

Returns: - tuple[torch.Tensor, torch.Tensor] | pandas.Series: The input and target tensors, or the raw row.

__len__() int[source]

Returns the length of the dataset.

Returns: - int: The length of the dataset.

data: RawSample | list[ProcessedSample] | None
get_unprocessed(idx: int) Series[source]
is_preprocessed() bool[source]
len: int | None
load() None[source]

Loads the dataset from the file.

preprocessing: bool
abstract process_raw_row(row: Series) ProcessedSample[source]

Converts a raw row into input/target tensors. Subclasses must implement this.

class chipiron.players.boardevaluators.datasets.datasets.SupervisedData(*args, **kwargs)[source]

Bases: Protocol

A protocol that defines the structure for classes that have input and target value attributes.

get_input_layer() Tensor[source]

Returns the input layer tensor.

get_target_value() Tensor[source]

Returns the target value tensor.

is_batch: bool = False
chipiron.players.boardevaluators.datasets.datasets.custom_collate_fn_fen_and_value(batch: list[chipiron.players.boardevaluators.datasets.datasets.FenAndValueData]) FenAndValueData[source]
chipiron.players.boardevaluators.datasets.datasets.process_stockfish_value(row: Series) float[source]

Processes the stockfish value for a given board and row.

Args: - board (BoardChi): The chess board. - row (pandas.Series): The row from the dataset.

Returns: - torch.Tensor: The processed target value tensor.

Module contents