"""Label scaling utilities for trend labelling."""
from enum import IntEnum
import numpy as np
from numpy.typing import NDArray
[docs]
class Labels(IntEnum):
"""Standard label values for trend classification."""
DOWN = -1
NEUTRAL = 0
UP = 1
# Explicit mappings from input labels to standardized values
BINARY_MAP = {0: Labels.DOWN, 1: Labels.UP}
TERNARY_MAP = {0: Labels.DOWN, 1: Labels.NEUTRAL, 2: Labels.UP}
[docs]
def scale_binary(labels: NDArray[np.int_]) -> NDArray[np.int_]:
"""Scale binary labels from {0,1} to {-1,1}.
Args:
labels (NDArray[np.int_]): Input labels (must contain only 0s and 1s)
Returns:
NDArray[np.int_]: Scaled labels in {-1,1}
"""
return np.vectorize(BINARY_MAP.get)(labels)
[docs]
def scale_ternary(labels: NDArray[np.int_]) -> NDArray[np.int_]:
"""Scale ternary labels from {0,1,2} to {-1,0,1}.
Args:
labels (NDArray[np.int_]): Input labels (must contain only 0s, 1s, and 2s)
Returns:
NDArray[np.int_]: Scaled labels in {-1,0,1}
"""
return np.vectorize(TERNARY_MAP.get)(labels)