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

Kernel Regression Predictor — Machine Learning/Classical Models

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

Kernel Regression Predictor

Machine Learning / Classical Models

Evaluates a fitted kernel regression model at inference – what MATLAB's predict returns for a RegressionKernel model (trained with fitrkernel) and one observation. Such a model is a linear model on a random feature expansion of x that approximates a Gaussian kernel:

xs = (x − Mu) ./ Sigma (only for a model trained with 'Standardize', true),   y = Σc Betac·zc(xs) + Bias,

where z is MATLAB's Fastfood expansion: for each Hadamard block i, T = H(H(xs·Si)·Gi permuted by Pi)·Bi·√2/(KernelScale·√o), with H the Walsh–Hadamard transform of order o = 2⌈log2 D⌉ (x zero-padded to o entries), and the columns [cos T1, sin T1, cos T2, sin T2, …] cut to the first n = numel(Beta) and each scaled by 1/√(o·b). This is not the kernel SVM of SVM Predictor: there are no support vectors, only the explicit expansion.

The model is baked in as configuration. MATLAB keeps most of its numbers out of the model's public properties, and publishes them through saveLearnerForCoder(Mdl, 'kmdl'); then s = load('kmdl.mat').compactStruct holds every one below.

Ports

  • x – one observation, a column [D,1] with one predictor per row, in the order the model was trained on. D decides the Hadamard order o, which must match the feature maps' width; at most 8 predictors.
  • y – the predicted response, a scalar [1,1] whatever D is.

Parameters

  • Feature Map S – the Fastfood scaling matrix, [b,o], one row per Hadamard block: s.FeatureMapper.S.
  • Feature Map G – the Gaussian scaling matrix, [b,o]: s.FeatureMapper.G.
  • Feature Map B – the random signs, [b,o]: s.FeatureMapper.B.
  • Feature Map P – the permutations, [b,o], each row a permutation of 1…o (one-based, as MATLAB saves it): double(s.FeatureMapper.P).
  • Kernel Scale – the model's KernelScale, a positive number (the resolved value when the model was fitted with 'auto').
  • Beta – the linear coefficients, one per expanded feature, [n,1]: s.Impl.Beta. n is the model's NumExpansionDimensions, at most 256, and it must need exactly b = ⌈n/(2o)⌉ Hadamard blocks – the four feature maps and Beta come from the same model.
  • Bias – the intercept, a scalar: s.Impl.Bias. Added after the sum.
  • Mu – the predictor means, [1,D]: Mdl.Mu. [] (the default) for a model trained without 'Standardize', whose Mu is empty.
  • Sigma – the predictor standard deviations, [1,D]: Mdl.Sigma, or [] with Mu. As in MATLAB, a predictor whose Sigma is 0 is centred and not divided.
  • 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 feature map is linear in x up to the cosine, so it is folded at export into one dense [D,o·b] matrix and every target writes the sum out term by term – D multiply-adds, one cosine and one sine per column pair. That is why D and n are capped: the limits bound the size of the generated code, not the math.

The three HDL targets are simulation-only real arithmetic: a cosine has no Q16.16 form to call. x is converted from Q16.16 at the port and y is quantized to Q16.16 once, at the output.

Simulink bridge

None. Simulink's RegressionKernel 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 these numbers – RegressionKernel 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. The Simulink block also has no SampleTime parameter.

Notes

  • Algebraic and stateless: the output depends only on the current input. Nonlinear, so it carries no state space.
  • Fastfood only. Every model fitrkernel builds uses it – the function has no option to choose another expansion. A model built with the undocumented Kitchen Sinks expansion keeps a matrix W instead of S, G, B and P, and is not carried.
  • ResponseTransform: a model whose ResponseTransform is not 'none' (the default) applies that function after the sum; put it downstream of this block.
  • Missing values differ. MATLAB replaces the prediction for an observation holding a NaN with its PredictionForMissingValue (by default the median of the training responses); here the NaN propagates to y.
  • Agreement with predict is to rounding, not bit for bit: MATLAB applies the butterflies to each observation, this block applies their product, folded once. The two differ by about 10−15.

Code facts#

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

Ports#

#DirectionSignal typeDescription label
1inICoreDoublex
2outICoreDoubley

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
Feature Map S[1.3403916917403467 0.55174335549582743;0.504257347749938…—
Feature Map G[0.56055004797991481 0.46637451014154208;0.30374400581612…—
Feature Map B[-1 1;1 1]—
Feature Map P[1 2;1 2]—
Kernel Scale1—
Beta[-0.47736541704726032;-1.9895626841220537;-0.656430612688…—
Bias-0.69064331012244096—
Mu[]—
Sigma[]—

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 RegressionKernel Predict block (statsLibrary) takes its model as TrainedLearner, the NAME of a fitted RegressionKernel object in the MATLAB workspace, and RegressionKernel has no public constructor -- no parameter mapping can build that object from the feature maps, Beta and Bias, 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).

Kernel Regression Predictor — a fitted MATLAB RegressionKernel model at inference xs = (x - Mu) ./ Sigma only for a model trained with Standardize y = SUM_c Beta_c * z_c(xs) + Bias z = MATLAB's Fastfood feature expansion

Everything shared with Kernel_Classifier_Predictor -- reading the model, building the dense form of the feature map, the reference sum and its ten emitted forms -- lives in ICoreRandomFeatureSupport, whose banner carries the measured map. This file is the block around it: one input, one output, nine configs.

What predict applies was read out of R2026a's RegressionKernel.m (response): standardize when the model was trained with Standardize, map through the FeatureMapper at KernelScale, then LinearImpl.score -- Xm*Beta + Bias -- and finally the ResponseTransform, which is 'none' for every fitrkernel model unless the user sets one. Measured against predict from the model's numbers alone: <= 1.3e-15 over 16 fitted models (n = 7, 10, 16, 128; with and without Standardize; svm and leastsquares learners) and 6.7e-16 on the primary rig's model.

Sample results#

No stimulus produced a sampled output in this rig — Invalid model at: ICore Blocks/Home/Kernel Regression 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 23d8841c6561ca4bb64cd9b5b64da9638de12629 · produced by docsSample --out <folder> --blocks Fixed_Wing_Point_Mass Kernel_Classifier_Predictor Kernel_Regression_Predictor Rotor Rotor_With_Flap_Effects Multirotor Multirotor_With_Flap_Effects Dynamic_Inflow_3_State Kurtogram Empirical_Mode_Decomposition Modal_FRF Order_Spectrum --steps 60

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