Some operations on matrix

17 views
Skip to first unread message

Christian LeMoussel

unread,
Nov 25, 2013, 3:06:16 AM11/25/13
to accor...@googlegroups.com
Hi all,

I have a symetric square matrix A.
    double[,] A =
   
{
       
{ 100.00, 27.56, 33.89},
       
{
27.56, 100.00, 24.76},
       
{
33.89, 24.76, 100.00}
   
};
The values ​​in matrix are percentages of similarity between texts.

Without taking the value of the diagonal, I would like to calculate

A
verage  by line
:
Average1 = (27.56 + 33.89) / 2 = 30.73
Average1 = (27.5624.76) / 2 = 26.16
Average3 = (33.89, 24.76) / 2 = 29.33

Total Average :
TotalAverage = (30.73 + 26.16 + 29.33) / 3 = 28.74


Is it possible to calculate these averages with Accord.NET framework?

Regards.

Christian.




César

unread,
Nov 25, 2013, 4:06:50 AM11/25/13
to accor...@googlegroups.com
Hi Christian!

Well, you could try computing the mean using Statistics.Tools.Mean and then removing the influence of the diagonal afterwards. Otherwise, you could set the diagonal to zero, compute the sum and divide by the new number of samples. Perhaps something like this might work:

            double[,] a =

           
{
               
{ 100.00, 27.56, 33.89},
               
{ 27.56, 100.00, 24.76},
               
{ 33.89, 24.76, 100.00}
           
};


            a
= a.Subtract(Matrix.Diagonal(3, 100.0));

           
var mean = a.Sum().Divide(2);



Hope it helps!

Regards,
Cesar

Christian LeMoussel

unread,
Nov 25, 2013, 7:45:15 AM11/25/13
to accor...@googlegroups.com
Thank's for you help César.

With this  square array, I use System.Array.GetLength(int dimension) to get the length of a specific dimension.

var mean = A.Sum().Divide(A.GetLength(0) - 1);

Reply all
Reply to author
Forward
0 new messages