mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-04-04 04:18:22 +00:00
Huffman base2/3
This commit is contained in:
19
Esiur.Analysis/Coding/Functions.cs
Normal file
19
Esiur.Analysis/Coding/Functions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user