Exemplo n.º 1
0
        /// <summary>
        /// Calculates the correlation between components
        /// </summary>
        /// <returns>Matrix of Correlation values</returns>
        public double[,] WCorrelation(int[] group = null)
        {
            int[] grp = group;
            if (group != null && group.Length < 2)
            {
                throw new Exception("Group must contain at least two elements.");
            }

            if (grp == null)
            {
                grp = Enumerable.Range(1, EM.Count).ToArray();
            }


            //prepare for forecasting by calculation necessary values
            var wi      = calculateWeights();
            var count   = grp.Length;
            var contrib = new List <double[]>();

            //
            foreach (var g in grp)
            {
                var c = diagonalAveraging(EM[g]);
                contrib.Add(c);
            }

            //
            var Fnorms = new double[count];

            for (int i = 0; i < count; i++)
            {
                Fnorms[i] = wi.Multiply(contrib[i].Multiply(contrib[i])).Sum();
            }

            Fnorms = Fnorms.Pow(-0.5);
            //
            var wCorr = MatrixEx.Identity(count, count);

            for (int i = 0; i < count; i++)
            {
                for (int j = i + 1; j < count; j++)
                {
                    wCorr[i, j] = Math.Round(Math.Abs(wi.Multiply(contrib[i].Multiply(contrib[j])).Sum()) * Fnorms[i] * Fnorms[j], 4);
                    wCorr[j, i] = wCorr[i, j];
                }
            }
            return(wCorr);
        }