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

Linear Classifier Predictor — Machine Learning/Classical Models

Machine_Learning/Classical_Models/Linear_Classifier_Predictor · 1 input / 2 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.

Linear Classifier Predictor

Machine Learning / Classical Models

Evaluates a fitted binary linear classifier at inference – what MATLAB's [label, score] = predict(Mdl, x) returns for a ClassificationLinear model and one observation:

f = Σj Betaj·xj + Bias,   score = [ T(−f) ; T(f) ],   label = ClassNames(2) when score(2) > score(1), ClassNames(1) otherwise – where T is the model's score transform.

The model is baked in as configuration: paste Mdl.Beta, Mdl.Bias, Mdl.ClassNames and Mdl.ScoreTransform from a model trained with fitclinear. Nothing is fitted here and no model file is read.

Ports

  • x – one observation, a column [D,1] with one predictor per row, in the order the model was trained on. D must equal the number of entries of Beta.
  • label – the predicted class, a scalar [1,1]: one of the two Class Names, as a number.
  • score – the two class scores, a column [2,1] in Class Names order: row 1 is T(−f), the first class's score, and row 2 is T(f), the second class's. MATLAB returns the same pair as a row.

Parameters

  • Beta – the linear coefficients, one per predictor: the model's Beta property, [D,1]. A row is accepted too. A matrix with more than one column is refused – that is a model fitted over several regularization strengths; pick one with selectModels(Mdl, idx) first. The Simulink block refuses such a model as well.
  • Bias – the intercept, a scalar: the model's Bias property.
  • Class Names – the two class labels as numbers, in the model's own order: Mdl.ClassNames, copied as it is. The second is the class whose score is T(f) – that holds whatever order the names are in (a model trained with 'ClassNames',[7 3] scores 3 with T(f)). The two must differ. Text or categorical labels are not numbers: use their positions, [1 2], and map them downstream.
  • Score Transform – T, the model's ScoreTransform, spelled as MATLAB spells it. fitclinear sets logit for a logistic learner and none for an SVM learner. All eight act on the pair [−f, f]:
    • none – T(z) = z. The default.
    • logit – 1/(1 + e−z), a probability.
    • doublelogit – 1/(1 + e−2z). On a two-class pair this is also exactly what softmax gives, so use it for a model whose transform is softmax.
    • symmetric – 2z − 1.
    • symmetriclogit – 2/(1 + e−z) − 1.
    • sign – −1, 0 or +1 by the sign of z.
    • ismax – 1 for the larger of the pair and 0 for the other; on a tie the first gets the 1.
    • symmetricismax – as ismax, with −1 in place of 0.
    invlogit is not offered: it takes the logarithm of z/(1−z) and turns complex for any score outside (0,1), which is every raw linear score of one sign. A custom function handle cannot be pasted as a number either.
  • 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 HDL story depends on the transform. f is a multiply-accumulate and the three HDL targets always compute it in genuine Q16.16 fixed point. With none, symmetric, sign, ismax and symmetricismax the whole block stays in fixed point. logit, doublelogit and symmetriclogit have an exponential, so those three HDL bodies are simulation-only real arithmetic after f, quantized again at the output port.

Simulink bridge

None. Simulink's ClassificationLinear Predict block (Statistics and Machine Learning Toolbox) exists, but its only model parameter, TrainedLearner, is the name of a fitted model object in the MATLAB workspace. That object cannot be built from Beta, Bias, the class names and the transform – ClassificationLinear has no public constructor – 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 in every transform. The Simulink block also has no SampleTime parameter.

