Linear Regression Predictor — Machine Learning/Classical Models
Machine_Learning/Classical_Models/Linear_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.
Linear Regression Predictor
Machine Learning / Classical Models
Evaluates a fitted linear regression model at inference – what
MATLAB's predict returns for a RegressionLinear model and
one observation:
y = Σj Betaj·xj + Bias
The model is baked in as configuration: paste Mdl.Beta and
Mdl.Bias from a model trained with fitrlinear. Nothing is
fitted here and no model file is read, which is what lets the block export to all
ten targets.
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.
- y – the predicted response, a scalar [1,1] whatever D is.
Parameters
- Beta – the linear coefficients, one per predictor: the model's
Betaproperty, [D,1]. A row is accepted too; both spell the same sequence. A matrix with more than one column is refused – that is a model fitted over several regularization strengths, which is several models; pick one withselectModels(Mdl, idx)first. The Simulink block refuses such a model as well. - Bias – the intercept, a scalar: the model's
Biasproperty. It is added after the sum. - 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. Beta and Bias are baked into the body at export time; there is no tunable parameter, so a refitted model means a re-export. The sum is a multiply-accumulate, so the three HDL targets carry it in genuine Q16.16 fixed point, rounded to nearest once per sample; a coefficient or a response beyond ±32768 does not fit that format.
Simulink bridge
None. Simulink's RegressionLinear 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. A model object cannot be built from Beta and Bias –
RegressionLinear 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.
- Affine, not linear, and it deliberately carries no state space: a nonzero Bias is an offset, which A/B/C/D cannot express, so a state space would let model reduction merge the block and drop the Bias.
- What predict applies, and nothing more. These models have no predictor
standardization (
fitrlineartakes no such option), and the learner –svmorleastsquares– changes how Beta was found, never how it is used. A model whoseResponseTransformis not'none'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 the model's
PredictionForMissingValue(by default the median of the training responses); here the NaN propagates to y. - Categorical predictors enter MATLAB's model as dummy variables, and Beta is then indexed by the expanded predictors; feed x in that expanded form.
Code facts#
| Fact | Value |
|---|---|
| registered type | Machine_Learning/Classical_Models/Linear_Regression_Predictor |
| family | Machine_Learning/Classical_Models |
| solver environment class | ICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Regression_Predictor |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/Linear_Regression_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Regression_Predictor.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Classical_Models/Linear_Regression_Predictor/ICoreBlock_0_Machine_Learning_1_Classical_Models_2_Linear_Regression_Predictor.h |
| default size on canvas | 130 × 70 px |
| ports at insert | 1 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | x |
| 2 | out | ICoreDouble | y |
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 variable | Default | Simulink parameter |
|---|---|---|
Beta | [1; -0.5] | — |
Bias | 0 | — |
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.
Simulink bridge#
| support | Support::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): no bridge: Simulink's RegressionLinear Predict block (statsLibrary) takes its model as TrainedLearner, the NAME of a fitted RegressionLinear object in the MATLAB workspace, and RegressionLinear has no public constructor -- no parameter mapping can build that object from 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:
B0every 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 Regression Predictor — a fitted MATLAB RegressionLinear model at inference y = SUM_j Beta_j * x_j + Bias
Everything shared with Linear_Classifier_Predictor -- the config reading, the reference sum and the emitted score in ten languages -- lives in ICoreLinearModelSupport. This file is the block around it: one input, one output, two configs.
What predict applies was read out of R2026a's RegressionLinear.m and LinearImpl.m and then measured, not assumed: predict is ResponseTransform(X*Beta + Bias) and nothing else, with the transform 'none' for every fitrlinear model. Against X*Beta + Bias it came back at exactly 0 over 400 observations for both learners (svm and leastsquares), the Simulink RegressionLinear Predict block matched predict to 2.2e-16, and fitrlinear refuses a Standardize option outright -- so there is no scaling step anywhere to transcribe.
Sample results#
No stimulus produced a sampled output in this rig — Invalid model at: ICore Blocks/Home/Linear 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 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_Regression_Predictor.json