Skip to content

minrecord.comparable

minrecord.comparable

Contain the comparable record implementations.

minrecord.comparable.ComparableRecord

Bases: Record[T]

Implement a record of comparable values.

Parameters:

Name Type Description Default
name str

The name of the record.

required
comparator BaseComparator[T]

The comparator to use to find the best value.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store in the record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False
Example
>>> from minrecord import ComparableRecord
>>> from minrecord.comparator import MaxScalarComparator
>>> record = ComparableRecord("value", MaxScalarComparator())
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_last_value()
42.0
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_best_value()
64.0

minrecord.comparable.ComparableRecord.is_better

is_better(old_value: T, new_value: T) -> bool

Indicate if the new value is better than the old value.

Parameters:

Name Type Description Default
old_value T

The old value to compare.

required
new_value T

The new value to compare.

required

Returns:

Type Description
bool

True if the new value is better than the old value, otherwise False.

Example
>>> from minrecord import ComparableRecord
>>> from minrecord.comparator import MaxScalarComparator
>>> record = ComparableRecord("accuracy", MaxScalarComparator())
>>> record.is_better(new_value=1, old_value=0)
True
>>> record.is_better(new_value=0, old_value=1)
False

minrecord.comparable.MaxScalarRecord

Bases: ComparableRecord[Number]

A specific implementation to track the max value of a scalar record.

This record uses the MaxScalarComparator to find the best value of the record.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store inthe record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False
Example
>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord("value")
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
64.0

minrecord.comparable.MaxScalarRecord.from_elements classmethod

from_elements(
    name: str, elements: Iterable[tuple[float | None, T]]
) -> Self

Instantiate a MaxScalarRecord object from the elements.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[float | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

required

Returns:

Type Description
Self

The instantiated record.

Example
>>> from minrecord import MaxScalarRecord
>>> record = MaxScalarRecord.from_elements("value", ((None, 64.0), (None, 42.0)))
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
64.0

minrecord.comparable.MinScalarRecord

Bases: ComparableRecord[Number]

A specific implementation to track the min value of a scalar record.

This record uses the MinScalarComparator to find the best value of the record.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[int | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

()
max_size int

The maximum number of elements to store inthe record.

10
best_value T | None

The initial best value. If None, the initial best value of the comparator is used.

None
improved bool

Indicate if the last value is the best value or not.

False
Example
>>> from minrecord import MinScalarRecord
>>> record = MinScalarRecord("value")
>>> record.add_value(64.0)
>>> record.add_value(42.0)
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
42.0

minrecord.comparable.MinScalarRecord.from_elements classmethod

from_elements(
    name: str, elements: Iterable[tuple[float | None, T]]
) -> Self

Instantiate a MaxScalarRecord object from the elements.

Parameters:

Name Type Description Default
name str

The name of the record.

required
elements Iterable[tuple[float | None, T]]

The initial elements. Each element is a tuple with the step and its associated value.

required

Returns:

Type Description
Self

The instantiated record.

Example
>>> from minrecord import MinScalarRecord
>>> record = MinScalarRecord.from_elements("value", ((None, 64.0), (None, 42.0)))
>>> record.get_most_recent()
((None, 64.0), (None, 42.0))
>>> record.get_last_value()
42.0
>>> record.get_best_value()
42.0