tensorflow TensorBoard标量图中“平滑”参数背后的数学原理是什么?

pkln4tw6  于 2023-02-13  发布在  其他
关注(0)|答案(3)|浏览(578)

我假设它是某种移动平均线,但有效范围在0和1之间。

k4emjkb1

k4emjkb11#

下面是执行指数平滑的实际源代码,注解中解释了一些额外的去偏,以补偿零初始值的选择:

last = last * smoothingWeight + (1 - smoothingWeight) * nextVal

图片来源:www.example.comhttps://github.com/tensorflow/tensorboard/blob/34877f15153e1a2087316b9952c931807a122aa7/tensorboard/components/vz_line_chart2/line-chart.ts#L714

06odsfpq

06odsfpq2#

用于TensorBoard的EMA平滑实现可以在这里找到。
Python中的等价物实际上是:

def smooth(scalars: list[float], weight: float) -> list[float]:
    """
    EMA implementation according to
    https://github.com/tensorflow/tensorboard/blob/34877f15153e1a2087316b9952c931807a122aa7/tensorboard/components/vz_line_chart2/line-chart.ts#L699
    """
    last = 0
    smoothed = []
    num_acc = 0
    for next_val in scalars:
        last = last * weight + (1 - weight) * next_val
        num_acc += 1
        # de-bias
        debias_weight = 1
        if weight != 1:
            debias_weight = 1 - math.pow(weight, num_acc)
        smoothed_val = last / debias_weight
        smoothed.append(smoothed_val)

    return smoothed
nwnhqdif

nwnhqdif3#

它被称为指数移动平均线,下面是一个代码解释它是如何创建的。
假设所有真实的标量值都在一个名为scalars的列表中,平滑应用如下:

def smooth(scalars: List[float], weight: float) -> List[float]:  # Weight between 0 and 1
    last = scalars[0]  # First value in the plot (first timestep)
    smoothed = list()
    for point in scalars:
        smoothed_val = last * weight + (1 - weight) * point  # Calculate smoothed value
        smoothed.append(smoothed_val)                        # Save it
        last = smoothed_val                                  # Anchor the last smoothed value

    return smoothed

相关问题