以另一个值为条件重新采样分布

Resample a distribution conditional on another value

我想通过从经验观察中重新采样来创建一系列模拟值。我拥有的数据是 1 分钟频率的时间序列。模拟应该在任意天数和每天相同的时间进行。不同之处在于,我需要根据时间进行采样,即当采样时间为 8:00 时,应该更有可能在 8:00 附近采样一个值(但不限于 8:00) 来自原始系列。

我画了一个小草图来展示绘制分布如何根据模拟 a 值的时间而变化:

即对于 T=0,更有可能从一天中时间接近 0 的实际分布中得出一个值,而不太可能在一天中的 T=n/2 时间从原始分布中得出一个值,或者稍后,其中 n 是一天中唯一时间戳的数量。

这里是生成示例数据的代码片段(我知道没有必要根据这个测试数据进行条件采样,但这只是为了展示数据的结构)

import numpy as np
import pandas as pd

# Create a test data frame (only for illustration)
df = pd.DataFrame(index=pd.date_range(start='2020-01-01', end='2020-12-31', freq='T'))
df['MyValue'] = np.random.normal(0, scale=1, size=len(df))
print(df)

                      MyValue
2020-01-01 00:00:00  0.635688
2020-01-01 00:01:00  0.246370
2020-01-01 00:02:00  1.424229
2020-01-01 00:03:00  0.173026
2020-01-01 00:04:00 -1.122581
                       ...
2020-12-30 23:56:00 -0.331882
2020-12-30 23:57:00 -2.463465
2020-12-30 23:58:00 -0.039647
2020-12-30 23:59:00  0.906604
2020-12-31 00:00:00 -0.912604
[525601 rows x 1 columns]

# Objective: Create a new time series, where each time the values are 
# drawn conditional on the time of the day

我无法在这里找到符合我要求的答案。感谢所有帮助。

我考虑这句话:

need to sample conditional on the time, i.e. when sampling for a time of 8:00, it should be more probable to sample a value around 8:00 (but not limited to 8:00) from the original serie.

然后,假设标准差是一天的六分之一(根据您的绘图)

value = np.random.normal(loc=current_time_sample, scale=total_samples/6)