コード例 #1
0
        //public override Icon GetIcon()
        //{
        //    return null;
        //}

        private Data.TimeSeries ApplyFilterTo(Data.TimeSeries ts)
        {
            var retval = new Data.TimeSeries();

            var maOrder = maCoeffs.Length;
            var arOrder = arCoeffs.Length;

            double arSum = 0;

            for (var i = 1; i < arOrder; ++i)
            {
                arSum += arCoeffs[i];
            }
            double maSum = 0;

            for (var i = 0; i < maOrder; ++i)
            {
                maSum += maCoeffs[i];
            }

            // now go through and apply filter
            for (var t = 0; t < ts.Count; ++t)
            {
                var tx = 0.0;
                if (TimeInterval.Ticks == 0) // apply the filter to successive data points
                {
                    // get MA part
                    for (var i = 0; i < maOrder; ++i)
                    {
                        tx += t >= i ? maCoeffs[i] * ts[t - i] : ts[0];
                    }
                    // get AR part
                    for (var i = 1; i < arOrder; ++i)
                    {
                        tx += t >= i ? arCoeffs[i] * retval[t - i] : ts[0];
                    }
                    tx /= arSum + maSum;
                }
                else // apply the filter to data points at specified sampling interval
                {
                    // get MA part
                    for (var i = 0; i < maOrder; ++i)
                    {
                        tx += maCoeffs[i] * ts.ValueAtTime(ts.TimeStamp(t) - new TimeSpan(i * TimeInterval.Ticks));
                    }
                    // get AR part
                    for (var i = 1; i < arOrder; ++i)
                    {
                        tx += arCoeffs[i] * retval.ValueAtTime(ts.TimeStamp(t) - new TimeSpan(i * TimeInterval.Ticks));
                    }
                    tx /= arSum + maSum;
                }

                retval.Add(ts.TimeStamp(t), tx, false);
            }

            return(retval);
        }
コード例 #2
0
        private Data.TimeSeries DoUnivariateSampling(Data.TimeSeries ofTS)
        {
            var retval = new Data.TimeSeries();

            retval.Title = ofTS.Title;

            if (SamplingInterval.Ticks == 0)
            {
                int  i0, i1;
                bool gotHit;
                i0 = ofTS.IndexAtOrBefore(StartTime, out gotHit);
                if (!gotHit)
                {
                    ++i0;
                }
                i1 = ofTS.IndexAtOrBefore(EndTime, out gotHit);
                ++i1;
                if (i1 > ofTS.Count)
                {
                    i1 = ofTS.Count;
                }
                for (var t = i0; t < i1; ++t)
                {
                    retval.Add(ofTS.TimeStamp(t), ofTS[t], false);
                }
            }
            else
            {
                for (var current = new DateTime(StartTime.Ticks);
                     current < EndTime;
                     current = new DateTime((current + SamplingInterval).Ticks))
                {
                    foreach (var sampleOffset in SamplingBaseOffsets)
                    {
                        var adjusted = current + sampleOffset;
                        var skipping = false;
                        if (SkipWeekends)
                        {
                            if (adjusted.DayOfWeek == DayOfWeek.Saturday || adjusted.DayOfWeek == DayOfWeek.Sunday)
                            {
                                skipping = true;
                            }
                        }
                        if (IsWithinSkipIntervals(adjusted))
                        {
                            skipping = true;
                        }

                        if (!skipping)
                        {
                            var sampled = ofTS.ValueAtTime(adjusted);
                            retval.Add(adjusted, sampled, false);
                        }
                    }
                }
            }

            return(retval);
        }
コード例 #3
0
        //public override Icon GetIcon()
        //{
        //    return null;
        //}

        private Data.TimeSeries ApplyFilterTo(Data.TimeSeries ts)
        {
            var retval = new Data.TimeSeries();

            // now go through and apply filter
            for (var t = 0; t < ts.Count; ++t)
            {
                var tx = 0.0;
                // get MA part
                tx += (1 - SmoothFactor) * ts[t];
                // get AR part
                tx += t >= 1 ? SmoothFactor * retval[t - 1] : 0;
                retval.Add(ts.TimeStamp(t), tx, false);
            }

            return(retval);
        }