//-----------------------------------------------------------------------------------------------
        public static double GetMatrixPopulationVariance(RealMatrix matrix)
        {
            int    elementsCount = matrix.RowCount * matrix.ColumnCount;
            double averageValue  = matrix.GetAverageValue();
            double sum           = 0;

            for (int row = 0; row < matrix.RowCount; row++)
            {
                for (int column = 0; column < matrix.ColumnCount; column++)
                {
                    double value = matrix[row, column] - averageValue;
                    sum += value * value;
                }
            }

            double result = sum / elementsCount;

            return(result);
        }
        //-----------------------------------------------------------------------------------------------
        public static double GetMatricesCovariance(RealMatrix matrixOne, RealMatrix matrixTwo)
        {
            double result;

            double averageOne = matrixOne.GetAverageValue();
            double averageTwo = matrixTwo.GetAverageValue();

            int    elementsCount = matrixOne.RowCount * matrixOne.ColumnCount;
            double sum           = 0;

            for (int row = 0; row < matrixOne.RowCount; row++)
            {
                for (int column = 0; column < matrixOne.ColumnCount; column++)
                {
                    sum += (matrixOne[row, column] - averageOne) * (matrixTwo[row, column] - averageTwo);
                }
            }
            result = sum / elementsCount;
            return(result);
        }