2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
2023-04-04 18:38:28 +03:00

25 lines
616 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Esiur.Analysis.Coding
{
public static class Functions
{
public static double Entropy(int[] frequencies)
{
double total = frequencies.Sum();
return frequencies.Sum(x => ((double)x / total * -Log2(x)));
}
public static double AverageLength<T>(this CodeWord<T>[] words)
{
return words.Sum(x => x.Length) / (double)words.Length;
}
public static double Log2(double value) => Math.Log10(value) / Math.Log10(2);
}
}