Generated reference › ECOC Classifier Predictor — Machine Learning/Classical Models
kind: generated#block#machine-learning-classical-models

ECOC Classifier Predictor — Machine Learning/Classical Models

Machine_Learning/Classical_Models/ECOC_Classifier_Predictor · 1 input / 3 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

ECOC Classifier Predictor

Machine Learning / Classical Models

Evaluates a fitted multiclass error-correcting output codes model at inference – what MATLAB's [label, NegLoss, PBScore] = predict(Mdl, x) returns for a ClassificationECOC model (trained with fitcecoc) and one observation. Each of L binary learners scores x; each of K classes is scored by how well those scores agree with its row of the coding matrix M:

sl = T(fl(x)),   lossk = meanj g(Mkj·sj),   NegLoss = −loss,   label = ClassNames(k) for the first k with the largest NegLoss – where fl is the l-th learner's score, T the learners' score transform and g the binary loss.

Each learner is a kernel machine: z = (x − Mul) ./ Sigmal, fl = Σi Alphai·K(z/sl, SVi/sl) + Biasl, or (z/sl)·Betal + Biasl for the linear kernel. The model is baked in as configuration, pasted from the fitted object; nothing is fitted here and no model file is read.

Supported binary learners

  • SVM learners (fitcecoc's default, and templateSVM) with the linear, gaussian or polynomial kernel, standardised or not, each learner with its own kernel scale, Mu and Sigma.
  • Linear learners (templateLinear, ClassificationLinear): the linear kernel with Kernel Scale 1, Mu 0 and Sigma 1; Binary Score Transform logit for the logistic learner, none for the svm learner.

Not supported: kernel learners (templateKernel, a random feature expansion – a different model), tree, KNN, naive Bayes, discriminant and ensemble learners (each a different model representation), SVM learners fitted with 'FitPosterior' (their step or sigmoid transforms are per-learner functions), custom kernels and custom binary losses (a function handle cannot be pasted as a number), and the posterior-probability output (a per-observation optimisation).

Ports

  • x – one observation, a column [D,1] with one predictor per row, in the order the model was trained on.
  • label – the predicted class, a scalar [1,1]: one of the Class Names, as a number.
  • negloss – the negated average binary loss per class, a column [K,1] in Class Names order: MATLAB's NegLoss, as a column.
  • pbscore – each binary learner's positive-class score s, a column [L,1]: MATLAB's PBScore, as a column.

Parameters

  • Coding Matrix – Mdl.CodingMatrix, [K,L], entries −1, 0 or +1: row k is class k, column l is learner l. Every design fitcecoc and designecoc produce is accepted (onevsone, onevsall, binarycomplete, ternarycomplete, ordinal, denserandom, sparserandom), since the design is only the matrix. Every row needs at least one nonzero entry.
  • Class Names – Mdl.ClassNames, K numbers in the model's own order (the order of the coding matrix's rows). Text or categorical labels are not numbers: use their positions, 1..K, and map them downstream.
  • Kernel Function – the learners' KernelParameters.Function, shared by all of them as a templateSVM makes it:
    • linear – K = a·b. The default, as in fitcecoc. The learners are then given by Beta.
    • gaussian – K = exp(−‖a − b‖²) (MATLAB's 'rbf' is the same kernel).
    • polynomial – K = (a·b + 1)Order.
  • Beta – [D,L], column l the l-th learner's Beta. Used by linear only. fitcecoc's linear SVM learners discard their support vectors and keep only this.
  • Support Vectors – [N,D], every learner's SupportVectors stacked in learner order (standardised, as MATLAB stores them). Used by gaussian and polynomial.
  • Alpha – N signed coefficients stacked the same way: each learner's Alpha .* SupportVectorLabels.
  • Support Vector Counts – L whole numbers, how many of the stacked rows belong to each learner.
  • Bias – L values, each learner's Bias.
  • Kernel Scale – L values, each learner's KernelParameters.Scale ('auto' gives every learner its own), or one value for all. Strictly positive.
  • Polynomial Order – a whole number from 1 to 32. Used by polynomial only.
  • Mu – [L,D], row l the l-th learner's Mu: standardised one-vs-one learners each carry their own, since each saw only its own classes. One row applies to every learner; 0 means none (an unstandardised model).
  • Sigma – [L,D] likewise, or one row, or 1 for none. A predictor whose Sigma is 0 is centred but not divided, as in MATLAB.
  • Binary Score Transform – the learners' ScoreTransform:
    • none – s = f, unbounded. SVM learners, and svm-learner linear ones.
    • logit – s = 1/(1 + e−f), a probability. Logistic linear learners.
  • Binary Loss – g, MATLAB's 'BinaryLoss' (the model's BinaryLoss is its default: hinge for SVM learners, quadratic for logistic ones), with y = Mkj·sj:
    • hinge – max(0, 1 − y)/2.
    • hamming – (1 − sign(y))/2; with logit scores, (1 − sign(M·(2s − 1)))/2.
    • linear – (1 − y)/2.
    • quadratic – (1 − M·(2s − 1))²/2.
    • exponential – exp(−y)/2.
    • binodeviance – log(1 + exp(−2y))/(2·log 2).
    • logit – log(1 + exp(−y))/(2·log 2).
    As in MATLAB, quadratic needs logit scores and linear, exponential, binodeviance, hinge and logit need none; hamming takes either. Any other pairing is refused.
  • Decoding – MATLAB's 'Decoding':
    • lossweighted – the mean over the learners whose coding entry for the class is nonzero. The default.
    • lossbased – the mean over all L learners, a zero entry contributing g(0).
    With no zero in the coding matrix (onevsall, binarycomplete) the two agree.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. The whole model is baked into the body at export time; there is no tunable parameter, so a refitted model means a re-export. The software targets evaluate exactly the arithmetic above, in the same order. The three HDL bodies are simulation-only real arithmetic in every kernel, loss and decoding, quantized at the ports only: the decoder is a mean over each class's coding row followed by an argmax, and five of the seven losses and the gaussian kernel need an exponential or a logarithm. They are not offered as synthesizable.

