/// <summary>
        /// Multiply matrix times scalar
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>A new matrix with entry [i,j] equal to a*b[i,j]</returns>
        public static PositiveDefiniteMatrix operator *(double a, PositiveDefiniteMatrix b)
        {
            PositiveDefiniteMatrix result = (PositiveDefiniteMatrix)b.Clone();

            result.Scale(a);
            return(result);
        }
        /// <summary>
        /// Multiply matrix times scalar
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>A new matrix with entry [i,j] equal to a[i,j]*b</returns>
        public static PositiveDefiniteMatrix operator *(PositiveDefiniteMatrix a, double b)
        {
            PositiveDefiniteMatrix result = (PositiveDefiniteMatrix)a.Clone();

            result.Scale(b);
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a weighted observation.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="weight"></param>
        public void Add(Vector x, double weight)
        {
            // new_mean = mean + w/(count + w)*(x - mean)
            // new_cov = count/(count + w)*(cov + w/(count+w)*(x-mean)*(x-mean)')
            count += weight;
            if (count == 0)
            {
                return;
            }
            diff.SetToDifference(x, mean);
            double s = weight / count;

            mean.SetToSum(1.0, mean, s, diff);
            //outer.SetToOuter(diff,diff2);
            // this is more numerically stable:
            //outer.SetToOuter(diff, diff).Scale(s);
            cov.SetToSumWithOuter(cov, s, diff, diff);
            cov.Scale(1 - s);
        }