Skip to content

FiniteStateChannel: use Mealy-machine channels with dit channel codes - #34

Merged
Autoplectic merged 1 commit into
mainfrom
dit-channel-adapter
Oct 26, 2026
Merged

Autoplectic merged 1 commit into
mainfrom
dit-channel-adapter

Conversation

@Autoplectic

Copy link
Copy Markdown
Member

Summary

Makes every stochastic MealyMachine, and so every ε-transducer, usable as a channel for dit.coding channel codes. It implements dit's duck-typed channel protocol from dit/dit#301, so dit needs no knowledge of sofic.

from dit.coding import hamming
from sofic.examples.processes import trapdoor

code = hamming(3)
code.probability_of_error(trapdoor(), method="exact")
code.capacity_gap(trapdoor())  # (lower, upper)
  • MealyMachine.__dit_channel__() returns a new FiniteStateChannel. It is exported from sofic.generators and sofic.
  • FiniteStateChannel provides:
    • log_likelihood: the scaled forward algorithm. It is exact for any finite-state channel, unifilar or not.
    • sample: draws a state path from the initial law.
    • symbol_log_likelihoods: forward-backward (BCJR) under uniform i.i.d. inputs. dit's LDPC, polar, and soft-Viterbi decoders use these values.
    • capacity(**kw): the (lower, upper) no-feedback bracket from sofic.generators.capacity.capacity. The codes don't use feedback.
    • Symbol maps: by default digit strings become ints ("0" becomes 0); input_map and output_map override this.
  • Refactor: the initial-state law is factored out of channel_tensors into initial_law, which both use.
  • Docs: a new docs/generators/channel_coding.rst page, Bahl1974 added to docs/references.bib, and a CHANGELOG entry.

Depends on dit/dit#301. The new tests skip themselves when the installed dit has no dit.coding.as_channel. Raise the dit>=2.3 floor once a dit release includes that PR.

Test plan

  • New tests/test_channel_coding.py:
    • trapdoor and ising_channel likelihoods and BCJR symbol likelihoods match brute-force sums over state paths.
    • Sampled frequencies match the likelihoods.
    • Exact error probability matches a direct sum.
    • A one-state binary_channel(p, p) matches dit's binary symmetric channel.
    • capacity_gap returns a bracket that contains the binary symmetric channel's gap.
    • Custom symbol maps work.
  • Full suite passes against a local checkout of Channel protocol: attach channels with memory to channel codes dit#301 (2189 passed, 11 skipped).
  • ruff check / ruff format --check clean.

Made with Cursor

MealyMachine.__dit_channel__ wraps a stochastic transducer as a
FiniteStateChannel implementing dit.coding's channel protocol: forward-algorithm
likelihoods, state-path sampling, BCJR symbol likelihoods, and a no-feedback
capacity bracket. Factor the initial-state law out of channel_tensors.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Autoplectic
Autoplectic merged commit 4bbf9d5 into main Oct 26, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant