Click or drag to resize

StatMax Method (DoubleMatrix, DataOperation)

Returns the largest entries in rows or columns of the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static IndexValuePair[] Max(
	DoubleMatrix data,
	DataOperation dataOperation
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data to search for maxima.
dataOperation
Type: Novacta.AnalyticsDataOperation
A constant to specify if row or column maxima are to be computed.

Return Value

Type: IndexValuePair
The pairs given by the maximum values and their first indexes.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptiondataOperation is not a field of DataOperation.
Remarks

Operating on rows

If dataOperation is OnRows, then the method returns an array of IndexValuePair structures, one for each row in data. The i-th array entry exposes the maximum value in the i-th row through property Value, while the corresponding first column position in the row can be inspected by getting property Index.

Operating on columns

If dataOperation is OnColumns, then the method returns an array of IndexValuePair structures, one for each column in data. The j-th array entry exposes the maximum value in the j-th column through property Value, while the corresponding first row position in the column can be inspected by getting property Index.

Examples

In the following example, row and column largest entries of the specified data are computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MaxExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
               -1, -2,
                2,  3,
                3, -4
            };
            var matrix = DoubleMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Return the largest entries in columns of the specified data. 
            var columnMaxs = Stat.Max(matrix, DataOperation.OnColumns);

            Console.WriteLine();
            for (int j = 0; j < matrix.NumberOfColumns; j++) {
                Console.WriteLine("Column {0}: maximum is {1} on row {2}",
                    j, columnMaxs[j].Value, columnMaxs[j].Index);
            }

            // Max is overloaded to accept data as a read-only matrix:
            // return the largest entries in rows using a read-only wrapper of 
            // the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var rowMaxs = Stat.Max(readOnlyMatrix, DataOperation.OnRows);

            Console.WriteLine();
            for (int i = 0; i < readOnlyMatrix.NumberOfRows; i++) {
                Console.WriteLine("Row {0}: maximum is {1} on column {2}",
                    i, rowMaxs[i].Value, rowMaxs[i].Index);
            }
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// -1               -2               
// 2                3                
// 3                -4               
// 
// 
// 
// Column 0: maximum is 3 on row 2
// Column 1: maximum is 3 on row 1
// 
// Row 0: maximum is -1 on column 0
// Row 1: maximum is 3 on column 1
// Row 2: maximum is 3 on column 0

See Also