influxdata / influxdata/influxdb

Feature Request: Binomial Coefficient Entropy Coding for Inverted Index Postings

Open
#22,984 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

- Feature Name: Binomial Coefficient Entropy Coding for Inverted Index Postings
- Status: draft
- Start Date: 2021-12-13
- Authors: Murage Kibicho

# Summary
This is a proposal for encoding inverted index integer sequences using a number system based on binomial coefficients.
This number system is chosen because the [minimum number of bits](https://arxiv.org/abs/1908.10598) needed to encode a list of strictly increasing integers
is given by the equation ![ceilinglog2](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/log2UN130.png)
where ![U](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/U.png) is largest number in the list and ![n](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/n.png) is the number of elements in the list.
For example to encode the sequence **1,2,3,4,10,11** we need at least 9 bits: ![11 choose 6](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/11choose6.png) and
![log2(462) = 8.85 ~ 9 bits](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/ceil.png).
Binary interpolative coding, one of the best methods for inverted list compression takes at least 20 bits to represent the example sequence. You can confirm this [here](https://github.com/jermp/interpolative_coding).
However, if we represent the same sequence as a sum of binomial coefficients, it takes 10 bits to encode the list, and an extra 3 bits to store the length of the list. The total is 13 bits. You can confirm this [here](https://postingscompress.github.io/PostingsWebsite/#/).

# Motivation
Compression is a solved problem. The best compressors work by changing radixes, or number bases to find the most concise representation of data.
For instance, arithmetic coding is a [generalized change of radix](https://rosettacode.org/wiki/Talk:Arithmetic_coding/As_a_generalized_change_of_radix) for coding
at the [information theoretic entropy bound](https://en.wikipedia.org/wiki/Entropy_(information_theory)). This bound is a measure of redundancy - how many duplicates are in your data. Strictly increasing integer sequences have no duplicates, therefore, cannot be compressed
according to the information theoretic bound. This means huffman coding and arithmetic coding methods are inefficient with non-repetitive integer sequences.

This rfc proposes the use of the combinatorial number system to encode inverted index integer sequences at the [combinatorial information theoretic entropy bound](https://arxiv.org/abs/1908.10598).
Just like arithmetic coding, this change in number systems allows us to encode integer sequences with the least number of bits.
\
I am a Math major in my junior year and if this RFC succeeds I would love to take a gap year and work on this [library](https://github.com/PostingsCompress/Postings/tree/main/MathLibraries) full time. The library
has sample code for converting between binary and the combinatorial number system using a greedy algorithm, or by generating a lookup table.

# Technical design
## Overview of Combinatorial Number System
Any natural number ![N](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/N.png) can be uniquely written as a sum of binomial coefficients
using [this](http://math0.wvstateu.edu/~baker/cs405/code/Combinadics.html) greedy algorithm.

1. Find the largest binomial coefficient such that ![akChoosek](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/akChooseKleqN.png)
2. Subtract to find the residue ![NminusAkChoosek](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/NMinusBinomial.png)
3. Find the largest binomial coefficient such that ![Repeat](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/repeat.png)

## **Example:** Find the combinatorial representation of ![n63K4](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/n63K4.png)
![Convert to Binomial](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/conversionToBinomials.png)
\
To **reverse** the process, sum your list of binomial coefficients
![Sum](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/sum130.png)

## Comparison to Binary Interpolative Coding
In the example above, it can be seen that the sequence ![forward sequence](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/forward.png)
can be encoded in ![for2](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/for2.png) using the combinatorial number system with an extra 3 bits to store the length of the sequence. This is a total of 9 bits to encode this sequence.
\
Using [this library](https://github.com/jermp/interpolative_coding) it can be confirmed that binary interpolative coding takes between 15 to 23 bits to encode the same sequence.
\
This is a screenshot of the result of binary interpolative coding.
![Screenshot](https://raw.githubusercontent.com/PostingsCompress/PostingsWebsite/main/bic.png)
\
The combinatorial number systems always encodes integer sequences at the entropy limit.

Contributor guide

Open the contributing guide

Research direction

Read the proposal and inspect the repository's MathLibraries directory, which the issue identifies as containing sample combinatorial-number-system code. Then locate how inverted-index postings are represented and compressed in InfluxDB. Done would require a decided integration scope, implementation, and evidence that the proposed encoding works for postings.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.