Algorithm Search⌘K

Definitionadvanced

Orthogonal array

Also called orthogonal array of strength t, OA(N, k, s, t).

An N x k array over s symbols in which every N x t subarray has each t-tuple equally often. It is the combinatorial core of fractional designs.

An orthogonal array is a table of runs in which every choice of tt factors sees every combination of their levels equally often. Rao (1947) defined these arrays as a common frame for factorial experiments: a full factorial design, a regular fractional factorial design, a Plackett-Burman design and a set of mutually orthogonal Latin squares are all orthogonal arrays. Strength 2 makes the main effects orthogonal; higher strength protects them from more interactions. Rao also proved a lower bound on the number of runs. The same objects appear in coding theory: the codewords of a linear code form an orthogonal array whose strength is one less than the minimum distance of the dual code.

Definition

An orthogonal array OA(N,k,s,t)\mathrm{OA}(N, k, s, t) is an N×kN \times k array with entries from a set of ss symbols, such that in every N×tN \times t subarray each of the sts^t possible rows occurs exactly λ=N/st\lambda = N/s^t times. NN is the number of runs, kk the number of factors, ss the number of levels, tt the strength and λ\lambda the index. Strength tt implies strength t−1t - 1, because each (t−1)(t-1)-tuple extends to ss tuples on one more column. A full factorial sks^k design is an OA(sk,k,s,k)\mathrm{OA}(s^k, k, s, k), and a regular two-level fraction of resolution RR is an orthogonal array of strength R−1R - 1 (Theorem 3).

Theorem 1 (strength gives orthogonal effects). Let ϕ0=1,ϕ1,…,ϕs−1\phi_0 = 1, \phi_1, \dots, \phi_{s-1} be real functions on the symbols that are orthonormal for the uniform distribution, so 1s∑aϕi(a)ϕj(a)=[i=j]\frac1s\sum_a \phi_i(a)\phi_j(a) = [i = j]; they exist by Gram-Schmidt. For a set SS of columns and a map α\alpha from SS to {1,…,s−1}\{1, \dots, s-1\}, let vS,αv_{S,\alpha} be the vector of length NN whose entry in run rr is ∏c∈Sϕα(c)(rc)\prod_{c \in S}\phi_{\alpha(c)}(r_c), an effect column of order ∣S∣|S|. In an array of strength tt, two such vectors with ∣S∪T∣≤t|S \cup T| \le t have vS,α⊤vT,β=Nv_{S,\alpha}^\top v_{T,\beta} = N if (S,α)=(T,β)(S, \alpha) = (T, \beta) and 00 otherwise.

Proof. The entry of run rr in the product depends only on the columns in S∪TS \cup T, at most tt of them. By strength tt, these columns take every combination of levels equally often, so the sum over the runs is NN times the mean over independent uniform levels XcX_c, c∈S∪Tc \in S \cup T. That mean factors over the columns. A column in only one of the sets gives E ϕi(Xc)=0\mathbb E\,\phi_i(X_c) = 0 for i≥1i \ge 1, and a column in both gives E ϕi(Xc)ϕj(Xc)=[i=j]\mathbb E\,\phi_i(X_c)\phi_j(X_c) = [i = j]. So the mean is 1 when (S,α)=(T,β)(S, \alpha) = (T, \beta) and 0 otherwise. □\square

With t=2t = 2, the main-effect columns of different factors are orthogonal, so the main effects are estimated independently when interactions are absent. In general, with u=⌊t/2⌋u = \lfloor t/2 \rfloor, all effects of order at most uu are estimated independently when the interactions of order above t−ut - u are absent.

Theorem 2 (the Rao bound). An OA(N,k,s,t)\mathrm{OA}(N, k, s, t) with t=2ut = 2u has

N≥∑i=0u(ki)(s−1)i,N \ge \sum_{i=0}^{u} \binom{k}{i}(s - 1)^i,

and one with t=2u+1t = 2u + 1 has

N≥∑i=0u(ki)(s−1)i+(k−1u)(s−1)u+1.N \ge \sum_{i=0}^{u} \binom{k}{i}(s - 1)^i + \binom{k - 1}{u}(s - 1)^{u + 1}.

