import numpy as np

__all__ = ['sigmoid']


def sigmoid(x):
    """Sigmoid activation function.

    Applies the sigmoid function element-wise to the input, with overflow protection.

    Parameters
    ----------
    - `x` : `np.ndarray | float`
        - Input data to be transformed

    Returns
    ----------
    - `np.ndarray | float`
        - Sigmoid transformation of input, bounded between 0 and 1

    Notes
    ----------
    The function clips input values to [-200, 200] to prevent numerical overflow.
    """
    x = np.clip(x, -200, 200)  # 防止溢出
    return 1 / (1 + np.exp(-x))
