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 |
required |
y_pred
|
ndarray
|
The predicted labels. This input must be an
array of shape |
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: |
'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
|
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 |
False
|
Returns:
Type | Description |
---|---|
bool
|
|
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