2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2023-04-04 18:38:28 +03:00
parent 5966598c9f
commit 0ceaee88aa
6 changed files with 76 additions and 6 deletions

View File

@ -7,6 +7,5 @@ namespace Esiur.Analysis.Coding
public class Arithmetic<T> where T : System.Enum
{
}
}

View File

@ -0,0 +1,34 @@
using Esiur.Analysis.Graph;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Analysis.Coding
{
internal class BlockCode<T> where T : struct
{
public Matrix<T> Generator { get; private set; }
public Matrix<T> ParityCheck { get; private set; }
int k = 0;
Matrix<T> p;
public BlockCode(Matrix<T> parityMatrix, T identity)
{
// create generator matrix from parity matrix
// K = number of rows
p = parityMatrix;
k = parityMatrix.Rows;
var g = new Matrix<T>(p.Rows, p.Columns + p.Rows);
for(var i = 0; i < p.Rows; i++)
for(var j = 0; j < p.Columns; j++)
g[i, j] = p[i, j];
for (var i = 0; i < k; i++)
g[i, p.Columns + i] = (T)1;
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.Text;
@ -41,6 +42,16 @@ namespace Esiur.Analysis.Coding
Two
}
public interface BaseNumber<T>
{
public static T AdditiveIdentity { get; }
public static T MultiplicativeIdentity { get; }
//public
}
//public struct BinaryValue : IBaseValue<Base2>
//{
// public Base2 Value { get; set; }

View File

@ -14,6 +14,11 @@ namespace Esiur.Analysis.Coding
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);
}
}

View File

@ -23,7 +23,7 @@ namespace Esiur.Analysis.Coding
return ToString().GetHashCode();
}
public int Length => Word.Length;
public static CodeWord<Base2> FromByte(byte b)
{