Beispiel #1
0
        /// <summary>Combine two QuantilesEstimators.</summary>
        /// <param name="a">First QuantilesEstimator</param>
        /// <param name="b">Second QuantilesEstimator</param>
        public static QuantilesEstimator operator +(QuantilesEstimator a, QuantilesEstimator b)
        {
            var e = new QuantilesEstimator(a.P);

            for (int i = 1; i < e.N.Length; i++)
            {
                e.N[i] = a.N[i] + b.N[i];
            }
            if (a.Q[0] == b.Q[0])
            {
                e.Q[0] = a.Q[0];
                e.N[0] = a.N[0] + b.N[0];
            }
            else if (a.Q[0] < b.Q[0])
            {
                e.Q[0] = a.Q[0];
                e.N[0] = a.N[0];
            }
            else
            {
                e.Q[0] = b.Q[0];
                e.N[0] = b.N[0];
            }
            e.Q[e.Q.Length - 1] = a.Q[a.Q.Length - 1] > b.Q[b.Q.Length - 1] ? a.Q[a.Q.Length - 1] : b.Q[b.Q.Length - 1];
            var w = (double)b.N[b.N.Length - 1] / (a.N[a.N.Length - 1] + b.N[b.N.Length - 1]);

            for (int i = 1; i < e.Q.Length - 1; i++)
            {
                e.Q[i] += a.Q[i] + (b.Q[i] - a.Q[i]) * w;
            }
            return(e);
        }
Beispiel #2
0
        /// <summary>Combine another QuantilesEstimator.</summary>
        /// <param name="e">QuantilesEstimator</param>
        public void Add(QuantilesEstimator e)
        {
            for (int i = 1; i < N.Length; i++)
            {
                N[i] += e.N[i];
            }
            if (e.Q[0] == Q[0])
            {
                N[0] += e.N[0];
            }
            else if (e.Q[0] < Q[0])
            {
                Q[0] = e.Q[0];
                N[0] = e.N[0];
            }
            if (e.Q[e.Q.Length - 1] > Q[Q.Length - 1])
            {
                Q[Q.Length - 1] = e.Q[e.Q.Length - 1];
            }
            var w = (double)e.N[e.N.Length - 1] / N[N.Length - 1];

            for (int i = 1; i < Q.Length - 1; i++)
            {
                Q[i] += (e.Q[i] - Q[i]) * w;
            }
        }