import torch


def get_numerical_characteristics(data):
    """
    返回数据(data)的 4 个数字特征(numerical characteristics):
    1. mean：均值
    2. std：标准差
    3. skewness: 偏度
    4. kurtosis: 峰度

    :param data: 数据
    :return: 一维数据: torch.Size([4])
    """
    mean = torch.mean(data)
    diffs = data - mean
    var = torch.mean(torch.pow(diffs, 2.0))
    std = torch.pow(var, 0.5)
    z_scores = diffs / std

    # 偏度：数据分布偏斜方向、程度的度量, 是数据分布非对称程度的数字特征
    # 定义: 偏度是样本的三阶标准化矩
    skewness = torch.mean(torch.pow(z_scores, 3.0))

    # excess kurtosis, should be 0 for Gaussian
    # 峰度(kurtosis): 表征概率密度分布曲线在平均值处峰值高低的特征数
    # 若峰度(kurtosis) > 3, 峰的形状会比较尖, 会比正态分布峰陡峭
    kurtoses = torch.mean(torch.pow(z_scores, 4.0)) - 3.0

    # reshape(1, )：将常量转化为torch.Size([1])型张量(Tensor)
    final = torch.cat((mean.reshape(1, ), std.reshape(1, ), skewness.reshape(1, ), kurtoses.reshape(1, )))

    return final