BernoulliZip: a Compression Algorithm for Bernoulli Processes and Erdos-Renyi Graphs

Amirmohammad Farzaneh, Mihai-Alin Badiu, Justin P. CoonarXiv 2021

Abstract

BernoulliZip is a novel, lossless compression algorithm designed specifically for Bernoulli processes and Erdős–Rényi (ER) graphs. By utilizing the conditional entropy identity $H(X) = H(S) + H(X|S)$, the algorithm achieves near-optimal compression—approaching the theoretical Shannon entropy limit—with linear time complexity $O(n)$. This approach provides a computationally stable alternative to traditional methods like Huffman or arithmetic coding, which often suffer from numerical underflow or exponential complexity when applied to long sequences.

Introduction

Compressing sequences of independent Bernoulli trials is a fundamental task in information theory. While arithmetic coding is a standard solution, it faces significant practical hurdles as sequence length $n$ increases. The joint probability of a long sequence decreases exponentially, leading to precision errors and numerical "underflow" in standard floating-point arithmetic.

Furthermore, while many algorithms target complex real-world graphs, few focus on the Erdős–Rényi (ER) model, where edges exist independently with a fixed probability $p$. Since the adjacency matrix of an ER graph is essentially a Bernoulli process, an efficient compression method for the latter directly solves the former. BernoulliZip addresses these challenges by offering a method that is fast, easy to implement, and numerically stable.

Methodology

BernoulliZip operates on a "divide and conquer" principle based on the conditional entropy identity: $$H(X) = H(S) + H(X|S)$$ where $X$ is the sequence and $S$ is its Hamming weight (the number of 1s).

1. Compressing the Hamming Weight ($S$)

Instead of a massive Huffman tree, BernoulliZip exploits the binomial distribution of $S$. It codes the distance of $S$ from its mean ($np$). Values closer to the mean receive shorter codewords. The code for $S$ includes a sign bit, a magnitude header, and the binary representation of the distance.

2. Compressing the Sequence given Weight ($X|S$)

Once $S=k$ is known, all sequences with exactly $k$ ones are equally likely. BernoulliZip uses a lexicographic ordering technique to map the specific sequence to a unique index among the $\binom{n}{k}$ possible arrangements. This index is stored in $\lceil \log_2 \binom{n}{k} \rceil$ bits.

Complexity and Efficiency

Unlike Huffman coding, which has a complexity of $O(n 2^n)$ for whole-sequence symbols, or Shannon-Fano-Elias at $O(2^n)$, BernoulliZip runs in $O(n)$ time. This efficiency makes it suitable for large-scale data applications.

Comparison of algorithm complexity and mean codeword length.

Results and Analysis

The algorithm was evaluated using simulated Bernoulli sequences and Erdős–Rényi graphs in MATLAB.

Asymptotic Optimality

The authors proved that the mean codeword length is $nh(p) + O(\log_2 \log_2 n)$. As $n$ grows, the overhead becomes negligible, and efficiency approaches the Shannon limit. Experimental results confirm this linear relationship and the tight bound to theoretical entropy.

Compression length vs. sequence length n, showing near-entropy performance.

Performance Metrics

For a Bernoulli sequence with $n=50$ and $p=0.1$ (Entropy: 23.45 bits), BernoulliZip achieves a mean length of 25.64 bits. In graph compression tests using the "Direct Method" (10 nodes, $p=0.1$), the algorithm compressed the data to 23.64 bits against a theoretical entropy of 21.10 bits.

Discussion and Conclusion

BernoulliZip provides a significant leap in practical compression for independent trials by bypassing numerical instability. By focusing on counts and lexicographic ranks rather than multiplying tiny probabilities, it remains stable for very large $n$.

Limitations and Future Work

The $O(n)$ complexity assumes binomial coefficients are pre-calculated. For extremely large $n$, on-the-fly calculation could become a bottleneck. Additionally, as the algorithm is optimized for independent trials, it does not account for correlations and would be less effective for "scale-free" or "small-world" graphs. Future work may involve optimizing the "Block Method" for hardware acceleration on FPGAs or GPUs to handle massive datasets in real-time.

Summary updated

BibTeX
@misc{farzaneh2021bernoullizip,
  author = {Amirmohammad Farzaneh and Mihai-Alin Badiu and Justin P. Coon},
  title = {{BernoulliZip: a Compression Algorithm for Bernoulli Processes and Erdos-Renyi Graphs}},
  year = {2021},
  eprint = {2105.06708},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.06708},
}
Figure