当前位置:网站首页>指数移动加权平均
指数移动加权平均
2022-06-09 06:14:00 【GodGump】
指数移动加权平均概念
我们最常见的算数平均指的是将所有数加起来除以数的个数,每个数的权重是相同的。加权平均指的是给每个数赋予不同的权重求得平均数。移动平均数,指的是计算最近邻的 N 个数来获得平均数。
公式以及理解
公式

其中:
St 表示指数加权平均值;
Yt 表示 t 时刻的值;
β 调节权重系数,该值越大平均数越平缓。
理解
1.指数移动加权平均法,是指各数值的加权系数随时间呈指数式递减,越靠近当前时刻的数值加权系数就越大。
2.指数移动加权平均较传统的平均法来说,一是不需要保存过去所有的数值;二是计算量显著减小。
代碼实现
我们随机产生进 30 天的气温数据,来看下使用指数加权平均后的结果(原因很簡單,指数移动加权很多书上的案列都是东京天气预报)
import torch
import matplotlib.pyplot as plt
# 产生的数据
ELEMENT_NUMBER = 30
# 指数加权平均温度
def test(beta=0.9):
# 固定随机数种子
torch.manual_seed(0)
# 产生30天的随机温度
temperature = torch.randn(size=[ELEMENT_NUMBER]) * 10
print(temperature)
days = torch.arange(1, ELEMENT_NUMBER + 1, 1)
# 绘制原始数据温度曲线图和散点图
plt.plot(days, temperature, color='r')
plt.scatter(days, temperature)
plt.show()
# 用来存储指数移动加权平均后的结果
exp_weight_avg = []
# 遍历每一个温度,下标从1开始
for idx, temp in enumerate(temperature,1):
# 第一个元素的的 EWA 值等于自身
if idx == 1:
exp_weight_avg.append(temp)
continue
# 第二个元素的 EWA 值等于上一个 EWA 乘以 β + 当前气氛乘以 (1-β)
new_temp = exp_weight_avg[idx - 2] * beta + (1 - beta) * temp
exp_weight_avg.append(new_temp)
# 绘制指数加权平均后的结果
plt.plot(days, exp_weight_avg, color='r')
plt.scatter(days, temperature)
plt.show()
if __name__ == '__main__':
test(0.1)
test(0.9)
边栏推荐
- 全志平台BSP裁剪(7)rootfs裁剪--用户工具和库的裁剪 & rootfs压缩
- Abstract classes and interfaces
- Educational Codeforces Round 20 C. Maximal GCD
- Ipop-imx6q development board qt5.7 system Mplayer migration - Cross compilation libmad-0.15.1b
- NAND flash Basics
- Educational Codeforces Round 20 D. Magazine Ad
- Openresty newly added module
- [reprint] LCD common interface principle
- 工业级AM335X核心模块选型
- unity iTween使用
猜你喜欢

RNN以及其改进版(附2个代码案列)

Bladed v4.3 installation (Pojie) process

Oracle lock table solution

Talk about bladed software

全志平台BSP裁剪(3)附件二 Kernel hacking配置说明

Shopify 主题样式开发

Wireshark illustrates TCP three handshakes and four waves

工业级AM335X核心模块选型

Bladed software windfile calculation

Bladed sequential wind configuration method
随机推荐
Bladed sequential wind configuration method
Powerdns 1- introduction and installation
Coredns part 2- compiling and installing external plugins
TypeScrtipt 中的模块化
Abstract classes and interfaces
C # special syntax
全志平台BSP裁剪(7)rootfs裁剪--用户工具和库的裁剪 & rootfs压缩
The performance comparison of Quanzhi T3 (a40i) /t5 (t507) is better than that of the previous generation
小米4安装微信失败
unity3d 更换项目字体
Allocation principle of IP address
C entrustment related
[early spring 2022] [leetcode] 91 Decoding method
全志T7/T507 Qt5.12.5移植记录
邂逅 NodeJS
srs-nodejs
Coredns Part 1 Introduction and installation
unity3d 各种路径&权限
Bladed v4.3 installation (Pojie) process
两个Integer比较大小,为什么100等于100,1000不等于1000?