Python_滑动窗口

发布时间 2023-10-09 14:13:41作者: 辰令

SQL中窗口函数

常用窗口函数
窗口函数主要分为了聚合、排序、分布、平移及首尾等类型
1) 聚合函数:sum()、count()、max()、min()、avg()   
2) 排序函数:row_number()、rank()、dense_rank()    
3) 分布函数:percent_rank()、cume_dist()
4) 平移函数:lead()、lag()
5) 首尾函数:first_val()、last_val()

窗口大小--over
   rows frame_start   or  rows between frame_start and frame_end

python窗口

数值型数据,Pandas 提供了几种窗口函数,比如移动函数(rolling)、扩展函数(expanding)和指数加权函数(ewm)
  ewm(全称 Exponentially Weighted Moving)表示指数加权移动

滑窗

滑动窗口计算,最容易想到的就是用两层for循环来实现
def sliding_window(data, window_size, step_size):
    window_sequences = [data[i:i+window_size] for i in range(0, len(data)-window_size+1, step_size)]
    result = [sum(sequence) for sequence in window_sequences]
    return result
###滑窗的大小和滑动步长。滑窗大小表示滑窗子序列的长度,滑动步长表示滑动窗口每次移动的距离

def sliding_windows(timestamps,step,exclude=2):
    cur_idx = 0
    while(cur_idx < len(timestamps)):
        target_ts = timestamps[cur_idx]
        selected = range(max(0, cur_idx), min(cur_idx + step, len(timestamps)))
        cur_idx += step
        timestamps_window = [timestamps[s] for s in selected]
        if len(timestamps_window) < exclude:
            print(f" timestamps_window len = {len(timestamps_window)}")
            break
		###滑窗内操作	
        for i, ts in enumerate(timestamps_window):
            sensor= os.path.join(root_path, ts+r"."+"json")
            calib = json.load(open(sensor, 'r'))

点云下采样

random_down_sample(pcd, sampling_ratio):
   从输入点云pcd中选择n*sampling_ratio随机点。它可以用于数据增强,因为每次都选择不同的点。但是,它对噪声很敏感。
uniform_down_sample(every_k_points):
    根据点的顺序统一选择点。它每隔every_k_points选择一个点。第一个点(索引为0)总是被选中。
	因此,所选点的索引为:0,every_k_points, 2 *every_k_points等。
	如果输入点云是有组织的,则该函数返回一个均匀的点云;否则,它与第一种方法类似,只是每次都会生成相同的输出。
voxel_down_sample(voxel_size):
     创建3D体素网格

Moving Window

滑窗(Moving  Window)算法	
跳窗(Jumping Window)算法  漏桶算法(Leaky Bucket)
选择性搜索(Selective Search)    

参考

Python滑窗实现教程 https://blog.51cto.com/u_16175490/7383370
数据统计—滑动窗口 https://book.itheima.net/course/221/1270308811000782849/1271374094515838977
 Python滑动窗口用法介绍 https://www.python100.com/html/Q02B5K8M1E3R.html