Exemple #1
0
        private void addCache(DataSeries arrY, int x)
        {
            double           y = arrY[x];
            OnlineRegression temp;

            //# 新しい列を作成
            stats[x]    = new Dictionary <int, OnlineRegression>();
            stats[x][x] = new OnlineRegression();
            stats[x][x].push(x, y);
            int p    = getPrevIndex(x);
            int prev = (p >= 0) ? cachedXY[p].Key : -1;

            //# 対象期間の値を加算
            temp = new OnlineRegression();
            for (int j = prev + 1; j <= x; j++)
            {
                temp.push(j, arrY[j]);
            }


            //# 直前のデータがあれば行に合計値をセット
            if (p >= 0)
            {
                int limit = x - (int)(LookBack * 1.5);
                foreach (KeyValuePair <int, OnlineRegression> kv in stats[prev])
                {
                    if (kv.Key < limit)
                    {
                        continue;
                    }
                    stats[x][kv.Key] = kv.Value + temp;
                }
            }
            //# 以降にデータがあれば
            int sz = cachedXY.Count;

            if (p + 1 < sz)
            {
                int last = cachedXY[sz - 1].Key;
                temp = new OnlineRegression();
                for (int j = x; j <= last; j++)
                {
                    temp.push(j, arrY[j]);
                    Dictionary <int, OnlineRegression> o;
                    if (stats.TryGetValue(j, out o))
                    {
                        stats[j][x] = temp;
                    }
                }
            }

            int i_ins = p + 1;

            cachedXY.Insert(i_ins, new KeyValuePair <int, double>(x, y));
        }
Exemple #2
0
        public static OnlineRegression operator +(OnlineRegression a, OnlineRegression b)
        {
            OnlineRegression combined = new OnlineRegression();

            combined.n  = a.n + b.n;
            combined.x  = a.x + b.x;
            combined.y  = a.y + b.y;
            combined.xx = a.xx + b.xx;
            combined.yy = a.yy + b.yy;
            combined.xy = a.xy + b.xy;
            return(combined);
        }