Simulink bridge

None. Simulink's ClassificationECOC Predict block (Statistics and Machine Learning Toolbox) exists, and its BinaryLoss and Decoding are dialog parameters, but its model parameter, TrainedLearner, is the name of a fitted model object in the MATLAB workspace. That object cannot be built from a coding matrix and the learners' coefficients – ClassificationECOC's constructor refuses direct use and its binary learners' are not public – and a parameter mapping carries one value to one parameter, so neither direction can cross. The bridge reports the block rather than dropping it silently, and it has no parity testbench, which is the documented consequence of that. The arithmetic is checked against MATLAB's own predict instead, and code export verification covers all ten languages. The Simulink block also has no SampleTime parameter.

Notes

  • Algebraic and stateless: the outputs depend only on the current input.
  • A tie goes to the earlier class in Class Names order – MATLAB takes the first maximum of NegLoss. Ties are common under hamming, whose losses take a handful of values.
  • Prior and Cost do not enter the label. MATLAB uses the prior only for an observation whose losses are all NaN, which it labels with the most probable class; here a NaN in x makes every loss NaN and the label ClassNames(1).
  • The label is discontinuous, so the three HDL targets, which quantize x to Q16.16, can disagree with the simulation on a sample within about 1.5×10−5 of a decision boundary: the label then differs by the distance between two class names. That is inherent to quantizing the input, not an export fault; take negloss downstream if an application cannot tolerate it.
  • Carries no state space: the label is a discontinuous function of x.

Code facts#

FactValue
registered typeMachine_Learning/Classical_Models/ECOC_Classifier_Predictor
familyMachine_Learning/Classical_Models
solver environment classICoreBlock_0_Machine_Learning_1_Classical_Models_2_ECOC_Classifier_Predictor
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/ECOC_Classifier_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_ECOC_Classifier_Predictor.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/ECOC_Classifier_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_ECOC_Classifier_Predictor.h
default size on canvas150 × 100 px
ports at insert1 in, 3 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublex
2outICoreDoublelabel
3outICoreDoublenegloss
4outICoreDoublepbscore

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Coding Matrix[1 1 0; -1 0 1; 0 -1 -1]—
Class Names[1 2 3]—
Kernel Functionmsvm::kernelComboSpec()—
Beta[1 0.5 -0.5]—
Support Vectors[0.6; -0.4; 0.6; -0.4; 0.6; -0.4]—
Alpha[1; -1; 1; -1; 1; -1]—
Support Vector Counts[2 2 2]—
Bias[0.2 -0.1 0.3]—
Kernel Scale1—
Polynomial Order3—
Mu0—
Sigma1—
Binary Score Transformnone%~%logit~~none—
Binary Losshinge%~%hamming%~%linear%~%quadratic%~%exponential%~%bino…—
Decodinglossweighted%~%lossbased~~lossweighted—

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::None
Simulink path—
port-count rulePortsParam::None
SampleTime parameteryes

