Skip to content

minrecord.functional

minrecord.functional

Contain functions to manipulate records.

minrecord.functional.get_best_values

get_best_values(
    records: Mapping[str, BaseRecord[Any]],
    prefix: str = "",
    suffix: str = "",
) -> dict[str, Any]

Get the best value of each record.

This function ignores the empty and non-comparable records.

Parameters:

Name Type Description Default
records Mapping[str, BaseRecord[Any]]

The records and their associated keys.

required
prefix str

The prefix used to create the dict of best values. The goal of this prefix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''
suffix str

The suffix used to create the dict of best values. The goal of this suffix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''

Returns:

Type Description
dict[str, Any]

The dict with the best value of each record.

Example
>>> from minrecord import (
...     MinScalarRecord,
...     MaxScalarRecord,
...     get_best_values,
... )
>>> record1 = MinScalarRecord.from_elements("loss", elements=[(None, 1.9), (None, 1.2)])
>>> record2 = MaxScalarRecord.from_elements("accuracy", elements=[(None, 42), (None, 35)])
>>> get_best_values({"loss": record1, "accuracy": record2})
{'loss': 1.2, 'accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, prefix="best/")
{'best/loss': 1.2, 'best/accuracy': 42}
>>> get_best_values({"loss": record1, "accuracy": record2}, suffix="/best")
{'loss/best': 1.2, 'accuracy/best': 42}

minrecord.functional.get_last_values

get_last_values(
    records: Mapping[str, BaseRecord[Any]],
    prefix: str = "",
    suffix: str = "",
) -> dict[str, Any]

Get the last value of each record.

This function ignores the empty records.

Parameters:

Name Type Description Default
records Mapping[str, BaseRecord[Any]]

The records and their associated keys.

required
prefix str

The prefix used to create the dict of best values. The goal of this prefix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''
suffix str

The suffix used to create the dict of best values. The goal of this suffix is to generate a name which is different from the record name to avoid confusion. By default, the returned dict uses the same name as the record.

''

Returns:

Type Description
dict[str, Any]

The dict with the best value of each record.

Example
>>> from minrecord import (
...     MinScalarRecord,
...     MaxScalarRecord,
...     get_last_values,
... )
>>> record1 = MinScalarRecord.from_elements("loss", elements=[(None, 1.9), (None, 1.2)])
>>> record2 = MaxScalarRecord.from_elements("accuracy", elements=[(None, 42), (None, 35)])
>>> get_last_values({"loss": record1, "accuracy": record2})
{'loss': 1.2, 'accuracy': 35}
>>> get_last_values({"loss": record1, "accuracy": record2}, prefix="last/")
{'last/loss': 1.2, 'last/accuracy': 35}
>>> get_last_values({"loss": record1, "accuracy": record2}, suffix="/last")
{'loss/last': 1.2, 'accuracy/last': 35}