WorksComputer Science
When Is Product Decoding of ECOC MAP-Consistent? Pair Structure and the n-vs-Rest Codes
Abstract
Error-Correcting Output Codes (ECOC) combine binary classifiers by the sum decoder, which totals probabilities, or the product decoder, which totals log-likelihoods. In the noiseless setting, where the binary classifiers output the true posteriors, we ask on which code matrices each decoder always agrees with the Bayes-optimal (MAP) class. For the sum decoder the answer is known: the code must be equidistant (James and Hastie, 1998). We answer the question for the product decoder. Two classes are compared through the votes of the columns on which they differ: the sum decoder decides by their sample mean, the product decoder by an M-estimator with influence function artanh, and each vote is the MAP margin plus a bias determined by the other classes alone. Our main theorem states that the product decoder is MAP-consistent if and only if, for every class pair, the columns on which the two classes differ are matched with the columns obtained by swapping the two classes (or their complements), and equivalently if and only if the code is a union of n-vs-Rest codes. Efficient equidistant codes are therefore excluded: Hadamard codes (), which meet the Plotkin bound with columns, have no such pairs, and for the Sylvester type the reversal margin can be at least a constant 0.0182 independent of . All theorems are machine-checked in Lean 4. On six real datasets with estimated probabilities, the product decoder is slightly more accurate when each column is calibrated, and the sum decoder is better when the calibration error differs across columns; in either case the decoders disagree only near ties.
Introduction
Error-Correcting Output Codes (ECOC) reduce multi-class classification to binary problems [4, 1]. Each class is assigned a code word , and a binary classifier is trained for each column ; decoding aggregates the outputs and predicts the class with the “closest” code word.
Decoders fall into two groups: the sum decoder ( decoding [4]), which adds the column probabilities, and the product decoder (loss-based decoding (Allwein et al., 2000; Passerini et al., 2004)), which adds the Bernoulli log-likelihoods of the columns. Which should be used? Our answer:
If the classifiers output the true posteriors, the sum decoder always returns the MAP class if and only if the code is equidistant (James & Hastie, 1998b), and the product decoder if and only if the code is a union of -vs-Rest codes. Short codes with large distance, such as Hadamard codes, are equidistant but not of this form, so on them only the sum decoder is safe. For real classifiers with estimation error, the product decoder is slightly more accurate when each column is calibrated individually, and the sum decoder is better when the calibration error varies across columns. In either case the two decoders differ only near ties.
We derive the first part of this answer in the noiseless setting, in which the binary classifiers are perfect:
where is the true posterior vector. Here any disagreement with MAP is caused by the decoding rule and the code structure, not by estimation error.
The answer matters because codes differ greatly in cost. The number of binary classifiers is the code length, and the error-correcting power is governed by the distance between code words. The -vs-Rest codes (nvR: the columns are all splits of classes versus the rest) include 1-vs-Rest, which has length but distance only 2, and 2vR, whose distance costs columns. The Hadamard code reaches distance with only columns, meeting the Plotkin bound (Plotkin, 1960), and is used in ECOC practice [2] (Yin et al. 2005; Verma & Swami 2019). Which decoder may be used with such efficient codes?
Contributions
Our analysis rests on one observation. In comparing classes and , only the columns on which their code words differ matter, and each casts a vote for or . The sum decoder decides by the sample mean of these votes, the product decoder by an M-estimator through artanh. For every code, each vote is the MAP margin plus a bias determined by the background mass alone (§ 3). We obtain the following results.
First, the main theorem: the product decoder is MAP-consistent for all in the interior of the simplex if and only if every class pair has pair structure, and if and only if the code is a union of nvR codes (Theorem 1). Pair structure means that the columns on which two classes differ are matched one to one with the columns obtained by swapping the two classes (or their complements). Prior work (Kumoi et al., 2021) represented each column by the pair of class sets on its two sides and defined this correspondence as a symmetry condition. It showed that the condition suffices for product consistency and proved consistency for the nvR family. The main theorem strengthens this to a necessary and sufficient condition and identifies the codes that satisfy it: pair structure for every class pair makes the code invariant under every permutation of the classes, and the invariant codes are exactly the unions of nvR codes. For comparison we restate the known condition for the sum decoder, equidistance (James & Hastie, 1998b), in the same terms (Proposition 1): the sum decoder needs only the first moment of the votes to balance, the product decoder the whole vote distribution. Every product-consistent code is therefore sum-consistent (Corollary 3), but not conversely.
Second, Hadamard codes () do not have a single paired column because their columns are orthogonal (Proposition 3), so for every type of Hadamard matrix the product decoder can disagree with MAP on every class pair. For the Sylvester type, the reversal margin can be at least a constant independent of (Theorem 2). To leading order the reversal margin is governed by the variance of the vote sample (Eq. (9)), and under typical posterior distributions it roughly decays with (Experiment B). The efficiency of the Hadamard code and product consistency are thus incompatible.
Third, experiments on six real datasets examine which decoder is better under estimation error (§ 7). The product decision, a signed sum of log-odds, is invariant to a temperature common to all columns, and with calibrated classifiers the product decoder is slightly more accurate. When the calibration error differs across columns, the sum decoder, which uses bounded votes, is better.
All theorems, lemmas, propositions, and corollaries in Sections 3–6, including the proofs in the appendix, have been machine-checked in Lean 4 with Mathlib (ancillary files of this arXiv submission).
Relation to prior work
Bayes optimality of decoding (James and Hastie). James & Hastie (1998b) (see also James & Hastie (1998a)) showed that decoding, i.e., the sum decoder, is Bayes optimal—it returns the Bayes class whenever the binary classifiers are Bayes classifiers—if and only if the code is equidistant. Proposition 1 restates their theorem for the order of every class pair and in the weak form. We include its short proof because the vote decomposition used there is the starting point for the product decoder.
Robustness to estimation error (Kittler et al.). Kittler et al. (1998) showed that the product rule is Bayes optimal for conditionally independent representations and that the sum rule approximates it when the posteriors are close to the priors, and argued that the sum rule is robust to estimation error. Their question is which combination rule is robust to noisy estimates; ours is whether each decoder, as a function of the code , reproduces MAP given the true probabilities. The two are complementary. In our real-data experiments, with calibrated classifiers the product decoder is sometimes the one that is correct when the two decoders disagree (§ 7).
Asymptotic surrogate consistency (Ramaswamy et al.). Ramaswamy et al. (2014) give conditions on the code matrix under which minimizing a binary surrogate loss recovers the Bayes classifier in the infinite-data limit. There the decoder is designed for the code (the inverse link of a proper composite loss followed by a linear decoding), and consistency is decided by a column-space condition on the code matrix. We go the other way: the decoder is fixed to the plain product (or sum) rule, and we characterize the codes on which it is consistent. Our study of a fixed code, noiseless probabilities, and plain decoders is thus complementary.
Symmetry condition for the product decoder (Kumoi et al., 2021). Prior work showed, through a symmetry condition on class pairs, that the product decoder is MAP-consistent for nvR codes (including 1-vs-Rest, 2vR, half-vs-half) and the Exhaustive code. We add (i) the necessity of this symmetry condition (equivalent to pair structure) for the product decoder and the identification of all codes that satisfy it (Theorem 1); (ii) the inclusion between the two decoders (Corollary 3); and (iii) the absence of pair structure in Hadamard codes (), the resulting inconsistency of the product decoder, and the size of its reversal margin (§ 6). The Hadamard code with coincides with the 2vR code up to column complements and is the only Hadamard code with pair structure (Remark 1).
Passerini et al. (2004) proposed a probability-based (product-like) decoder but gave no MAP-consistency condition. The loss-based decoding of Allwein et al. [1] has the same form as the product decoder, but their theorems bound the training and generalization errors. Tax et al. (2000) showed that sum and product coincide in the special case of two classes and two classifiers. Viewing sum and product as linear and logarithmic opinion pools (DeGroot & Mortera [3]; Genest & Zidek (1986)) places both among aggregation rules.
Section 2 defines the notation and the decoders, Section 3 decomposes the votes, Section 4 restates the condition for the sum decoder, and Section 5 proves the main theorem for the product decoder. Section 6 treats Hadamard codes, Section 7 presents experiments, Section 8 discusses, and Section 9 concludes. Details are in the appendix.
Preliminaries
Decoders and MAP-consistency
Let be the code matrix for classes and code length (row is the code word ), the Hamming distance between code words, and the row weight. Given binary-classifier probabilities , the two decoding scores of class are
with predictions and . The sum decoder is equivalent to decoding onto the code words in [4], and the product decoder sums the Bernoulli log-likelihoods of the columns, i.e., is a logarithmic pool (Genest & Zidek, 1986).
We assume that no column of the code matrix is all-0 or all-1 and that all code words are distinct. Since the product score requires , statements about the product decoder take in the relative interior of the simplex (all entries positive), where these assumptions give for every column. The sum decoder is treated on all of , including the boundary. Complementing column () maps and leaves the th term of and unchanged: a complemented column is the same classifier for both decoders. We therefore assume that a code contains no repeated column and no pair of mutually complemented columns (repeating every column equally often leaves both decoders unchanged, and repeating only some amounts to weighting columns).
The MAP class is . A decoder ( or ) is MAP-consistent if, for every in the range considered,
i.e., the preference order of the decoder agrees with the posterior order on every class pair; at a tie we require . For the weak form, which imposes only , Proposition 1 and Theorem 1 give the same conditions.
Here noiseless refers to the assumption that the binary classifiers output the true posteriors without error (), the same term as in prior work (Kumoi et al., 2023). Real classifiers have , introducing estimation error, which we treat in the real-data experiment of § 7 (Experiment C).
Equidistant codes and the code families studied
Definition 1 (Equidistant code). A code matrix is equidistant if every pair of distinct classes has the same Hamming distance .
Table 1 lists the code families studied and our conclusions. An R code has as columns all partitions of classes versus the rest, including 1-vs-Rest (), 2vR (; two classes versus the rest, not one-vs-one), and half-vs-half (). The normalized Hadamard code is the code obtained from a normalized Hadamard matrix of order by deleting the constant column and mapping to . Class 0 has the all-ones code word, the other classes have weight , and every class pair is at distance (Plotkin, 1960). With a Sylvester matrix ( a power of two), its code words are those of the simplex code with every bit complemented.
Remark 1 (Hadamard code with ). The normalized Hadamard code with has three columns, each placing exactly two classes on one side, so its column set coincides, up to complements, with that of the 2vR code (= half-vs-half ()). For it coincides with no R code. As shown in § 6, the presence of pair structure also splits at this boundary between and .
Class-Pair Comparisons as Samples of Votes
We express the class-pair comparisons of both decoders through one object, the sample of votes cast by the columns on which the two classes differ; the results hold for every code. Fix a class pair and write for the set of columns on which and differ, and . Outside we have , so only the columns in contribute to and .
Definition 2 (Support, vote, agreement sign). For a column , the total posterior of the classes with the same bit as class , , is the support for in column , and is the vote of column $j. The vote is positive if it leans toward and negative if toward . For a background class , the agreement sign is if and otherwise, and is the agreement pattern of column $j.
If then , and if then . Using the odd symmetry of the log-odds , we obtain
That is, the sum decoder decides a class pair by the sign of the sample mean of the votes, and the product decoder by the sign of the sum of the votes passed through . Since is strictly increasing, the latter is equivalent to taking the sign of the root of the location M-estimating equation with influence function . The slope of diverges as , so the product decoder weights confident columns (votes near ) heavily, the opposite of a Huber-type M-estimator, which suppresses outliers.
Lemma 1 (Vote decomposition). Let . For every ,
The bias is determined by the background posteriors alone and does not involve .
Proof. For we have , so class belongs to and class to . Hence .
By Lemma 1, fixing the background mass and moving mass only between and translates the vote sample by without changing its shape. We work on this one-dimensional family. Since , ranges over on it ( for the product decoder). Figure 1 gives an example: with pair structure (§ 5) the sample is symmetric and the two decoders agree; without it, stretches the large votes of a skewed sample and only the product decoder can reverse the MAP order.
Figure 1. Vote sample of one class pair, with the same masses in both panels (, , 0.2 on each of three background classes; MAP picks ). The sum decoder decides by the sign of the mean of the votes , the product decoder by the sign of the mean of . (a) With pair structure the sample is symmetric and the two decoders agree. (b) For the Hadamard code with the sample is skewed; artanh stretches the large vote, and only the product decoder reverses. The masses in (b) are the construction of Theorem 2, with class indices translated in .
The sum of the biases is expressed by code distances.
Lemma 2 (Distance identity). For every background class , . Hence
Proof. For , the bit of agrees with exactly one of and . Thus is the number of columns in on which agrees with minus the number on which it agrees with , i.e., for the distance restricted to . Outside , and agree, so the contributions outside are equal in both distances and the difference is . Eq. (7) follows by substituting into Eqs. (5) and (6).
The second term of Eq. (7) says that each background class pulls the sum decision toward the class closer to itself: if is closer to (), the decision shifts toward .
Sum Decoder: Equidistance Is Necessary and Sufficient
The condition for the sum decoder is known (James & Hastie, 1998b). We restate it in the language of votes, which sets up the comparison with the product decoder.
Proposition 1 (Sum decoder; James & Hastie, 1998b). Let . The sum decoder is MAP-consistent for all if and only if the code is equidistant, in which case . The equivalence also holds for the weak form of consistency that does not require ties.
Proof. (Sufficiency) If the code is equidistant, the second term of Eq. (7) vanishes and . Since , the signs agree.
(Necessity) Take distinct , and for and with set , , , and all others 0. By Eq. (7), . Even under weak consistency this must be positive for and negative for , so letting gives , i.e., . Since this holds for any three distinct classes, two class pairs sharing a class have equal distances. Any two class pairs , are connected by a chain of pairs each sharing a class with the next, such as (a shorter chain suffices when, e.g., ), so all class pairs have equal distances.
For , for distinct code words, so the sum decoder is always MAP-consistent.
Equidistance can also be written as a Gram-matrix condition.
Corollary 1 (Gram-matrix form). A code is equidistant if and only if there exist and such that , in which case . In the equal-weight case ( constant), is a constant vector and the condition reduces to .
Proof. () . () Setting and gives and .
Application to code families
All code families in Table 1 except logM are equidistant. The Hadamard code has unequal row weights (the all-ones row , the others ) but is equidistant, so the sum decoder is MAP-consistent. logM violates equidistance, and the sum decoder indeed disagrees with MAP (§ 7).
| Name | Shape | Equidistant | Pair structure | Sum | Product |
| 1-vs-Rest | Yes, | Yes | Yes | Yes | |
| 2vR | Yes, | Yes | Yes | Yes | |
| Half-vs-Half | Yes, | Yes | Yes | Yes | |
| Hadamard () | Yes, | Yes | Yes | Yes | |
| Hadamard () | Yes, | No | Yes | No | |
| logM | No | No | No | No |
Table 1. Code families studied and their MAP-consistency (noiseless setting). Sum/Product: whether the sum/product decoder is MAP-consistent.
The order of a Hadamard matrix is a multiple of four (apart from 1, 2), but equidistance is preserved under row deletion, since deleting rows but keeping columns preserves the distances among the remaining rows.
Corollary 2 (Equidistant codes by row deletion). Deleting two rows from the Hadamard code with yields an equidistant code with . Deleting two rows including the all-ones row (weight ) leaves ten rows forming an equal-weight equidistant code; keeping the all-ones row and deleting two other rows gives an unequal-weight equidistant code. In both cases the sum decoder is MAP-consistent.
Numerically, no noiseless sum-decoder disagreement was observed for either deletion (Appendix § 13). In general, for not a multiple of four, deleting rows from the Hadamard code of order (as done in practice, e.g., by (Verma & Swami, 2019)) gives an equidistant code for classes with columns and distance : the cost of the missing orders is at most three extra columns.
Remark 2 (Sum product bitwise thresholding on complete codes). When is a power of two, the logM code has every word of as a code word (a complete code). Each column term can then be maximized independently, so the sum decoder, the product decoder, and bitwise thresholding coincide identically and the two decoders never differ, while their disagreement with MAP equals the gap between the bitwise marginal MAP and the joint MAP. The disagreement of logM is thus not a matter of sum versus product but a structural consequence of cutting the code length to .
Product Decoder: The Main Theorem
The sum decoder looks only at the mean of the votes; through artanh, the product decoder also sees the shape of the vote sample. We characterize product reversals on the one-dimensional family with fixed background (Proposition 2) and then give the necessary and sufficient condition over all (Theorem 1). Throughout this section lies in the relative interior of the simplex.
Reversal on a single class pair
Fix a class pair and a background (all entries positive, ), and let
where is the bias of Lemma 1. By Eqs. (5) and (6), on the family.
Proposition 2 (Reversal on a single class pair). is strictly increasing on .
If , then for every on the family (no reversal occurs).
If , then has a unique root , and the product decoder reverses the MAP order if and only if . This interval is nonempty. The case follows by swapping .
Proposition 2 (proved in Appendix § 11) shows that reversal on a class pair is determined solely by whether the bias sample is balanced at zero in the artanh sense (whether ). Even biases with mean zero (as for every equidistant code) need not be balanced, since artanh is nonlinear.
Pair structure and the main theorem
Definition 3 (Pair structure). For a class pair , columns are paired if column equals the column obtained from column by swapping its th and th entries, or the complement of that column. The code has pair structure for if can be partitioned exactly into paired columns.
@
Complements are allowed because a complemented column represents the same classifier (§ 2). The symmetry condition of prior work (Kumoi et al., 2021) is defined on the family of class sets on both sides of each column, so it does not distinguish complements either; since for the swap has no fixed point on , pair structure for all class pairs is equivalent to that condition.
Lemma 3 (Pairs and agreement patterns). Let . Columns are paired if and only if . Hence the class pair has pair structure if and only if the multiset of agreement patterns is invariant under the sign flip .
Proof. In the representation , we have and (). The swapped column of column has entry at , at , and background entries , so its agreement pattern is . Complementing all entries flips the signs of both and , leaving the agreement pattern unchanged. Hence paired columns satisfy . Conversely, suppose . If , the background entries are and column equals the swapped column. If , then and column equals the complement of the swapped column. For the second statement, when , so if the multiset is invariant under sign flip, each occurrence of a pattern can be matched one to one with an occurrence of , and conversely.
We read each column as the split of the classes, where .
Definition 4 (Union of nvR codes). A code is a union of nvR codes if its columns, read as splits, are exactly the splits of the nvR codes for in some nonempty set ; equivalently, together with every column, every split with the same side sizes is a column.
Examples are each nvR code (), the Exhaustive code (), and 1-vs-Rest together with 2vR ().
Theorem 1 (Product decoder; main theorem). Let , take in the relative interior of the simplex, and let the code satisfy the conventions of § 2 (distinct code words, no repeated or complemented columns). The following are equivalent: (1) the product decoder is MAP-consistent; (2) the product decoder is MAP-consistent in the weak form (); (3) every class pair has pair structure; (4) the code is a union of nvR codes.
Proof. (3)(1): By Lemma 3, paired satisfy . Hence for every background , and by Proposition 2(1) the signs agree for all pairs and all . (1)(2): Immediate.
(2)(3): We prove the contrapositive. If a class pair lacks pair structure, it suffices to show for some background ; then by Proposition 2(2) the product decoder strictly reverses the MAP order on a nonempty interval of , contradicting weak consistency. In outline: Expanding as a power series in , the term of degree is (for odd). If vanished for every background, all these terms vanish, and all odd moments of the distribution of agreement patterns are 0. For a distribution on a finite set, the vanishing of all odd moments is equivalent to symmetry under sign flip, which means pair structure (Lemma 3). Appendix B makes this rigorous by restricting to a single ray , which needs only a one-variable power series and a Vandermonde matrix.
(3)(4): A column with is unchanged by swapping and . Hence pair structure for says exactly that the set of columns, read as splits, is invariant under the transposition of and . Pair structure for every class pair is thus invariance under every transposition and, since transpositions generate the symmetric group, under every permutation of the classes. The orbit of a split under all permutations consists of all splits with the same side sizes, i.e., the columns of the nvR code with . A set of splits invariant under all permutations is therefore a union of such orbits, which is (4); conversely, a union of nvR codes is invariant under every permutation.
Without the convention on repeated columns, (4) reads: the multiplicity of a split among the columns depends only on its side sizes.
Corollary 3 (Product consistency sum consistency). A code on which the product decoder is MAP-consistent is equidistant, and hence the sum decoder is also MAP-consistent. The converse fails (Hadamard codes, ; § 6).
Proof. Under pair structure, the pairs cancel in the sum, so for every background class . By Lemma 2, , and the argument in the necessity part of Proposition 1 shows that the code is equidistant.
Proposition 1 and Theorem 1 are requirements of different strength on the vote biases . The sum decoder requires that the sum of the agreement signs of each background class vanish (balance of the first moment); this is equidistance. The product decoder requires that the distribution of agreement patterns itself be symmetric under sign flip (balance of all odd moments); this is pair structure. First-order balance alone is not enough for the product decoder, and through condition (4) the symmetry of the vote distribution for every class pair becomes a symmetry of the whole code under all permutations of the classes.
Application to code families
Corollary 4 (Code families with pair structure). The R codes (including 1-vs-Rest, 2vR, and half-vs-half), the Exhaustive code, their unions, and the Hadamard code with have pair structure for every class pair, so both decoders are MAP-consistent on them.
Proof. Each is a union of R codes: the Exhaustive code is the union over all , and the columns of the Hadamard code with are the three splits of the four classes into two pairs, i.e., half-vs-half with (Remark 1). Condition (4) of Theorem 1 applies. For pairs of the Hadamard code with containing class 0 (the all-ones row), both columns of lie on the side of class 0, so the pair is given not by the swap but by the complement of the swap.
As in the last case, some columns pair only with the complement of the swapped column when read as 0/1 vectors; representing each column by the class sets on its two sides removes the distinction (the Hadamard code with is the same matrix as the 2vR example () of prior work).
Pair structure is fragile. Deleting one column from 2vR breaks its pair, and pair structure is lost for the class pairs that differ on that column. This is consistent with the jump in the product disagreement rate (from 0% to a few %) observed in Experiment A. Row deletion, on the other hand, preserves pair structure (the swap and complement relations still hold on the remaining rows).
Remark 3 (The cost of product consistency). By condition (4), a product-consistent code contains an entire R block. For , every product-consistent code other than 1-vs-Rest therefore has at least columns ( for , and for ), while 1-vs-Rest has distance only 2. The Hadamard code reaches distance with columns, fewer than 2vR by a factor of about , but has no pair structure (§ 6).
Hadamard Codes: Absence of Pair Structure and the Reversal Margin
Hadamard codes are equidistant, so the sum decoder is consistent. For the product decoder we show that for no column has a paired column, and we evaluate how large the resulting disagreement can be.
Absence of pair structure
Proposition 3 (Hadamard codes have no pair structure). For every normalized Hadamard code with (not only the Sylvester type) and every class pair , no column in has a paired column.
Proof. In the representation, suppose columns are paired. The swapped column differs from column only in entries and , so the entrywise product has exactly 2 entries equal to $-1, and for the complement of the swapped column exactly . On the other hand, distinct columns of a Hadamard matrix are orthogonal, so the entrywise product sums to , i.e., has exactly entries equal to . We have only for .
Corollary 5 (Product inconsistency on Hadamard codes). For every normalized Hadamard code with , the sum decoder is MAP-consistent but the product decoder is not. Moreover, for every class pair there exists on which the product decoder reverses the MAP order.
Proof. By Proposition 3 no class pair has pair structure, so by the proof of (2)(3) in Theorem 1, for every class pair there exists at which a reversal occurs.
The columns of a Hadamard code are maximally spread: any two differ on half of the rows. This enlarges the code distance and gives equidistance (first-order balance), but makes it impossible for two columns to be related by a swap (pair structure). The property that makes the Hadamard code a good error-correcting code thus rules out pair structure. Orthogonality is also why Verma & Swami (2019) choose Hadamard codes, since orthogonal code words make their probability estimates admissible; for MAP-consistency of the product decoder, the orthogonality of the columns is instead the obstacle.
For the Sylvester type, some class does not appear at all in the comparison statistic.
Proposition 4 (Invisible class). For the Sylvester Hadamard code with , index the classes by . For every class pair , the class satisfies identically on . Hence on does not involve , and does not depend on .
Proof. The code word of class on the nonzero columns is with (since , ). By the character product rule , , so for .
For a pair containing class , : does not involve of the compared class itself, whereas the sum decoder gives , which involves explicitly.
How large can the reversal margin be?
By Proposition 2, the width of the range of with reversal (the reversal margin) is the root of (unless it exceeds the feasible range ). For equidistant codes the biases have mean (Lemma 2). Substituting into and solving for with , the leading terms are
The numerator has only odd moments (skewness) of the bias sample; the even moments (variance) enter the denominator and suppress the margin. A symmetric bias sample thus produces no reversal (pair structure), and a larger reversal margin requires a skewed sample.
One may expect the background to be diluted and the margin to shrink to as grows; under typical posteriors this indeed happens (see below). For the Sylvester type, however, concentrating the background mass on a few classes to maximize skewness keeps the margin at a constant independent of .
Theorem 2 (Dimension-independent lower bound on the worst-case reversal margin). Let be the unique positive root of
(). For every Sylvester Hadamard code (), every class , and every , there exists (in the relative interior) with such that class is the MAP class (the largest entry of ) but the product decoder ranks class above . That is, the worst-case reversal margin is at least , and does not depend on .
The key to the proof is to place mass on each element of an -closed triple of background classes. By the character product rule, the bias then degenerates to two points, (proportion ) and (proportion ), and the root equation of becomes Eq. (10), which involves neither nor . The full proof is given in Appendix § 11.
Numerically, agrees to machine precision for , and the same construction gives not only a class-pair reversal but also an argmax disagreement. The argmax disagreement persists while the MAP margin (the gap between the top two posteriors) is at most , independently of ; the product decoder then picks a class of the background triple. Below, the reversal margin measured in experiments is this MAP margin at points where the argmax disagrees.
is a proven lower bound, not the worst-case supremum. We ran multi-start SLSQP from class pairs whose code words have equal weight and from sampled disagreement points. For every it found margins (mean 0.0232, coefficient of variation 0.10), each verified with the decoders. These exceed the construction value 0.0166 for every . The worst MAP margin with argmax disagreement is thus at least 0.0166 for the Sylvester type, and local search found none above 0.025; its exact value is open. For non-Sylvester types the triple character identity is unavailable, so we have no proved lower-bound constant (numerically, a similar is observed).
The typical margin decays with
The largest among disagreement points found by random sampling (the typical value below) roughly decays with (Dirichlet: 0.0135 at , 0.0066 at , about 0.003 at ). The product ranges over 0.10–0.18 rather than being constant, so a pure law does not hold. The decay is consistent with Eq. (9): as grows, the background mass spreads over many classes and the skewness of the bias sample shrinks. The worst-case construction lies in a corner of the simplex with mass on only five classes, which random sampling rarely hits.
Hence, the worst-case reversal margin does not vanish as grows, but the at which reversals occur are confined to a thin region near ties, which shrinks with under typical distributions.
Experiments
We examine three questions: A, do the theorems hold numerically (noiseless setting)? B, how large are the reversals on Hadamard codes? C, which decoder is more accurate with real classifiers? A and B confirm the theory; C answers the second half of the question in the introduction (which decoder is better under estimation error). Settings are detailed in Appendix § 13.
A: Numerical confirmation of the theorems
We sampled noiseless probabilities (four series per code and : Dirichlet and two posteriors built from Gaussian data, 200,000 samples each, or 100,000 for codes with many columns) and measured each decoder’s disagreement rate with MAP (Figure 2). The sum decoder never disagreed on the equidistant codes (all but logM). The product decoder never disagreed on 1-vs-Rest, 2vR, and half-vs-half, which have pair structure, or on the Hadamard code with ; on Hadamard codes with its rate was small but nonzero (0.145%, 0.265%, and 0.300% for $M = 8, 16, 32). logM disagrees heavily for both decoders (14.0% to 68.6% for to 32).
Figure 2. Disagreement rate with MAP in the noiseless setting (%, mean over four series). Left: sum; right: product. The sum decoder is 0 on all equidistant codes (all but logM), the product decoder only on codes with pair structure (1-vs-Rest, 2vR, half-vs-half, Hadamard with ) (Proposition 1 and Theorem 1). n/c: not computed. Half-vs-half has columns (6435 at , about at ), so only was computed; having pair structure, its rate is 0 by the theorem.
The experiments also show that pair structure is fragile (§ 5). Deleting one random column from 2vR raises the product disagreement rate to 4.72% at and 3.12% at (mean over 10 seeds). Since the deletion also breaks equidistance, the sum rate rises similarly (5.26%, 4.48%).
To verify the main theorem pair by pair, we took all 977 class pairs of 49 codes (nvR-type codes; Hadamard , with of Paley type; logM; 24 random codes; and 10 codes obtained from nvR codes by row deletion) and independently (a) tested pair structure (Lemma 3) and (b) searched for at which the product decoder strictly reverses the MAP order (sampling near ties and local optimization).
Every reversal candidate was confirmed with the original decoding formula. Reversals were found for all 773 pairs without pair structure and for none of the 204 pairs with it. Among Hadamard codes, all pairs had pair structure for and none for (consistent with Proposition 3).
B: Size of the reversal margin
We measured the reversal margin of Hadamard codes for in the typical case (Dirichlet sampling, Gaussian data) and the worst case (multi-start SLSQP; Figure 3). The typical value (largest at sampled disagreement points) roughly decays from 0.0135 () to about 0.003 (), whereas the worst case stays within for all , from 1.3 times the typical (Dirichlet) value at to about 9 times at . Over 500,000 noiseless samples for , the true MAP margin at disagreement points was at most 0.00845 (0.51 times the construction value 0.0166). Random posteriors rarely hit the worst-case construction (a corner of the simplex).
Figure 3. Dependence of the reversal margin on (Hadamard codes). Typical values (largest margin at disagreement points found by Dirichlet sampling and Gaussian data) roughly decay with ; the worst values found by local SLSQP search stay within regardless of . Red dashed line: the largest MAP margin with argmax disagreement in the construction of Theorem 2; triangles: Sylvester-type (to which the theorem applies).
C: Which decoder is more accurate with real classifiers?
We compared the decoders under estimated probabilities on six datasets (letter, isolet, pendigits, MNIST, Fashion-MNIST, MobileNetV2 features of CIFAR-100). For random class subsets with (as the data allow), logistic regression was trained for each column of 1-vs-Rest, 2vR, Hadamard, and random dense codes (). Each column was temperature-calibrated on validation data (“calibrated” below), and calibration error was then introduced by scaling the logits (a) of all columns by a common factor (: uniform overconfidence), or (b) by column-specific factors , , (calibration error varying across columns). We compared test accuracies over 5 seeds per condition. Condition (a) and the hypotheses were fixed before the runs; (b) is exploratory, added after seeing (a). On 1-vs-Rest the decoders coincide identically (both take the argmax of the logit of column ), so we report the other codes.
Figure 4 shows the results. When calibrated, the product decoder was more accurate: by +0.3 to +0.4 points for all codes (95% bootstrap confidence intervals excluding 0), and significantly better by McNemar’s test in 24 of the 39 cells (dataset, , code), the sum decoder in none. Uniform overconfidence widens the product advantage (+0.9 to +1.8 points at ). The product decision, a signed sum of logits (Eq. (5)), is unchanged by a common factor. The sum decoder, in contrast, moves toward a Hamming-distance majority vote as the sigmoid saturates, which is consistent with its loss of accuracy. Calibration error varying across columns reverses the sign. At the sum decoder was better by 0.9 to 2.0 points, significantly in 36 of the 39 cells. This is consistent with how the decoders weight the votes: the product decoder weights confident columns heavily (§ 3), so overconfidence in a few columns can dominate its decision, whereas the sum votes are bounded in . We did not model how the column errors combine; § 8 lists this as future work. The reversal was largest on Hadamard codes.
Figure 4. Accuracy difference between the product and sum decoders with real classifiers (points; positive means the product decoder is more accurate). Means and 95% bootstrap confidence intervals over six datasets, each , and 5 seeds. (a) All logits multiplied by a common factor : the product decision is unchanged, while the sum decoder degrades as grows. (b) Column-specific factors : as the spread grows, the sum decoder becomes better.
The estimated margin at disagreement points (the gap between the top two sum scores) was small, about 7% of the overall mean (median), and below the overall mean in all 139 of the 156 (dataset, , code, ) conditions with at least 20 disagreements: disagreements concentrate near ties.
Discussion
Which decoder should be used?
By the criterion of noiseless consistency the answer is clear. Exact MAP-consistency requires an equidistant code for the sum decoder (Proposition 1) and a code with pair structure, that is, a union of codes, for the product decoder (Theorem 1), and pair structure implies equidistance (Corollary 3). The sum decoder is thus safe on a wider class of codes. In particular, the Hadamard code is an efficient equidistant code with distance and length , but for it has no pair structure (Proposition 3); with a Hadamard code, choose the sum decoder if exact consistency is needed. The codes are consistent for both decoders, but column deletion breaks pair structure and equidistance (Experiment A), so the code must be used in full.
Product reversals matter only in a limited range. is a proven lower bound showing that the reversal margin can be this large (Theorem 2), not an upper bound guaranteeing safety; local search has found reversals up to 0.025. Under random posteriors the MAP margin at disagreement points was at most about half of the construction value (Experiment B); either way, reversals are confined to near ties, where the posteriors are nearly equal.
Under estimation error the picture changes (Experiment C). With calibrated logistic regression the product decoder is slightly more accurate, and its decision is unchanged under uniform overconfidence of all columns; when the calibration error differs across columns, the sum decoder is better. This is consistent with the product decoder reading the votes as unbounded log-odds and the sum decoder as bounded probabilities. In practice, use the product decoder if the probability of each column can be calibrated individually, and the sum decoder if the calibration quality varies across columns (or cannot be checked). Either way the difference is within about 2 points (0.3–0.4 points when calibrated), and disagreements are confined to near ties. The claim of Kittler et al. (1998) that the sum is robust to estimation error can be read as robustness to calibration error varying across columns.
Limitations and future work
Our theory assumes the noiseless setting , which separates the decoding rule and the code structure from classifier error but does not hold for real classifiers: under estimated probabilities, even , on which both decoders agree with MAP in the noiseless setting, yields different sum and product decisions (Experiment C). How robust equidistance and pair structure are to estimation error is unknown. Experiment C suggests that, under estimation error, which decoder wins may depend on how the column errors combine; analyzing this through error exponents (reliability functions) is future work.
For the reversal margin of Hadamard codes, open problems are (1) the exact worst MAP margin with argmax disagreement (at least 0.0166; local search found at most 0.025) and an analytic derivation of the threshold in the construction (currently only numerical); (2) the lower-bound constant for non-Sylvester types (numerically, a similar is observed); and (3) the exact rate of decay in the typical case.
Conclusion
We have characterized the MAP-consistency of the product decoder in ECOC under the noiseless setting . Reading a class-pair comparison as a sample of votes, the sum decoder decides by the sample mean and the product decoder by an M-estimator through , and for every code each vote is the MAP margin plus a bias determined by the background alone. The sum decoder is MAP-consistent if and only if the code is equidistant (James & Hastie, 1998b) (Proposition 1). Our main theorem (Theorem 1): the product decoder is MAP-consistent if and only if every class pair has pair structure, which strengthens the sufficient symmetry condition of prior work (Kumoi et al., 2021) to a necessary and sufficient one, and if and only if the code is a union of codes. Every product-consistent code is sum-consistent (Corollary 3). Hadamard codes (), which meet the Plotkin bound, have no pair structure because their columns are orthogonal (Proposition 3), and for the Sylvester type the reversal margin can be at least a constant independent of (Theorem 2). For not a multiple of four, row deletion gives equidistant codes at a cost of at most three extra columns.
Experiments confirmed Proposition 1 on the codes of Experiment A and the main theorem on 977 class pairs. Under estimation error, the product decoder was slightly more accurate when each column was calibrated, and the sum decoder was better when the calibration error differed across columns; with real classifiers it appears safe to choose the product decoder if the calibration of each column can be checked, and the sum decoder otherwise. The core difference between the two decoders is that the sum decoder requires only first-moment balance of the votes (equidistance), whereas the product decoder requires symmetry of the whole vote distribution (pair structure), and this symmetry leaves only the codes.
Acknowledgments
The author is deeply grateful to Shigeichi Hirasawa, Manabu Kobayashi, and Hideki Yagi for many years of seminar discussions; this paper is the culmination of the discussions that began with the earlier work (Kumoi et al., 2021). This work was supported by JSPS KAKENHI Grant Number JP24K20833.
Proofs from the Main Text
Proof of Proposition 2. When is in the relative interior, , so and . is defined on the open interval on which for all , and it diverges to at the left endpoint and at the right endpoint, so it has a unique root on . Since , we have .
The product decoder prefers iff , and MAP prefers iff . (1) If , monotonicity gives . (2) If , the root lies at ; for the reversal occurs, and for the signs agree. Since on the family is restricted to , the reversal interval is , which is nonempty because .
Proof of Theorem 2. Fix any class and take the class pair . Since , and ; in the character form of Proposition 4, , and the agreement sign of a background class is . Choose linearly independent with (possible for ) and let . Place background mass on each element of the triple and set the other background classes to 0. Then and .
By Lemma 1, the bias is . By the product rule , , taking the value 3 only when . Since are linearly independent, is uniformly distributed on over . Hence
and , . By Proposition 2(2) there is a root . Writing and using the odd symmetry of , the root equation becomes , i.e., Eq. (10), which does not involve . Since , the reversal interval is , i.e., . Then exceeds the triple masses and , so is the MAP class.
This construction has mass on only five classes and lies on the boundary of the simplex. Distribute a small mass uniformly over the remaining classes and scale the five masses by to obtain . Each on is continuous in , and at the values are bounded away from the endpoints. For fixed the reversal and the fact that is the MAP class hold at with strict inequalities, so they persist for all sufficiently small (the scaling turns into ; starting from restores ).
Proof of (2)⇒(3) in the Main Theorem
Suppose some class pair lacks pair structure, and assume weak consistency; we derive a contradiction. Let be the set of admissible backgrounds.
Step 1. for every . Indeed, if for some , Proposition 2(2) (and, if , the same proposition with ) gives a strict reversal of the MAP order on a nonempty interval of , contradicting weak consistency.
Step 2 (a single ray). Number the background classes and set . Since and , we have for , and Step 1 gives
For the left side equals the convergent power series , an odd function of . It therefore vanishes on all of , and uniqueness of power-series coefficients gives for every odd .
Step 3 (symmetry). Let be the finite set of the values and . For odd , ; for even the two terms cancel. These equations for imply by the nonsingularity of the Vandermonde matrix, i.e., the multiset is symmetric about 0.
Step 4 (back to patterns). With the set of background classes with , . By uniqueness of binary expansions, determines and hence , and corresponds to . Hence the multiset of agreement patterns is invariant under sign flip, and by Lemma 3 the class pair has pair structure, a contradiction.
Experimental Details
Table 2 summarizes the main settings of the experiments in § 7.
| Exp. | Main settings |
| A | Noiseless agreement: 1-vs-Rest, 2vR, half-vs-half, Hadamard, ; four series (Dirichlet and two derived from Gaussian data), 200,000 samples each (100,000 for codes with many columns); column deletion from 2vR (10 seeds); pair-structure check on 49 codes and 977 class pairs |
| A′ | Row deletion (Corollary 2): two rows deleted from Hadamard to give (equal-weight and unequal-weight cases); Dirichlet , 50,000 samples each; zero sum-decoder disagreements |
| B | Hadamard ; typical values (largest margin at disagreement points) from Dirichlet (50,000 × 3 seeds) and Gaussian data (20,000 × 4 variances ×3 seeds); worst values by multi-start SLSQP (maximum over 100 starts × 3 seeds); margin distribution at disagreement points from 500,000 noiseless samples for |
| C | letter, isolet, pendigits, MNIST and Fashion-MNIST (PCA-50, at most 1500 per class), CIFAR-100 (MobileNetV2 features, PCA-100); (as far as the number of classes allows); class subsets and splits (train/validation/test = 60/20/20) varied over 5 seeds; per-column logistic regression (inverse regularization strength 1, standardized features) with temperature calibration on validation data; (a) common factor , (b) column-specific factors , (3 draws each). The hypotheses and the design of (a) were fixed before the runs |
Table 2. Experimental settings.
Reproducibility. The Lean 4 formalization of all theorems, lemmas, propositions, and corollaries is provided in the ancillary files of this arXiv submission. The numerical claims are confirmed by verification scripts, and the code to reproduce the experiments will be released in a public repository after acceptance. The product score is computed as the sum of the Bernoulli log-likelihoods of the binary-classifier outputs (Eq. (3)), i.e., the exact log-likelihood rule rather than a -type approximation. CIFAR-100 features are extracted once and cached for reuse.
References
- [1]Erin L. Allwein, Robert E. Schapire, and Yoram Singer. Reducing multiclass to binary: A unifying approach for margin classifiers. Journal of Machine Learning Research, 1:113–141, 2000.
- [2]Lorena Álvarez-Pérez and Álvaro Callejas-Ramos. Walsh sequences as direct error correcting output code dichotomies for multiclass problems. Engineering Applications of Artificial Intelligence, 173:114442, 2026. doi: 10.1016/j.engappai.2026.114442.
- [3]Morris H. DeGroot and Julia Mortera. Optimal linear opinion pools. Management Science, 37(5):546–558, 1991. doi: 10.1287/mnsc.37.5.546.DOI
- [4]Thomas G. Dietterich and Ghulam Bakiri. Solving multiclass learning problems via error-correcting output codes. Journal of Artificial Intelligence Research, 2:263–286, 1995. doi: 10.1613/jair.105.DOI



