-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpolar_sequence.hh
More file actions
61 lines (53 loc) · 1.14 KB
/
polar_sequence.hh
File metadata and controls
61 lines (53 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Construct reliability sequences for polar codes
Copyright 2023 Ahmet Inan <inan@aicodix.de>
*/
#pragma once
#include "sort.hh"
namespace CODE {
template <int MAX_M>
class BhattacharyyaSequence
{
void compute(double pe, int i, int h)
{
if (h) {
compute(pe * (2-pe), i, h/2);
compute(pe * pe, i+h, h/2);
} else {
prob[i] = pe;
}
}
double prob[1<<MAX_M];
MergeSort<int, 1<<MAX_M> sort;
public:
void operator()(int *sequence, int level, double erasure_probability = std::exp(-1.))
{
assert(level <= MAX_M);
int length = 1 << level;
compute(erasure_probability, 0, length / 2);
for (int i = 0; i < length; ++i)
sequence[i] = i;
sort(sequence, length, [this](int a, int b){ return prob[a] > prob[b]; });
}
};
template <int MAX_M>
class ReedMullerSequence
{
MergeSort<int, 1<<MAX_M> sort;
public:
void operator()(int *sequence, int level)
{
assert(level <= MAX_M);
int length = 1 << level;
for (int i = 0; i < length; ++i)
sequence[i] = i;
sort(sequence, length, [](int a, int b){
int x = __builtin_popcount(a);
int y = __builtin_popcount(b);
if (x != y)
return x < y;
return a < b;
});
}
};
}