コード例 #1
0
        public static float [,] covariance(
            float [][] data)
        {
            data = ToolsCollection.Transpose(data);
            int column_count = data.Length;

            float [,] covariance_array = new float [column_count, column_count];
            float [] means = new float [column_count];

            for (int index_column = 0; index_column < column_count; index_column++)
            {
                means[index_column] = ToolsMathStatistics.Mean(data[index_column]);
            }

            for (int index_column = 0; index_column < column_count; index_column++)
            {
                covariance_array[index_column, index_column] = ToolsMathCollectionFloat
                                                               .covariance(data[index_column], data[index_column], means[index_column], means[index_column]);
            }

            for (int index_row = 0; index_row < column_count; index_row++)
            {
                for (int index_column = index_row + 1; index_column < column_count; index_column++)
                {
                    float covariance = ToolsMathCollectionFloat
                                       .covariance(data[index_row], data[index_column], means[index_row], means[index_column]);
                    covariance_array[index_row, index_column] = covariance;
                    covariance_array[index_column, index_row] = covariance;
                }
            }
            return(covariance_array);
        }
コード例 #2
0
        // //cov(xi, xj) = mean(xi.*xj) - mean(xi)*mean(xj);
        public static float covariance(
            float [] array_0,
            float [] array_1)
        {
            float mean_0       = ToolsMathStatistics.Mean(array_0);
            float mean_1       = ToolsMathStatistics.Mean(array_1);
            float mean_product = MeanProduct(array_0, array_1);

            return(mean_product - (mean_0 * mean_1));
        }
コード例 #3
0
 public static float [] means_row(
     float [][] array)
 {
     float [] means = new float [array.Length];
     for (int index_row = 0; index_row < array.Length; index_row++)
     {
         means[index_row] = ToolsMathStatistics.Mean(array[index_row]);
     }
     return(means);
 }