Calculate entropy value.

Namespace:  AForge.Math
Assembly:  AForge.Math (in AForge.Math.dll) Version: 2.2.5.0 (2.2.5.0)

Syntax

C#
public static double Entropy(
	int[] values
)

Parameters

values
Type: array< System..::.Int32 >[]()[]
Histogram array.

Return Value

Returns entropy value of the specified histagram array.

Remarks

The input array is treated as histogram, i.e. its indexes are treated as values of stochastic function, but array values are treated as "probabilities" (total amount of hits).

Sample usage:

CopyC#
// create histogram array with 2 values of equal probabilities
int[] histogram1 = new int[2] { 3, 3 };
// calculate entropy
double entropy1 = Statistics.Entropy( histogram1 );
// output it (1.000)
Console.WriteLine( "entropy1 = " + entropy1.ToString( "F3" ) );

// create histogram array with 4 values of equal probabilities
int[] histogram2 = new int[4] { 1, 1, 1, 1 };
// calculate entropy
double entropy2 = Statistics.Entropy( histogram2 );
// output it (2.000)
Console.WriteLine( "entropy2 = " + entropy2.ToString( "F3" ) );

// create histogram array with 4 values of different probabilities
int[] histogram3 = new int[4] { 1, 2, 3, 4 };
// calculate entropy
double entropy3 = Statistics.Entropy( histogram3 );
// output it (1.846)
Console.WriteLine( "entropy3 = " + entropy3.ToString( "F3" ) );

See Also