Compare commits
3 Commits
92d847ba69
...
6433bb5e9d
| Author | SHA1 | Date | |
|---|---|---|---|
| 6433bb5e9d | |||
| 1c7daec957 | |||
| d478be5f77 |
@ -33,3 +33,21 @@ pub fn generate_random_h(rows: usize, cols: usize, wc: usize, wr: usize) -> Matr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn generate_random_h_for_k(k: usize, wc: usize, wr: usize) -> MatrixGF2 {
|
||||||
|
assert!(wr > wc, "wr < wc ...");
|
||||||
|
assert!((k * wr) % (wr - wc) == 0, "Colonnes non entieres");
|
||||||
|
|
||||||
|
let n = (k * wr) / (wr - wc);
|
||||||
|
let m = n - k;
|
||||||
|
|
||||||
|
// On garde que les matrice de rang m
|
||||||
|
loop {
|
||||||
|
let h_matrix = generate_random_h(m, n, wc, wr);
|
||||||
|
let mut h_test = h_matrix.clone();
|
||||||
|
let (rank, _) = h_test.gauss_jordan_swap_cols();
|
||||||
|
if rank == m {
|
||||||
|
return h_matrix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -9,8 +9,64 @@ impl<'a> BitFlipDecoder<'a> {
|
|||||||
Self { code }
|
Self { code }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO paraléliser (le calcul de chaque check-node)
|
||||||
pub fn decode(&self, received: &[u8], max_iter: usize) -> Option<Vec<u8>> {
|
pub fn decode(&self, received: &[u8], max_iter: usize) -> Option<Vec<u8>> {
|
||||||
let graph = &self.code.tanner_graph;
|
let n = self.code.n;
|
||||||
unimplemented!("Algo de bit-flipp");
|
let m = self.code.h_matrix.rows;
|
||||||
|
|
||||||
|
let mut curr_bits = received.to_vec();
|
||||||
|
|
||||||
|
for iter in 0..max_iter {
|
||||||
|
// Syndrome s = v * H^T
|
||||||
|
let mut s = vec![0; m];
|
||||||
|
let mut s_w = 0;
|
||||||
|
|
||||||
|
for (cnid, cb) in self.code.tanner_graph.check.iter().enumerate() {
|
||||||
|
let mut sum = 0;
|
||||||
|
// Calcul des equation de parité
|
||||||
|
for &bid in cb {
|
||||||
|
sum ^= cb[bid];
|
||||||
|
}
|
||||||
|
s[cnid] = sum;
|
||||||
|
|
||||||
|
// Equation non vérifiée
|
||||||
|
if sum == 1 {
|
||||||
|
s_w += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aucune erreurs
|
||||||
|
if s_w == 0 {
|
||||||
|
return Some(curr_bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcul du nombre d'équations fausses le bit fait partie
|
||||||
|
let mut cpt = vec![0; n];
|
||||||
|
let mut max_cpt = 0;
|
||||||
|
|
||||||
|
for (cid, &sb) in s.iter().enumerate() {
|
||||||
|
if sb == 1 {
|
||||||
|
for &bid in &self.code.tanner_graph.check[cid] {
|
||||||
|
cpt[bid] += 1;
|
||||||
|
if cpt[bid] > max_cpt {
|
||||||
|
max_cpt = cpt[bid];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if max_cpt == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flip des bit qui causent le plus d'équations fausses
|
||||||
|
for i in 0..n {
|
||||||
|
if cpt[i] == max_cpt {
|
||||||
|
curr_bits[i] ^= 1; // Bit flip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Some(curr_bits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ impl DenseEncoder {
|
|||||||
// let mut codeword = vec![0; self.n];
|
// let mut codeword = vec![0; self.n];
|
||||||
|
|
||||||
// s = u * G
|
// s = u * G
|
||||||
|
|
||||||
// for c in 0..self.n {
|
// for c in 0..self.n {
|
||||||
// let mut sum = 0;
|
// let mut sum = 0;
|
||||||
// for r in 0..self.k {
|
// for r in 0..self.k {
|
||||||
|
|||||||
@ -11,14 +11,15 @@ impl TannerGraph {
|
|||||||
let mut check = vec![vec![]; matrix.rows];
|
let mut check = vec![vec![]; matrix.rows];
|
||||||
let mut bits = vec![vec![]; matrix.cols];
|
let mut bits = vec![vec![]; matrix.cols];
|
||||||
|
|
||||||
for i in 0..matrix.rows {
|
for (i, row_check) in check.iter_mut().enumerate() {
|
||||||
for j in 0..matrix.cols {
|
for (j, col_bits) in bits.iter_mut().enumerate() {
|
||||||
if matrix.get(i, j) == 0 {
|
if matrix.get(i, j) == 0 {
|
||||||
check[i].push(j);
|
row_check.push(j);
|
||||||
bits[j].push(i);
|
col_bits.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { check, bits }
|
Self { check, bits }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user