Notes

  • Algebraic and stateless: the outputs depend only on the current input.
  • The label compares the TRANSFORMED scores, as MATLAB does, and that is not always the same as the sign of f: at f = 0 exactly every transform ties and the first class wins, and under logit a score within about 10−16 of zero rounds both entries to 0.5 and also gives the first class.
  • The label is discontinuous at the boundary, so the three HDL targets, which quantize x to Q16.16, can disagree with the simulation on a sample whose x lies within one quantum (about 1.5×10−5) of the decision hyperplane: the label then differs by the whole distance between the two class names. That is inherent to reducing a continuous quantity to a decision in fixed point, not an export fault; threshold the score output downstream in floating point if an application cannot tolerate it.
  • Nonlinear, and deliberately carries no state space: the label is a discontinuous function of x.
  • No predictor standardization exists for these models (fitclinear takes no such option), and the learner changes how Beta was found, never how it is used. Prior and Cost do not enter the label either; MATLAB uses the prior only for an observation holding a NaN, which it labels with the most probable class – here a NaN makes both scores NaN and the label ClassNames(1).
  • Binary only. A ClassificationLinear model has two classes; several classes are an ECOC model of several of these.

Code facts#

FactValue
registered typeMachine_Learning/Classical_Models/Linear_Classifier_Predictor
familyMachine_Learning/Classical_Models
solver environment classICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Classifier_Predictor
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/Linear_Classifier_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Classifier_Predictor.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/Linear_Classifier_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Classifier_Predictor.h
default size on canvas140 × 90 px
ports at insert1 in, 2 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublex
2outICoreDoublelabel
3outICoreDoublescore

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
Beta[1; -0.5]—
Bias0—
Class Names[-1 1]—
Score Transformnone%~%logit%~%doublelogit%~%symmetric%~%symmetriclogit%~…—

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 ClassificationLinear Predict block (statsLibrary) takes its model as TrainedLearner, the NAME of a fitted ClassificationLinear object in the MATLAB workspace, and ClassificationLinear has no public constructor -- no parameter mapping can build that object from Beta, Bias, the class names and the score transform, or read them back out of a variable name

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

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 every stimulus in the sample errored — cross-checks skipped

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).

Linear Classifier Predictor — a fitted binary MATLAB ClassificationLinear model at inference f = SUM_j Beta_j * x_j + Bias score = [ T(-f) ; T(f) ] T = ScoreTransform, applied element by element label = ClassNames(2) if score(2) > score(1), else ClassNames(1)

Everything here was read out of R2026a (ClassificationLinear.m, LinearImpl.m, ClassificationModel.maxScore, +classreg/+learning/+transform/*.m) and then measured against predict on fitted models:

  • predict fills every class column with -f and then overwrites the column of the SECOND

class -- ClassNames(2), in the order the model reports them, whatever order that is -- with f. Measured: T(-f) and T(f) reproduce both score columns to exactly 0 under every transform below, and with ClassNames given as [7 3] the positive class is 3.

  • The label is maxScore's: the transform FIRST, then the first maximum of the pair. At f

exactly 0 all eight transforms tie and the first class wins (measured, all eight). And it is NOT the same thing as "f > 0": at f = 1.1e-16 the untransformed score picks the second class while logit rounds both entries to 0.5 and picks the first -- measured. So every backend compares the two transformed scores, never f.

  • Prior and Cost do not enter maxScore at all. Prior only chooses the label for an

observation whose scores are all NaN, which a wire here does not carry.

The linear score comes from ICoreLinearModelSupport, shared with the regression block.

Sample results#

No stimulus produced a sampled output in this rig — Invalid model at: ICore Blocks/Home/Linear Classifier Predictor. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit 383c0ecf1501cf1d43d89b8f688fc2fcad5e9b52 · produced by docsSample --out <folder> --blocks Ideal_Airspeed_Correction WGS84_Gravity_Model Linear_Regression_Predictor Linear_Classifier_Predictor Crossover_Pilot_Model Precision_Pilot_Model Tustin_Pilot_Model FIR_Least_Squares_Design FIR_Equiripple_Design Cartesian_To_Keplerian_Elements Keplerian_Elements_To_Cartesian --steps 60

Sample data: docs/generated/samples/Machine_Learning__Classical_Models__Linear_Classifier_Predictor.json