-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check_Node.cpp
144 lines (117 loc) · 3.35 KB
/
Check_Node.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Check_Node.cpp
*
* Created on: 23 Dec, 2014
\* Author: Mehrdad Tahernia
*/
#include "Message.h"
#include "Edge.h"
#include "Variable_Node.h"
#include "Check_Node.h"
/****************************************************************************
*
* Check node
*
****************************************************************************/
GFq &check_node::Value() {
static GFq Aux;
Aux = 0;
for (int i = 0; i < GetDegree(); i++)
Aux += GetEdge(i).label * GetEdge(i).LeftNode().Symbol;
return Aux;
}
// returns the variable node connected to edge specified with index
node &check_node::AdjacentNode(int index) {
return GetEdge(index).LeftNode();
}
message &FastCalcLeftboundMessage(message AuxLeft[], message AuxRight[],int left_index, int degree)
{
static message Aux;
// Init to delta pulse
Aux.Set_q(GFq::q);
Aux = AuxLeft[left_index];
Aux *= AuxRight[left_index];
// FIXME: Why is this normalization not important?
// if (GFq::IsPrimeQ)
// Aux /= (double) GFq::q;
Aux.IDFT();
Aux.Reverse(); // estimate of symbol value = (- sum of others)
return Aux;
}
void check_node::CalcAllLeftboundMessages() {
static message Vectors[MAX_DEGREE];
static message AuxLeft[MAX_DEGREE];
static message AuxRight[MAX_DEGREE];
static GFq ZERO(0);
// Calc auxiliary DFTs
for (int i = 0; i < GetDegree(); i++) {
Vectors[i] = GetEdge(i).RightBoundMessage;
Vectors[i].PermuteTimes(GetEdge(i).label.Inverse());
}
//-------------------------------------------------------------
// If power of two - use DFT2
//-------------------------------------------------------------
// if (!GFq::IsPrimeQ)
if (true)
{
for (int i = 0; i < GetDegree(); i++) {
Vectors[i].DFT();
}
// Calc auxiliary values
AuxLeft[0].Set_q(GFq::q);
AuxLeft[0] = 1.0;
for (int i = 1; i < GetDegree(); i++) {
AuxLeft[i] = AuxLeft[i - 1];
AuxLeft[i] *= Vectors[i - 1];
}
AuxRight[GetDegree() - 1].Set_q(GFq::q);
AuxRight[GetDegree() - 1] = 1.0;
for (int i = GetDegree() - 2; i >= 0; i--) {
AuxRight[i] = AuxRight[i + 1];
AuxRight[i] *= Vectors[i + 1];
}
// Calc leftbound messages
for (int i = 0; i < GetDegree(); i++) {
GetEdge(i).LeftBoundMessage = FastCalcLeftboundMessage(AuxLeft, AuxRight, i, GetDegree());
GetEdge(i).LeftBoundMessage.PermuteTimes(GetEdge(i).label);
}
}
/*
else {
// cout << "FIXME!!!" << std::endl;
for (int i = 0; i < GetDegree(); i++) {
Vectors[i].DFT2();
}
// Calc auxiliary values
AuxLeft[0].Set_q(GFq::q);
AuxLeft[0] = 1.0;
for (int i = 1; i < GetDegree(); i++) {
AuxLeft[i] = AuxLeft[i - 1];
AuxLeft[i] *= Vectors[i - 1];
}
AuxRight[GetDegree() - 1].Set_q(GFq::q);
AuxRight[GetDegree() - 1] = 1.0;
for (int i = GetDegree() - 2; i >= 0; i--) {
AuxRight[i] = AuxRight[i + 1];
AuxRight[i] *= Vectors[i + 1];
}
// Calc leftbound messages
for (int i = 0; i < GetDegree(); i++) {
GetEdge(i).LeftBoundMessage = FastCalcLeftboundMessage(AuxLeft, AuxRight, i, GetDegree());
GetEdge(i).LeftBoundMessage.PermuteTimes(GetEdge(i).label);
}
} */
}
// Used for encoding
GFq &check_node::Element(int index)
// Treats check node as a sparse matrix column
{
static GFq ReturnVal(0); // Value of check at column
for (int j = 0; j < GetDegree(); j++) {
if (GetEdge(j).LeftNode().GetID() == index) {
ReturnVal = GetEdge(j).label;
break;
}
}
return ReturnVal;
}