Caveat (shown to the user): no bridge: Simulink's ClassificationECOC Predict block (statsLibrary) takes its model as TrainedLearner, the NAME of a fitted ClassificationECOC object in the MATLAB workspace, and neither that class nor its binary learners can be constructed from coefficients -- no parameter mapping can build the object from a coding matrix and the learners' support vectors, or read them back out of a variable name

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

ECOC Classifier Predictor — a fitted MATLAB ClassificationECOC model at inference s_l = T( f_l(x) ) the l-th binary learner's positive score loss_k = mean over j of g( M(k,j) * s_j ) (lossweighted: j with M(k,j) ~= 0; lossbased: all) NegLoss = -loss, label = ClassNames(first k with the largest NegLoss)

Read out of R2026a (CompactClassificationECOC.score/predict/localScore, ecocutils.loss, ecocutils.prepareForPredictECOC, ClassificationModel.maxScore) and measured:

  • Seven fitcecoc models -- linear SVM, gaussian SVM (standardised with per-learner 'auto'

scales, and raw), polynomial SVM, one-vs-all gaussian, and ClassificationLinear learners (logistic and svm) -- times the seven losses times both decodings: NegLoss within 9e-15 of the transcription (8.4e-11 only where exponential loss reaches 2.3e4), 0 label mismatches. PBScore (each learner's s) within 1.8e-14.

  • The mean is MATLAB's mean(...,'omitnan') after the zeros of M are made NaN (lossweighted),

then divided by 2 -- or by 2*log(2) for binodeviance and logit.

  • The label is maxScore on NegLoss with the identity transform: the FIRST maximum, so a tie

goes to the earlier class in ClassNames order (measured on a three-way hamming tie, and on 81 ties in 20000 queries with 0 mismatches). Prior and Cost never enter it.

  • quadratic loss is refused unless the learners' scores are probabilities; linear,

exponential, binodeviance, hinge and logit are refused unless they are not (MATLAB's own errors). hamming takes either, with 2s-1 in place of s for probabilities.

  • fitcecoc's default linear SVM learners DISCARD their support vectors (Alpha empty, Beta

only); standardised one-vs-one learners carry their own Mu and Sigma, and KernelScale 'auto' gives each learner its own scale.

  • An ECOC model has no ScoreTransform of its own ("Score transformation is not supported for

ECOC models"); the transform here is the LEARNERS' -- 'logit' for logistic ClassificationLinear learners, 'none' for SVM and svm-learner linear ones.

Sample results#

ECOC Classifier Predictor — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sampleECOC Classifier Predictor — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample-202012345t (s)in ICoreDouble-Out-0out ICoreDouble-Out-0out ICoreDouble-Out-1 [3x1] entry 0out ICoreDouble-Out-2 [3x1] entry 0
tin ICoreDouble-Out-0out ICoreDouble-Out-0out ICoreDouble-Out-1 [3x1] entry 0out ICoreDouble-Out-2 [3x1] entry 0
0-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
0.40.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
0.8-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
1.20.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
1.6-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
20.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
2.4-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
2.80.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
3.2-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
3.60.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
4-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
4.40.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]
4.8-22[-1.225, 0, -0.575][-1.8, -1.1, 1.3]
5.20.51[-0.2875, -0.6625, -0.55][0.7, 0.15, 0.05]

Every 4th of 60 samples, from the table stimulus.

The same rig also ran:

StimulusWhat it isOutput range
impulseImpulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair)1 … 2
rampRamp: slope 1 from t = 01 … 2
sineSine Wave: amplitude 1, 2 rad/s, no phase, no bias1 … 2
stepStep: 0 -> 1 at t = 1 s1 … 2

Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample

Category static · sample time 0.1 · 60 steps · commit 50eb791849fca6bdc23368083262ef77a8b27ee2 · produced by docsSample --out <folder> --blocks SVM_Regression_Predictor ECOC_Classifier_Predictor --steps 60 · data docs/generated/samples/Machine_Learning__Classical_Models__ECOC_Classifier_Predictor.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).