Ejemplo n.º 1
0
        private double CalculateNextXSimple(Random rnd, DoubleSeries s, ARMASeriesConfig c)
        {
            var ar_part = 0.0;
            var ma_part = 0.0;

            // AR
            for (int j = 0, x_Count = s.X.Count; j < c.P.Length && j < s.X.Count; j++)
            {
                ar_part += c.P[j] * s.X[x_Count - 1 - j];
            }

            // MA
            for (int j = 0, e_Count = s.E.Count; j < c.Q.Length && j < s.E.Count; j++)
            {
                ma_part += c.Q[j] * s.E[s.E.Count - 1 - j];
            }

            var et = rnd.NextGaussian_BoxMuller(c.Mean, c.StdDev); // next noise/shock
            var xt = c.C + et + ar_part + ma_part;                 // next sensor value

            s.E.Add(et);
            s.X.Add(xt);

            return(xt);
        }
Ejemplo n.º 2
0
        private double CalculateNextX(Random rnd, DoubleSeries s, ARMASeriesConfig c)
        {
            var ar_part = 0.0;
            var ma_part = 0.0;

            // AR
            for (int j = 0, x_Count = s.X.Count; j < c.P.Length && j < s.X.Count; j++)
            {
                ar_part += c.P[j] * s.X[x_Count - 1 - j];
            }

            // MA
            for (int j = 0, e_Count = s.E.Count; j < c.Q.Length && j < s.E.Count; j++)
            {
                ma_part += c.Q[j] * s.E[s.E.Count - 1 - j];
            }


            // Drivers
            var ar_part_drivers = 0.0;
            var ma_part_drivers = 0.0;

            lock (seriesDict)
                CalculateDriverParts(c.Drivers, out ar_part_drivers, out ma_part_drivers);

            var et = rnd.NextGaussian_BoxMuller(c.Mean, c.StdDev);                     // next noise/shock
            var xt = c.C + et + ar_part + ma_part + ar_part_drivers + ma_part_drivers; // next sensor value

            lock (seriesDict) {
                if (s.X.Count > MAX_BUFFER_SIZE)
                {
                    s.X.RemoveAt(0);
                }
                if (s.E.Count > MAX_BUFFER_SIZE)
                {
                    s.E.RemoveAt(0);
                }
                s.E.Add(et);
                s.X.Add(xt);
            }

            return(xt);
        }
Ejemplo n.º 3
0
        private void StreamSeries(StreamingJob job, ARMASeriesConfig c)
        {
            DateTime dtts = new DateTime(1000, 1, 1, 0, 0, 0, 0);

            for (long i = 0; true; i++)
            {
                job.Token.ThrowIfCancellationRequested();

                double xt = 0.0;
                try {
                    lock (seriesDict)
                        xt = CalculateNextX(rnd, series, c);
                } catch (Exception ex) {
                    Console.WriteLine(ex.Message + "\n" + ex.Source);
                }


                if (c.Export && i > c.Delay)
                {
                    double outlierCandidate = rnd.NextDouble();
                    if (outlierCandidate < c.OutlierRatio3s)
                    {
                        xt = GenerateOutlier(rnd, xt, series.X, 3, 5);
                    }
                    else if (outlierCandidate < c.OutlierRatio2s)
                    {
                        xt = GenerateOutlier(rnd, xt, series.X, 2, 3);
                    }

                    // string timestamp = DateTime.Now.ToString(DATETIME_FORMAT); // v1
                    string timestamp = dtts.ToString(generatorConfig.DateTimeFormat); // v2
                    var    msg       = JsonConvert.SerializeObject(GenerateMessage(c, group, timestamp, xt));
                    job.Client.Publish(config.Topic, Encoding.UTF8.GetBytes(msg));
                    Thread.Sleep(c.Interval);
                    dtts = dtts.AddMilliseconds(c.Interval); // v2
                }
                else if (i > c.Delay)
                {
                    Thread.Sleep(c.Interval);
                }
            }
        }