mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
LBC
This commit is contained in:
parent
5966598c9f
commit
0ceaee88aa
@ -7,6 +7,5 @@ namespace Esiur.Analysis.Coding
|
|||||||
public class Arithmetic<T> where T : System.Enum
|
public class Arithmetic<T> where T : System.Enum
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
Esiur.Analysis/Coding/BlockCode.cs
Normal file
34
Esiur.Analysis/Coding/BlockCode.cs
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Microsoft.CodeAnalysis;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -41,6 +42,16 @@ namespace Esiur.Analysis.Coding
|
|||||||
Two
|
Two
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface BaseNumber<T>
|
||||||
|
{
|
||||||
|
public static T AdditiveIdentity { get; }
|
||||||
|
public static T MultiplicativeIdentity { get; }
|
||||||
|
|
||||||
|
//public
|
||||||
|
}
|
||||||
|
|
||||||
//public struct BinaryValue : IBaseValue<Base2>
|
//public struct BinaryValue : IBaseValue<Base2>
|
||||||
//{
|
//{
|
||||||
// public Base2 Value { get; set; }
|
// public Base2 Value { get; set; }
|
||||||
|
@ -14,6 +14,11 @@ namespace Esiur.Analysis.Coding
|
|||||||
return frequencies.Sum(x => ((double)x / total * -Log2(x)));
|
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);
|
public static double Log2(double value) => Math.Log10(value) / Math.Log10(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace Esiur.Analysis.Coding
|
|||||||
return ToString().GetHashCode();
|
return ToString().GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Length => Word.Length;
|
||||||
|
|
||||||
public static CodeWord<Base2> FromByte(byte b)
|
public static CodeWord<Base2> FromByte(byte b)
|
||||||
{
|
{
|
||||||
|
@ -9,14 +9,35 @@ namespace Esiur.Analysis.Graph
|
|||||||
{
|
{
|
||||||
internal T[,] value;
|
internal T[,] value;
|
||||||
|
|
||||||
public int Rows => value.GetLength(0);
|
public int Rows { get; private set; }
|
||||||
public int Columns => value.GetLength(1);
|
public int Columns { get; private set; }
|
||||||
|
|
||||||
public T this[int x, int y] => value[x, y];
|
public T this[int x, int y] {
|
||||||
|
get => value [x, y];
|
||||||
|
set => this.value[x, y] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix(int rows, int columns)
|
||||||
|
{
|
||||||
|
value = new T[rows, columns];
|
||||||
|
}
|
||||||
|
|
||||||
public Matrix(T[,] value)
|
public Matrix(T[,] value)
|
||||||
{
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
Rows = value.GetLength(0);
|
||||||
|
Columns = value.GetLength(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix<T> Transpose()
|
||||||
|
{
|
||||||
|
var rt = new T[Columns, Rows];
|
||||||
|
|
||||||
|
for(var i = 0; i < Rows; i++)
|
||||||
|
for(var j = 0; j < Columns; j++)
|
||||||
|
rt[j, i] = value[i, j];
|
||||||
|
|
||||||
|
return new Matrix<T>(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matrix<T> operator *(Matrix<T> a, Matrix<T> b)
|
public static Matrix<T> operator *(Matrix<T> a, Matrix<T> b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user