Proof. For even tt, take all vectors vS,αv_{S,\alpha} with ∣S∣≤u|S| \le u. There are (ki)(s−1)i\binom{k}{i}(s-1)^i of them with ∣S∣=i|S| = i. Any two have ∣S∪T∣≤2u=t|S \cup T| \le 2u = t, so by Theorem 1 they are nonzero and pairwise orthogonal, hence linearly independent in RN\mathbb R^N, and NN is at least their number. For odd tt, also take the vectors with ∣S∣=u+1|S| = u + 1 and SS containing column 1; there are (k−1u)(s−1)u+1\binom{k-1}{u}(s-1)^{u+1} of them. Two sets of size u+1u + 1 that both contain column 1 have a union of at most 2u+1=t2u + 1 = t columns, and a set of size u+1u + 1 with a set of size at most uu also has a union of at most tt columns. So Theorem 1 again makes all the vectors orthogonal. □\square

The bound counts the effects that the array can estimate, so it is the statistical statement "at least as many runs as parameters". It can be weak: since λ=N/st\lambda = N/s^t is an integer, NN is also a multiple of sts^t.

Theorem 3 (code duality). Let CC be a linear code of length kk over the field with qq elements, with C⊥≠{0}C^\perp \ne \{0\}, and let d⊥d^\perp be the minimum distance of the dual code C⊥C^\perp. The codewords of CC, as the rows of a ∣C∣×k|C| \times k array, form an orthogonal array of strength exactly d⊥−1d^\perp - 1.

Proof. Fix a set TT of tt columns. The projection πT\pi_T of CC onto the columns TT is linear, so if it is onto, every tt-tuple is hit by a coset of its kernel, that is, ∣C∣/qt|C|/q^t times. It fails to be onto exactly when a nonzero linear form on the coordinates TT vanishes on πT(C)\pi_T(C). Such a form is a nonzero vector ww supported inside TT with w⋅c=0w \cdot c = 0 for every c∈Cc \in C, that is, a nonzero dual codeword of weight at most tt supported in TT. So the array has strength tt if and only if no nonzero dual codeword has weight at most tt, that is, t≤d⊥−1t \le d^\perp - 1. □\square

Delsarte (1973) extended this to codes that are not linear, with the dual distance defined through the MacWilliams identity transform of the distance distribution; that result is cited here, not proved. For a regular 2k−p2^{k-p} fraction, the runs (with level +1+1 written as bit 0 and −1-1 as bit 1) are the dual of the code of defining words, whose minimum distance is the resolution RR. So Theorem 3 gives strength R−1R - 1.

Examples and non-examples

Example: OA(4,3,2,2)\mathrm{OA}(4, 3, 2, 2). The rows 000,011,101,110000, 011, 101, 110, the even-weight code of length 3, form the half fraction I=ABCI = ABC of a 232^3 design. Every two columns show 00,01,10,1100, 01, 10, 11 once, so the strength is 2, and N=4N = 4 meets the Rao bound 1+31 + 3. The strength is not 3: only 4 of the 8 triples occur.

Example: Latin squares. From mm mutually orthogonal Latin squares L1,…,LmL_1, \dots, L_m of order nn, the n2n^2 rows (i,j,L1(i,j),…,Lm(i,j))(i, j, L_1(i, j), \dots, L_m(i, j)) form an OA(n2,m+2,n,2)\mathrm{OA}(n^2, m + 2, n, 2), and every such array of index 1 arises this way. The two orthogonal squares of order 3 give OA(9,4,3,2)\mathrm{OA}(9, 4, 3, 2), and the three squares of order 4 built over the field with 4 elements give OA(16,5,4,2)\mathrm{OA}(16, 5, 4, 2). Both meet the Rao bound, 1+4⋅2=91 + 4 \cdot 2 = 9 and 1+5⋅3=161 + 5 \cdot 3 = 16. In general k≤n+1k \le n + 1 for index 1 is the Rao bound n2≥1+k(n−1)n^2 \ge 1 + k(n - 1), which is again the bound of at most n−1n - 1 mutually orthogonal Latin squares.

