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

SVM Predictor — Machine Learning/Classical Models

Machine_Learning/Classical_Models/SVM_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.

SVM Predictor

Machine Learning / Classical Models

Evaluates a fitted support vector machine at inference, with the model baked in as configuration:

score = intercept + Σi coefi·K(svi, u), and label = +1 when score ≥ 0, −1 otherwise.

The numbers come straight out of scikit-learn: support_vectors_, dual_coef_ and intercept_. Nothing is fitted here and no model file is read – that is what lets the block export to all ten targets and run with no interpreter.

Ports

  • u – the feature vector, a column [d,1], where d must equal the number of columns of Support Vectors.
  • score – a scalar [1,1]: the decision function. Its magnitude is the margin, in the units the kernel produces.
  • label – a scalar [1,1]: +1 or −1. Emitted as a number rather than a boolean, so no backend needs a type the others lack.

Parameters

  • Support Vectors – an [N,d] matrix, one support vector per row. This is scikit-learn's support_vectors_ orientation, so it pastes in without transposing.
  • Dual CoefficientsN values, scikit-learn's dual_coef_. ⚠ These already carry the sign (they are y·α, not α), so the class labels must not be applied again. A row or a column is accepted; both spell the same sequence.
  • Intercept – a scalar, scikit-learn's intercept_.
  • Kernel – which K:
    • RBF (Gaussian) – exp(−γ·‖u−sv‖²). The default, and what a model fitted without thought about kernels almost certainly uses.
    • Linear – u·sv. See Code export: this one collapses to a single weight vector.
    • Polynomial – (γ·u·sv + coef0)degree. Note γ multiplies the dot product inside the power, which is the detail that differs silently between libraries.
  • Gamma – the kernel width for RBF and the scale inside Polynomial. Must be strictly positive for RBF; at zero every kernel value collapses to 1 and the block reports its bias whatever the input is. Ignored by Linear.
  • Coef0 – the additive term inside the polynomial power. Ignored by the other two kernels.
  • Degree – the polynomial power, a whole number ≥ 1, rounded from what is typed. Ignored by the other two kernels. It is unrolled into repeated multiplication at export, so a large degree makes a large core; values above 32 are refused for that reason.
  • 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 linear kernel folds. Because K is a dot product, Σi coefi·(svi·u) is (Σi coefi·svi)·u, so the whole support-vector set collapses to one weight vector at config load and the exported core performs a single multiply-accumulate over d features instead of N×d. That folded vector is exactly what scikit-learn calls coef_.

The HDL story depends on the kernel. Linear and Polynomial are multiply-accumulate only, so the three HDL targets carry them in genuine Q16.16 fixed point. RBF has an exponential and cannot: those three bodies are simulation-only real arithmetic that quantizes at the port boundary only. A polynomial of high degree in Q16.16 will also saturate long before the software targets do, since each factor multiplies the dynamic range.

Simulink bridge

None. Simulink's SVM prediction blocks belong to the Statistics and Machine Learning Toolbox, which is not installed on this machine, and they take a fitted model object rather than parameters – there is no ParamRule that could carry a support-vector set across. The bridge reports the block rather than dropping it silently, and it has no parity testbench, which is the documented consequence of Support::None. Code export verification still covers it across all ten languages, in every kernel.

Notes

  • Algebraic and stateless: the outputs depend only on the current input, so the block cannot break an algebraic loop.
  • Nonlinear, and deliberately carries no state space – even under the linear kernel, where the score is affine in u. A state space would let model reduction absorb the block into a neighbouring plant, and what that erases is the label output, which is a discontinuous function of the same input.
  • The label is discontinuous at the boundary, so the three HDL targets can disagree with the simulation on a sample whose score sits within one Q16.16 quantum (about 1.5e-5) of zero: label then differs by 2, not by a rounding error. That is inherent to reducing a continuous quantity to a decision in fixed point. Threshold the score output downstream in floating point if an application cannot tolerate it.
  • Multi-class is not this block. A one-vs-rest ensemble is several of these into Argmax Decision; a one-vs-one vote is several into a vote. Keeping the block binary is what keeps the config a matrix rather than a ragged set of them.

Code facts#

FactValue
registered typeMachine_Learning/Classical_Models/SVM_Predictor
familyMachine_Learning/Classical_Models
solver environment classICoreBlock_0_Machine_Learning_1_Classical_Models_2_SVM_Predictor
sourcesrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/SVM_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_SVM_Predictor.cpp
headersrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/SVM_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_SVM_Predictor.h
default size on canvas130 × 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
1inICoreDoubleu
2outICoreDoublescore
3outICoreDoublelabel

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
Support Vectors[1 0.5; -1 -0.5]
Dual Coefficients[1; -1]
Intercept0
Kernelsvm::kernelComboSpec()
Gamma0.5
Coef00
Degree3

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 Simulink equivalent available: SVM prediction lives in the Statistics and Machine Learning Toolbox, which is not installed on this machine, and its predict blocks take a fitted model OBJECT rather than parameters -- there is no ParamRule that could carry a support-vector set, its dual coefficients and a kernel across

Catalog contract: src/ICoreSDK/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).

SVM Predictor — a fitted binary SVM at inference score = intercept + SUM_i coef_i * K(sv_i, u) label = +1 if score >= 0 else -1

All of the kernel machine -- conventions, config reading, reference math and ten emitted bodies -- lives in ICoreSvmKernelSupport, shared with One_Class_SVM_Score. This file is the block around it: ports, config, the two outputs, and the sign test.

The sign test is written as score < 0 -> -1 in every backend rather than >= 0 -> +1 in some and < 0 in others: the two disagree on a score of exactly zero, which is the one sample a fixed-point backend is most likely to produce, and a label is a whole step apart.

Sample results#

No stimulus produced a sampled output in this rig — Invalid model at: ICore Blocks/Home/SVM 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 ccf005c8 · produced by docsSample --out <folder> --steps 60

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