Skip to content

State

analora.state

Contain states.

analora.state.AccuracyState

Bases: BaseArgState

Implement a state used to compute accuracy results.

Parameters:

Name Type Description Default
y_true ndarray

The ground truth target labels. This input must be an array of shape (n_samples,) where the values are in {0, ..., n_classes-1}.

required
y_pred ndarray

The predicted labels. This input must be an array of shape (n_samples,) where the values are in {0, ..., n_classes-1}.

required
y_true_name str

The name associated to the ground truth target labels.

required
y_pred_name str

The name associated to the predicted labels.

required
nan_policy str

The policy on how to handle NaN values in the input arrays. The following options are available: 'omit', 'propagate', and 'raise'.

'propagate'

Example usage:

>>> import numpy as np
>>> from analora.state import AccuracyState
>>> state = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> state
AccuracyState(y_true=(5,), y_pred=(5,), y_true_name='target', y_pred_name='pred', nan_policy='propagate')

analora.state.BaseArgState

Bases: BaseState

Define a base class to manage arguments.

analora.state.BaseArgState.get_args abstractmethod

get_args() -> dict

Get a dictionary with all the arguments of the state.

Returns:

Type Description
dict

The dictionary with all the arguments.

Example usage:

>>> import numpy as np
>>> from analora.state import AccuracyState
>>> state = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> args = state.get_args()
>>> args
{'y_true': array([1, 0, 0, 1, 1]),
 'y_pred': array([1, 0, 0, 1, 1]),
 'y_true_name': 'target',
 'y_pred_name': 'pred',
 'nan_policy': 'propagate'}

analora.state.BaseState

Bases: ABC

Define the base class to implement a state.

Example usage:

>>> import numpy as np
>>> from analora.state import AccuracyState
>>> state = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> state
AccuracyState(y_true=(5,), y_pred=(5,), y_true_name='target', y_pred_name='pred', nan_policy='propagate')

analora.state.BaseState.clone abstractmethod

clone(deep: bool = True) -> Self

Return a copy of the state.

Parameters:

Name Type Description Default
deep bool

If True, it returns a deep copy of the state, otherwise it returns a shallow copy.

True

Returns:

Type Description
Self

A copy of the state.

Example usage:

>>> import numpy as np
>>> from analora.state import AccuracyState
>>> state = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
... cloned_state = state.clone()

analora.state.BaseState.equal abstractmethod

equal(other: Any, equal_nan: bool = False) -> bool

Indicate if two states are equal or not.

Parameters:

Name Type Description Default
other Any

The other state to compare.

required
equal_nan bool

Whether to compare NaN's as equal. If True, NaN's in both objects will be considered equal.

False

Returns:

Type Description
bool

True if the two states are equal, otherwise False.

Example usage:

>>> import numpy as np
>>> from analora.state import AccuracyState
>>> state1 = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> state2 = AccuracyState(
...     y_true=np.array([1, 0, 0, 1, 1]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> state3 = AccuracyState(
...     y_true=np.array([1, 0, 0, 0, 0]),
...     y_pred=np.array([1, 0, 0, 1, 1]),
...     y_true_name="target",
...     y_pred_name="pred",
... )
>>> state1.equal(state2)
True
>>> state1.equal(state3)
False