2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
2023-03-27 15:12:40 +03:00

20 lines
455 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 Log2(double value) => Math.Log10(value) / Math.Log10(2);
}
}