Example: the Hamming code. The 16 codewords of the [7, 4] Hamming code form an OA(16,7,2,3)\mathrm{OA}(16, 7, 2, 3): the dual is the [7, 3] simplex code, whose nonzero words all have weight 4, so d⊥=4d^\perp = 4 and the strength is 3. The Rao bound for k=7k = 7, s=2s = 2, t=3t = 3 is 1+7+6=141 + 7 + 6 = 14, so the array is above the bound. But NN must be a multiple of 23=82^3 = 8, so 16 is the smallest possible. Adding a parity bit gives the extended [8, 4, 4] code, which is its own dual: an OA(16,8,2,3)\mathrm{OA}(16, 8, 2, 3) that meets the Rao bound 1+8+7=161 + 8 + 7 = 16. As a design it is the 28−42^{8-4} fraction of resolution IV.

Example: the simplex code and the Plackett-Burman designs. The 8 words of the [7, 3] simplex code form an OA(8,7,2,2)\mathrm{OA}(8, 7, 2, 2), the saturated 27−42^{7-4} design; its dual is the Hamming code with d⊥=3d^\perp = 3. The 12-run Plackett-Burman design is an OA(12,11,2,2)\mathrm{OA}(12, 11, 2, 2). Both meet the Rao bound N≥1+kN \ge 1 + k for s=2s = 2, t=2t = 2. The 12-run array comes from no linear code, because 12 is not a power of 2.

Non-example: 8 runs for 8 factors. No OA(8,8,2,2)\mathrm{OA}(8, 8, 2, 2) exists, because the Rao bound is 1+8=91 + 8 = 9. So no 8-run two-level design has 8 balanced, pairwise orthogonal factor columns.

Non-example: a covering array. The 5 rows 0000,0111,1011,1101,11100000, 0111, 1011, 1101, 1110 show every pair of levels in every pair of columns, but 1111 occurs twice and the other pairs once. This is a covering array of strength 2, which asks that every tt-tuple occur at least once, not equally often. Pairwise testing of software often uses covering arrays. They are not orthogonal arrays (here 5 is not even a multiple of 222^2), and their main-effect columns are not orthogonal.

The test file checks every array on this page, the Rao bounds, and Theorem 3 on random linear codes over the fields with 2 and 3 elements.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

orthogonal_array.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/orthogonal-array/. The authors are listed in prov/5Q12GA.jsonl.
"""Orthogonal arrays OA(N, k, s, t): checking, the Rao bound, and constructions.

An N x k array on s symbols has strength t when, in every choice of t columns, each of
the s^t possible rows occurs equally often (lambda = N / s^t times).
"""

from collections import Counter
from collections.abc import Sequence
from itertools import combinations, product
from math import comb

Array = list[tuple[int, ...]]


def has_strength(rows: Sequence[Sequence[int]], s: int, t: int) -> bool:
    """True if every t columns show each of the s^t tuples equally often."""
    n = len(rows)
    k = len(rows[0]) if rows else 0
    if t == 0:
        return True
    if n % s ** t:
        return False
    lam = n // s ** t
    for cols in combinations(range(k), t):
        cnt = Counter(tuple(r[c] for c in cols) for r in rows)
        if len(cnt) != s ** t or any(v != lam for v in cnt.values()):
            return False
    return True


def strength(rows: Sequence[Sequence[int]], s: int) -> int:
    """The largest t such that the array has strength t (strength t implies t - 1)."""
    k = len(rows[0])
    t = 0
    while t < k and has_strength(rows, s, t + 1):
        t += 1
    return t


def rao_bound(k: int, s: int, t: int) -> int:
    """Rao's lower bound on the number of runs N of an OA(N, k, s, t)."""
    u = t // 2
    bound = sum(comb(k, i) * (s - 1) ** i for i in range(u + 1))
    if t % 2:
        bound += comb(k - 1, u) * (s - 1) ** (u + 1)
    return bound


def from_linear_code(generator: Sequence[Sequence[int]], p: int) -> Array:
    """The codewords of the linear code over GF(p) (p prime) spanned by the generator
    rows, as the rows of an array: an OA of strength d' - 1, where d' is the minimum
    distance of the dual code."""
    m = len(generator)
    k = len(generator[0])
    return sorted({tuple(sum(a * g[j] for a, g in zip(msg, generator)) % p for j in range(k))
                   for msg in product(range(p), repeat=m)})


