tmwavg

语法

tmwavg(T, X, Y, window)

参数说明和窗口计算规则请参考:tmFunctions

详情

在给定长度(以时间长度衡量)的滑动窗口内,以 Y 为权重(权重会自动缩放,使其元素之和为1),计算 X 元素的加权平均。

例子

T= 1 1 1 1 2 5 6 8 9 10
X = 1..10
Y = double(1..10)\10
m = table(T as t,X as x, Y as y)
select *, tmwavg(t, x, y, 3) from m
t x y tmwavg_t
1 1 0.1 1
1 2 0.2 1.6667
1 3 0.3 2.3333
1 4 0.4 3
2 5 0.5 3.6667
5 6 0.6 6
6 7 0.7 6.5385
8 8 0.8 7.5333
9 9 0.9 8.5294
10 10 1 9.0741
T = 2021.01.02 2021.01.06 join 2021.01.07..2021.01.14
X = 1..10
Y = double(1..10)\10
m=table(T as t,X as x, Y as y)
select *, tmwavg(t, y, x, 3) from m
t x y tmwavg_t
2021.01.02 1 0.1 0.1
2021.01.06 2 0.2 0.2
2021.01.07 3 0.3 0.26
2021.01.08 4 0.4 0.3222
2021.01.09 5 0.5 0.4167
2021.01.10 6 0.6 0.5133
2021.01.11 7 0.7 0.6111
2021.01.12 8 0.8 0.7095
2021.01.13 9 0.9 0.8083
2021.01.14 10 1 0.9074
select *, tmwavg(t, y, x, 1w) from m
t x y tmwavg_t
2021.01.02 1 0.1 0.1
2021.01.06 2 0.2 0.1667
2021.01.07 3 0.3 0.2333
2021.01.08 4 0.4 0.3
2021.01.09 5 0.5 0.3857
2021.01.10 6 0.6 0.45
2021.01.11 7 0.7 0.5148
2021.01.12 8 0.8 0.58
2021.01.13 9 0.9 0.6667
2021.01.14 10 1 0.7571

相关函数:wavg, mwavg