Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何为数据流挖掘创建滑动窗口模型?

我们有一种情况,即流(来自传感器的数据或服务器上的单击流数据)通过滑动窗口算法传输,我们必须将最后(例如)500个数据样本存储在内存中。然后将这些样本用于创建直方图,聚合和捕获有关输入数据流中异常的信息。

请告诉我如何制作这种滑动窗口。



回答:

如果要问如何以滑动窗口方式存储和维护这些值,请考虑以下简单示例,该示例跟踪一些随机数据流的最后10个值的运行平均值:

WINDOW_SIZE = 10; x = nan(WINDOW_SIZE,1); %# init counter = 0; stats = [NaN NaN]; %# previous/current value %# prepare figure SHOW_LIM = 200; hAx = axes('XLim',[1 SHOW_LIM], 'YLim',[200 800]); hLine = line('XData',1, 'YData',nan, 'EraseMode','none', ... 'Parent',hAx, 'Color','b', 'LineWidth',2); %# infinite loop! while true val = randi([1 1000]); %# get new value from data stream x = [ x(2:end) ; val ]; %# add to window in a cyclic manner counter = counter + 1; %# do something interesting with x stats(1) = stats(2); %# keep track of the previous mean stats(2) = nanmean(x); %# update the current mean %# show and update plot set(hLine, 'XData',[counter-1 counter], 'YData',[stats(1) stats(2)]) if rem(counter,SHOW_LIM)==0 %# show only the last couple of means set(hAx, 'XLim', [counter counter+SHOW_LIM]); end drawnow pause(0.02) if ~ishandle(hAx), break, end %# break in case you close the figure end

更新资料

在最近的版本中,不推荐使用EraseMode=none属性并将其删除。请改用animatedline函数来实现类似功能。



更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 04:59


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.