experiment
Experiment framework for the coding experiments library.
This module provides the infrastructure for running coding experiments, including experiment runners and result data structures. It enables systematic evaluation of different coding schemes and channel models.
- class codinglab.experiment.ExperimentResult(stats, start_time, end_time, metadata=<factory>)[source]
Bases:
objectResults from a coding experiment run.
This class encapsulates all data collected during an experiment, including statistics, timing information, and any additional metadata. It provides computed properties for common analysis and can be serialized for storage or further processing.
- stats: TransmissionStats
Transmission statistics collected during the experiment.
- property duration: float
Calculate the total duration of the experiment.
- Returns:
Experiment duration in seconds
- class codinglab.experiment.ExperimentRunner(sender, channel, receiver)[source]
Bases:
objectOrchestrates and runs coding experiments.
This class coordinates the interaction between sender, channel, and receiver components to run complete transmission experiments. It manages the data flow, timing, and result collection.
- Parameters:
sender (Sender[SourceChar, ChannelChar])
channel (Channel[ChannelChar])
receiver (TrackingReceiver[SourceChar, ChannelChar])
- __init__(sender, channel, receiver)[source]
Initialize the experiment runner with component instances.
- Parameters:
sender (
Sender[TypeVar(SourceChar),TypeVar(ChannelChar)]) – Sender instance for generating and encoding messageschannel (
Channel[TypeVar(ChannelChar)]) – Channel instance for transmitting messagesreceiver (
TrackingReceiver[TypeVar(SourceChar),TypeVar(ChannelChar)]) – TrackingReceiver instance for collecting stats
- Raises:
TypeError – If receiver is not a TrackingReceiver instance
- Return type:
None
- sender
Sender instance for generating and encoding messages.
- channel
Channel instance for transmitting messages.
- receiver
TrackingReceiver instance for receiving and decoding messages.
- run(num_messages=100)[source]
Run a coding experiment with the configured components.
This method executes the complete transmission pipeline: 1. Generate and encode messages using the sender 2. Transmit messages through the channel 3. Receive, decode, and track messages using the receiver 4. Collect and return experiment results
- Parameters:
num_messages (
int) – Number of messages to transmit (default: 100)- Return type:
- Returns:
ExperimentResult object containing all experiment data
- Raises:
ValueError – If num_messages <= 0