Skip to content

Commit

Permalink
chore: rename variables in lossless coding submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
rwnobrega committed Jan 3, 2025
1 parent 1b8006f commit 8766cf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/komm/_lossless_coding/FanoCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ def fano_algorithm(pmf: PMF, source_block_size: int) -> dict[Word, Word]:
xpmf = extended_probabilities(pmf, source_block_size, pbar)
stack: list[tuple[list[tuple[Word, float]], Word]] = [(xpmf, ())]
while stack:
current_pmf, prefix = stack.pop()
if len(current_pmf) == 1:
u, _ = current_pmf[0]
enc_mapping[u] = prefix
group, v = stack.pop()
if len(group) == 1:
u, _ = group[0]
enc_mapping[u] = v
pbar.update()
continue
probs = [p for _, p in current_pmf]
probs = [p for _, p in group]
total = np.sum(probs)
index = np.argmin(np.abs(np.cumsum(probs) - total / 2))
stack.append((current_pmf[index + 1 :], prefix + (1,)))
stack.append((current_pmf[: index + 1], prefix + (0,)))
stack.append((group[index + 1 :], v + (1,)))
stack.append((group[: index + 1], v + (0,)))

pbar.close()

Expand Down
2 changes: 1 addition & 1 deletion src/komm/_lossless_coding/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def extended_probabilities(pmf: PMF, k: int, pbar: Any) -> list[tuple[Word, floa
probs.append((-pu, u))
if pbar is not None:
pbar.update()
return [(u, -p) for p, u in sorted(probs)]
return [(u, -minus_pu) for minus_pu, u in sorted(probs)]


def empty_mapping(cardinality: int, block_size: int) -> dict[Word, Word]:
Expand Down

0 comments on commit 8766cf0

Please sign in to comment.