测试系统稳定性的功能,接收预测的时间序列作为输入 [英] Function for testing system stability, which receives predicted time series as input

查看:133
本文介绍了测试系统稳定性的功能,接收预测的时间序列作为输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个将时间序列和标准差作为参数并返回调整后的时间序列(类似于预测)的函数.

I want to write a function that gets a time series and a standard deviation as parameters and returns an adjusted time series which looks like a forecast.

使用此功能,我想测试系统的稳定性,该系统将获取天气预报的时间序列表作为输入参数.

With this function I want to test a system for stability, which gets a forecasted time series list for weather as input parameter.

我对这种功能的处理方式,如下所述:

My approach for such a function, which is described below:

vector<tuple<datetime, double>> get_adjusted_timeseries(vector<tuple<datetime, double>>& timeseries_original, const double stddev, const double dist_mid)
{

    auto timeseries_copy(timeseries_original);

    int sign = randInRange(0, 1) == 0 ? 1 : -1;


    auto left_limit = normal_cdf_inverse(0.5 - dist_mid, 0, stddev);
    auto right_limit = normal_cdf_inverse(0.5 + dist_mid, 0, stddev);

    for (auto& pair : timeseries_copy)
    {
        double number;
        do
        {
            nd_value = normal_distribution_r(0, stddev);
        }
        while (sign == -1 && nd_value > 0.0 || sign == 1 && nd_value < 0.0);


        pair = make_tuple(get<0>(pair), get<1>(pair) + (nd_value / 100) * get<1>(pair));


        if (nd_value > 0.0 && nd_value < right_limit || nd_value < 0.0 && nd_value > left_limit)
        {
            sign = sign == -1 ? 1 : -1;
        }
    }

    return timeseries_copy;
}

  • 从原始时间序列复制副本,该时间序列也来自类型vector<tuple<datetime, double>>
  • 获取0或1的随机数,并使用该数字设置符号.
  • 使用逆累积分布函数来获取限制,该限制指示何时更改符号.当复制的时间序列的值接近原始值时,将更改符号. 此处显示了逆CDF的实现
  • 时间序列中每个项目的循环:
    • 获取正态分布值,当sign == -1时应为零,而当sign == 1时应为零.
    • 根据正态分布调整时间序列的旧值 值
    • 如果正态分布值接近原始值,请
    • 更改sign.
      • Make a copy from the original time series, which is also from type vector<tuple<datetime, double>>
      • Get a random number that is either 0 or 1 and use the number to set the sign.
      • Use the Inverse Cumulative distribution function to get the limits, which indicate when the sign is changed. The sign is changed when the value of the copied time series is close to the original value. The implementation of the inverse CDF is shown here
      • For-loop for each item in the time series:
        • get a normal distributed value, which should be lower zero when sign == -1 and greater zero when sign == 1
        • adjust old value of time series according to the normal distributed value
        • change sign if the normal distributed value is close to the original value.
        • 例如,对于低标准偏差的结果可以在黄色处看到: 如果计算两个时间序列的平均绝对百分比误差(MAPE),则将得出以下关系:

          The result for a low standard deviation, for example, can be seen here in yellow: If the mean absolute percentage error (MAPE) of the two time series is calculated, the following relationship results:

          • stddev:5-> MAPE:〜0.04
          • stddev:10-> MAPE:〜0.08
          • stddev:15-> MAPE:〜0.12
          • stddev:20-> MAPE:〜0.16

          您如何看待这种方法?

          此功能可以用于测试必须处理预测时间序列的系统吗?

          Can this function be used to test a system that has to deal with predicted time series?

          推荐答案

          您要生成的时间序列数据的行为类似于实际现象(天气和证券交易所)中现有的一些时间序列数据.生成的时间序列数据将被馈送到某些系统中以测试其稳定性.

          You want to generate time series data that behave like some existing time series data that you have from real phenomena (weather and stock exchange). That generated time series data will be fed into some system to test its stability.

          您可以做的是:将一个模型适合您现有的数据,然后使用该模型生成遵循该模型的数据,从而生成现有数据.将数据拟合到模型会产生一组模型参数和一组偏差(差异未由模型解释).偏差可以遵循某些已知的密度函数,但不必遵循.给定模型参数和偏差,您可以生成看起来像原始数据的数据.请注意,如果模型不能很好地解释数据,则偏差会很大,并且模型生成的数据将看起来与原始数据不一样.

          What you could do is: fit some model to your exiting data, and then use that model to generate data that follow the model, and hence your existing data. Fitting data to a model yields a set of model parameters and a set of deviations (differences not explained by the model). The deviations may follow some known density function but not necessarily. Given the model parameters and deviations, you can generate data that look like the original data. Note that if the model does not explain the data well, deviations will be large, and the data generated with the model will not look like the original data.

          例如,如果您知道数据是线性的,则可以通过它们拟合一条线,而模型将是:

          For example, if you know your data is linear, you fit a line through them, and your model would be:

          y = M x + B + E
          

          其中,E是随机变量,其遵循适合您数据的线周围的误差分布,而MB是模型参数.现在,您可以使用该模型生成线性粗糙的(x, y)坐标.在对随机变量E进行采样时,可以假定它遵循某种已知分布(如正态分布),或者使用直方图来生成遵循任意密度函数的偏差.

          where E is a random variable that follows the distribution of the error around the line that fits your data, and where M and B are the model parameters. You can now use that model to generate (x, y) coordinates that are rougly linear. When sampling the random variable E, you can assume that it follows some known distribution like a normal distribution, or use an histogram, to generate deviations that follow arbitrary density functions.

          您可以使用多种时间序列模型来拟合天气和证券交易所数据.您可以查看指数平滑.它有几种不同的模型.我相信您可以在Wikipedia上找到许多其他模型.

          There are several time series models that you could use to fit your weather and stock exchange data. You could look at exponential smoothing. It has several different models. I am sure you can find many other models on Wikipedia.

          如果模型不能很好地适合您的数据,您还可以将其参数视为随机变量.在上面的示例中,假设我们已经观察到了似乎斜率正在变化的数据.我们将拟合多行并获得M的分布.然后,在生成数据时,我们将对该变量与E一起进行采样.

          If a model does not fit well your data, you can also see its parameters as random variables. In our example above, suppose that we have observed data where it seems that the slope is changing. We would fit several lines and obtain a distribution for M. We would then sample that variable along with E when generating data.

          这篇关于测试系统稳定性的功能,接收预测的时间序列作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