Click or drag to resize

StatMax Method (DoubleMatrix)

Returns the maximum value and the linear index of its first occurrence in the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static IndexValuePair Max(
	DoubleMatrix data
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data to search for a maximum.

Return Value

Type: IndexValuePair
The pair given by the maximum data value and its first linear index.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
Remarks
The method returns an IndexValuePair structure which exposes the maximum data value through property Value, while the corresponding first linear position can be inspected by getting property Index.
Note Note
In the Novacta.Analytics assembly, positions of matrix entries are interpreted as linearly ordered following a column major ordering.
Examples

In the following example, the largest entry of the specified data is computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MaxExample1  
    {
        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 entry of the specified data. 
            var dataMax = Stat.Max(matrix);

            Console.WriteLine();
            Console.WriteLine("Data maximum is {0} on linear position {1}",
                dataMax.Value, dataMax.Index);

            // Max is overloaded to accept data as a read-only matrix:
            // return the largest entry using a read-only wrapper of 
            // the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var readOnlyDataMax = Stat.Max(readOnlyMatrix);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Maximum is {0} on linear position {1}",
                readOnlyDataMax.Value, readOnlyDataMax.Index);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// -1               -2               
// 2                3                
// 3                -4               
// 
// 
// 
// Data maximum is 3 on linear position 2
// 
// Using read-only data. Maximum is 3 on linear position 2

See Also