# Set balancing

The set balancing problem in mathematics is the problem of dividing a set to two subsets that have roughly the same characteristics. It arises naturally in design of experiments.$^{:71–72}$
There is a group of subjects. Each subject has several features, which are considered binary. For example: each subject can be either young or old; either black or white; either tall or short; etc. The goal is to divide the subjects to two sub-groups: treatment group (T) and control group (C), such that for each feature, the number of subjects that have this feature in T is roughly equal to the number of subjects that have this feature in C. E.g., both groups should have roughly the same number of young people, the same number of black people, the same number of tall people, etc.

## Matrix representation

Formally, the set balancing problem can be described as follows.
$m$ is the number of subjects in the general population.
$n$ is the number of potential features.
The subjects are described by $A$, an $n\times m$ matrix with entries in ${0,1}$. Each column represents a subject and each row represents a feature. $a_{i,j}=1$ if subject $j$ has feature $i$, and $a_{i,j}=0$ if subject $j$ does not have feature $i$.
The partition to groups is described by $b$, an $m\times 1$ vector with entries in ${-1,1}$. $b_{j}=1$ if subject $j$ is in the treatment group T and $b_{j}=-1$ is subject $j$ is in the control group C.
The balance of features is described by $c=A\cdot b$. This is an $n\times 1$ vector. The numeric value of $c_{i}$ is the imbalance in feature $i$: if $c_{i}>0$ then there are more subjects with $i$ in T and if $c_{i}<0$ then there are more subjects with $i$ in C.
The imbalance of a given partition is defined as:
       $I(b)=||A\cdot b||_{\infty }=\max _{i\in 1\dots ,n}|c_{i}|$
The set balancing problem is to find a vector $b$ which minimizes the imbalance $I(b)$.

## Randomized algorithm

An approximate solution can be found with the following very simple randomized algorithm:
       Send each subject to the treatment group with probability 1/2.
In matrix formulation:
       Choose the elements of $b$ randomly with probability 1/2 to each value in {1,-1}.
Surprisingly, although this algorithm completely ignores the matrix $A$, it achieves a small imbalance with high probability when there are many features. Formally, for a random vector $b$:
       $Prob\left[I(b)\geq {\sqrt {4m\ln n}}\right]\leq {\frac {2}{n}}$
PROOF:
Let $k_{i}$ be the total number of subjects that have feature $i$ (equivalently, the number of ones in the $i$-th of the matrix $A$). Consider the following two cases:
Easy case: $k_{i}\leq {\sqrt {4m\ln n}}$. Then, with probability 1, the imbalance in feature $i$ (that we marked by $c_{i}$) is at most ${\sqrt {4m\ln n}}$.
Hard case: $k_{i}>{\sqrt {4m\ln n}}$. For every $j$, let $X_{j}=a_{i,j}b_{j}$. Each such $X_{j}$ is a random variable that can be either 1 or -1 with probability 1/2. The imbalance in feature $i$ is: $c_{i}=\sum _{j=1}^{m}{X_{j}}$. Since the $X_{j}$ are independent random variables, by the Chernoff bound, for every $a>0$:
       $Prob\left[|c_{i}|\geq a\right]\leq 2\exp(-a^{2}/2m)$
Select: $a={\sqrt {4m\ln n}}$ and get:
       $Prob\left[|c_{i}|\geq {\sqrt {4m\ln n}}\right]\leq {\frac {2}{n^{2}}}$
By the union bound,
       $Prob\left[\exists i:|c_{i}|\geq {\sqrt {4m\ln n}}\right]\leq {\frac {2}{n}}$.