def dual_distance(generator: Sequence[Sequence[int]], p: int) -> int:
    """The minimum weight of a nonzero word orthogonal to every generator row (brute force)."""
    k = len(generator[0])
    best = k + 1
    for w in product(range(p), repeat=k):
        if any(w) and all(sum(a * b for a, b in zip(w, g)) % p == 0 for g in generator):
            best = min(best, sum(1 for a in w if a))
    return best


def from_mols(squares: Sequence[Sequence[Sequence[int]]]) -> Array:
    """An OA(n^2, m + 2, n, 2) from m mutually orthogonal Latin squares of order n:
    rows (i, j, L_1(i, j), ..., L_m(i, j))."""
    n = len(squares[0])
    return [(i, j) + tuple(sq[i][j] for sq in squares) for i in range(n) for j in range(n)]
test_orthogonal_array.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/orthogonal-array/. The authors are listed in prov/5Q12GA.jsonl.

import random
from itertools import product

from orthogonal_array import dual_distance, from_linear_code, from_mols, has_strength, rao_bound, strength

SIMPLEX = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1]]  # columns 1..7 in binary
EXT_HAMMING = [[1] * 8, [0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1]]


def test_small_examples() -> None:
    oa4 = [(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)]
    assert strength(oa4, 2) == 2 and rao_bound(3, 2, 2) == 4
    oa9 = from_mols([[[0, 1, 2], [1, 2, 0], [2, 0, 1]], [[0, 1, 2], [2, 0, 1], [1, 2, 0]]])
    assert len(oa9) == 9 and strength(oa9, 3) == 2 and rao_bound(4, 3, 2) == 9


def test_simplex_code_meets_the_rao_bound() -> None:
    oa = from_linear_code(SIMPLEX, 2)
    assert len(oa) == 8 and strength(oa, 2) == 2
    assert dual_distance(SIMPLEX, 2) == 3  # the dual is the Hamming [7, 4, 3] code
    assert rao_bound(7, 2, 2) == 8


def test_extended_hamming_is_a_tight_strength_three_array() -> None:
    oa = from_linear_code(EXT_HAMMING, 2)
    assert len(oa) == 16 and strength(oa, 2) == 3
    assert rao_bound(8, 2, 3) == 16
    assert dual_distance(EXT_HAMMING, 2) == 4  # the code is self-dual


def test_code_duality_on_random_codes() -> None:
    rng = random.Random(1)
    for p, k_max in ((2, 8), (3, 5)):
        for _ in range(30):
            k = rng.randint(3, k_max)
            m = rng.randint(1, k - 1)
            gen = [[rng.randrange(p) for _ in range(k)] for _ in range(m)]
            rows = from_linear_code(gen, p)
            # dual_distance returns k + 1 when the dual code is {0}; then the array is all of GF(p)^k
            assert strength(rows, p) == min(dual_distance(gen, p), k + 1) - 1


def test_rao_bound_holds_for_every_array_found() -> None:
    rng = random.Random(2)
    for _ in range(60):
        k = rng.randint(3, 7)
        m = rng.randint(1, k)
        gen = [[rng.randrange(2) for _ in range(k)] for _ in range(m)]
        rows = from_linear_code(gen, 2)
        t = strength(rows, 2)
        if t >= 1:
            assert len(rows) >= rao_bound(k, 2, t)


HAMMING = [[1, 0, 0, 0, 0, 1, 1], [0, 1, 0, 0, 1, 0, 1], [0, 0, 1, 0, 1, 1, 0], [0, 0, 0, 1, 1, 1, 1]]
MOLS4 = [[[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]],
         [[0, 1, 2, 3], [2, 3, 0, 1], [3, 2, 1, 0], [1, 0, 3, 2]],
         [[0, 1, 2, 3], [3, 2, 1, 0], [1, 0, 3, 2], [2, 3, 0, 1]]]
PB12 = "++-+++---+-"


