简体   繁体   English

如何生成嘈杂的模拟时间序列或信号(在Python中)

[英]How to generate noisy mock time series or signal (in Python)

Quite often I have to work with a bunch of noisy, somewhat correlated time series. 我常常需要处理一堆嘈杂的,有点相关的时间序列。 Sometimes I need some mock data to test my code, or to provide some sample data for a question on Stack Overflow. 有时我需要一些模拟数据来测试我的代码,或者为Stack Overflow上的问题提供一些示例数据。 I usually end up either loading some similar dataset from a different project, or just adding a few sine functions and noise and spending some time to tweak it. 我通常最终会从不同的项目中加载一些类似的数据集,或者只是添加一些正弦函数和噪声并花一些时间来调整它。

What's your approach? 你的方法是什么? How do you generate noisy signals with certain specs? 如何使用某些规格生成噪声信号? Have I just overlooked some blatantly obvious standard package that does exactly this? 我是否只是忽略了一些明显明显的标准包装呢?

The features I would generally like to get in my mock data: 我通常希望在我的模拟数据中获得的功能:

  • Varying noise levels over time 随着时间的推移噪音水平不同
  • Some history in the signal (like a random walk?) 信号中的一些历史(如随机漫步?)
  • Periodicity in the signal 信号的周期性
  • Being able to produce another time series with similar (but not exactly the same) features 能够生成具有相似(但不完全相同)特征的另一个时间序列
  • Maybe a bunch of weird dips/peaks/plateaus 也许是一堆奇怪的逢低/峰值/高原
  • Being able to reproduce it (some seed and a few parameters?) 能够重现它(一些种子和一些参数吗?)

I would like to get a time series similar to the two below [A]: 我想得到一个类似下面两个[A]的时间序列:

实时系列1 实时系列2

I usually end up creating a time series with a bit of code like this: 我通常最终创建一个时间序列,其代码如下:

import numpy as np

n = 1000
limit_low = 0
limit_high = 0.48
my_data = np.random.normal(0, 0.5, n) \
          + np.abs(np.random.normal(0, 2, n) \
                   * np.sin(np.linspace(0, 3*np.pi, n)) ) \
          + np.sin(np.linspace(0, 5*np.pi, n))**2 \
          + np.sin(np.linspace(1, 6*np.pi, n))**2

scaling = (limit_high - limit_low) / (max(my_data) - min(my_data))
my_data = my_data * scaling
my_data = my_data + (limit_low - min(my_data))

Which results in a time series like this: 这会产生如下时间序列:

模拟时间序列

Which is something I can work with, but still not quite what I want. 这是我可以使用的东西,但仍然不是我想要的。 The problem here is mainly that: 这里的问题主要是:

  1. it doesn't have the history/random walk aspect 它没有历史/随机游走方面
  2. it's quite a bit of code and tweaking (this is especially a problem if i want to share a sample time series) 它是相当多的代码和调整(如果我想分享一个示例时间序列,这尤其是一个问题)
  3. I need to retweak the values (freq. of sines etc.) to produce another similar but not exactly the same time series. 我需要重新记录值(正弦等的频率)以产生另一个相似但不完全相同的时间序列。

[A]: For those wondering, the time series depicted in the first two images is the traffic intensity at two points along one road over three days (midnight to 6 am is clipped) in cars per second (moving hanning window average over 2 min). [A]:对于那些想知道的人来说,前两张图片中描绘的时间序列是每秒车辆在三天(午夜到早上6点被修剪)的两条路上的两个点的交通强度(移动汉宁窗平均超过2分钟) )。 Resampled to 1000 points. 重新采样到1000点。

Have you looked into TSimulus ? 你看过TSimulus了吗? By using Generators , you should be able generate data with specific patterns, periodicity, and cycles. 通过使用Generators ,您应该能够生成具有特定模式,周期性和周期的数据。

The TSimulus project provides tools for specifying the shape of a time series (general patterns, cycles, importance of the added noise, etc.) and for converting this specification into time series values. TSimulus项目提供了用于指定时间序列形状(一般模式,周期,增加的噪声的重要性等)以及将此规范转换为时间序列值的工具。


Otherwise, you can try "drawing" the data yourself and exporting those data points using Time Series Maker . 否则,您可以尝试自己“绘制”数据并使用Time Series Maker导出这些数据点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM