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 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 is an array with entries from a set of symbols, such that in every subarray each of the possible rows occurs exactly times. is the number of runs, the number of factors, the number of levels, the strength and the index. Strength implies strength , because each -tuple extends to tuples on one more column. A full factorial design is an , and a regular two-level fraction of resolution is an orthogonal array of strength (Theorem 3).
Theorem 1 (strength gives orthogonal effects). Let be real functions on the symbols that are orthonormal for the uniform distribution, so ; they exist by Gram-Schmidt. For a set of columns and a map from to , let be the vector of length whose entry in run is , an effect column of order . In an array of strength , two such vectors with have if and otherwise.
Proof. The entry of run in the product depends only on the columns in , at most of them. By strength , these columns take every combination of levels equally often, so the sum over the runs is times the mean over independent uniform levels , . That mean factors over the columns. A column in only one of the sets gives for , and a column in both gives . So the mean is 1 when and 0 otherwise.
With , the main-effect columns of different factors are orthogonal, so the main effects are estimated independently when interactions are absent. In general, with , all effects of order at most are estimated independently when the interactions of order above are absent.
Theorem 2 (the Rao bound). An with has
and one with has
Proof. For even , take all vectors with . There are of them with . Any two have , so by Theorem 1 they are nonzero and pairwise orthogonal, hence linearly independent in , and is at least their number. For odd , also take the vectors with and containing column 1; there are of them. Two sets of size that both contain column 1 have a union of at most columns, and a set of size with a set of size at most also has a union of at most columns. So Theorem 1 again makes all the vectors orthogonal.
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 is an integer, is also a multiple of .
Theorem 3 (code duality). Let be a linear code of length over the field with elements, with , and let be the minimum distance of the dual code . The codewords of , as the rows of a array, form an orthogonal array of strength exactly .
Proof. Fix a set of columns. The projection of onto the columns is linear, so if it is onto, every -tuple is hit by a coset of its kernel, that is, times. It fails to be onto exactly when a nonzero linear form on the coordinates vanishes on . Such a form is a nonzero vector supported inside with for every , that is, a nonzero dual codeword of weight at most supported in . So the array has strength if and only if no nonzero dual codeword has weight at most , that is, .
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 fraction, the runs (with level written as bit 0 and as bit 1) are the dual of the code of defining words, whose minimum distance is the resolution . So Theorem 3 gives strength .
Examples and non-examples
Example: . The rows , the even-weight code of length 3, form the half fraction of a design. Every two columns show once, so the strength is 2, and meets the Rao bound . The strength is not 3: only 4 of the 8 triples occur.
Example: Latin squares. From mutually orthogonal Latin squares of order , the rows form an , and every such array of index 1 arises this way. The two orthogonal squares of order 3 give , and the three squares of order 4 built over the field with 4 elements give . Both meet the Rao bound, and . In general for index 1 is the Rao bound , which is again the bound of at most mutually orthogonal Latin squares.
Example: the Hamming code. The 16 codewords of the [7, 4] Hamming code form an : the dual is the [7, 3] simplex code, whose nonzero words all have weight 4, so and the strength is 3. The Rao bound for , , is , so the array is above the bound. But must be a multiple of , so 16 is the smallest possible. Adding a parity bit gives the extended [8, 4, 4] code, which is its own dual: an that meets the Rao bound . As a design it is the fraction of resolution IV.
Example: the simplex code and the Plackett-Burman designs. The 8 words of the [7, 3] simplex code form an , the saturated design; its dual is the Hamming code with . The 12-run Plackett-Burman design is an . Both meet the Rao bound for , . 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 exists, because the Rao bound is . So no 8-run two-level design has 8 balanced, pairwise orthogonal factor columns.
Non-example: a covering array. The 5 rows show every pair of levels in every pair of columns, but occurs twice and the other pairs once. This is a covering array of strength 2, which asks that every -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 ), 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.
Related definitions
- Factorial design: the full design, the array of largest strength.
- Fractional factorial design: a regular fraction of resolution is a linear orthogonal array of strength .
- Plackett-Burman design: two-level arrays of strength 2 that meet the Rao bound for every with a Hadamard matrix.
- Latin square design: mutually orthogonal Latin squares are the arrays of strength 2 and index 1.
- Linear code, dual code and MacWilliams identity: the strength of a code as an array is its dual distance minus 1.
- Singleton bound: two rows of an array of index 1 and strength agree in at most columns, so the rows form a code that meets the Singleton bound, such as a Reed-Solomon code.
- Balanced incomplete block design: balances pairs of treatments in blocks, as a strength-2 array balances pairs of levels in columns.
- Latin hypercube sampling: orthogonal arrays give Latin hypercube samples that are also balanced in pairs of dimensions.
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.
# 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
- 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)
- 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)
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 5Q12GA Edit this page History Report an error Markdown