def test_hamming_code_is_a_strength_three_array_above_the_rao_bound() -> None:
    oa = from_linear_code(HAMMING, 2)
    assert len(oa) == 16 and strength(oa, 2) == 3
    assert sorted(sum(r) for r in oa) == [0] + [3] * 7 + [4] * 7 + [7]  # the [7, 4, 3] code
    assert dual_distance(HAMMING, 2) == 4  # the dual is the [7, 3] simplex code
    assert rao_bound(7, 2, 3) == 14  # and N must be a multiple of 2^3, so 16 is the least possible
    assert rao_bound(7, 2, 3) < 16 and 16 % 8 == 0 and 14 % 8 != 0


def test_examples_and_non_examples() -> None:
    # complete set of MOLS of order 4: OA(16, 5, 4, 2) meeting the Rao bound 1 + 5 * 3
    oa = from_mols(MOLS4)
    assert len(oa) == 16 and strength(oa, 4) == 2 and rao_bound(5, 4, 2) == 16
    # the half fraction I = ABC: strength exactly 2
    half = [(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)]
    assert has_strength(half, 2, 2) and not has_strength(half, 2, 3)
    # the 12-run Plackett-Burman design: OA(12, 11, 2, 2), on the Rao bound, strength not 3
    g = [1 if c == "+" else 0 for c in PB12]
    pb = [tuple(g[(j + i) % 11] for j in range(11)) for i in range(11)] + [(0,) * 11]
    assert strength(pb, 2) == 2 and rao_bound(11, 2, 2) == 12
    # a covering array of strength 2 that is not an orthogonal array
    cover = [(0, 0, 0, 0), (0, 1, 1, 1), (1, 0, 1, 1), (1, 1, 0, 1), (1, 1, 1, 0)]
    for a in range(4):
        for b in range(a + 1, 4):
            pairs = [(r[a], r[b]) for r in cover]
            assert sorted(pairs.count(p) for p in product((0, 1), repeat=2)) == [1, 1, 1, 2]
            assert pairs.count((1, 1)) == 2
    assert not has_strength(cover, 2, 2)
    # no OA(8, 8, 2, 2): the Rao bound is 9
    assert rao_bound(8, 2, 2) == 9
    # the extended Hamming code: the 2^(8-4) design of resolution IV is an OA of strength 3
    assert strength(from_linear_code(EXT_HAMMING, 2), 2) == 3


def test_strength_two_gives_orthogonal_main_effects() -> None:
    # centered functions of two different columns are orthogonal over the runs
    oa = from_linear_code([[1, 0, 1, 2], [0, 1, 1, 1]], 3)  # OA(9, 4, 3, 2)
    assert strength(oa, 3) == 2
    rng = random.Random(3)
    for _ in range(50):
        f = [rng.randint(-5, 5) for _ in range(3)]
        g = [rng.randint(-5, 5) for _ in range(3)]
        f = [3 * v - sum(f) for v in f]
        g = [3 * v - sum(g) for v in g]
        for i in range(4):
            for j in range(4):
                if i != j:
                    assert sum(f[r[i]] * g[r[j]] for r in oa) == 0


def test_full_factorial_has_strength_k() -> None:
    for s, k in ((2, 4), (3, 3)):
        rows = list(product(range(s), repeat=k))
        assert strength(rows, s) == k and has_strength(rows, s, k)

References

  1. C. R. Rao, Factorial experiments derivable from combinatorial arrangements of arrays, Supplement to the Journal of the Royal Statistical Society 9(1), 1947, pp. 128 to 139 (the arrays of strength t and the lower bound on the number of runs)
  2. A. S. Hedayat, N. J. A. Sloane and John Stufken, Orthogonal Arrays, Theory and Applications, Springer, 1999, Section 2.2 (Rao's inequalities, Chapter 2 on pp. 11 to 35) and Section 4.3 (linear codes and linear orthogonal arrays, starting on p. 65)
  3. Philippe Delsarte, An algebraic approach to the association schemes of coding theory, Philips Research Reports Supplements 10, 1973, the dual distance of a code and its strength as an orthogonal array, for codes that need not be linear (general locator)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/5Q12GA/text.yaml