Confidence Bounds — Control Systems/Curve Fitting
Control_Systems/Curve_Fitting/Confidence_Bounds · 1 input / 6 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.
Confidence Bounds
Control Systems / Curve Fitting
Fits a polynomial of degree N to a window of W samples taken at
configured sites, and answers the two interval questions Curve Fitting Toolbox
asks of a fit: how far each coefficient may be off (confint)
and how far the curve may be off at chosen points (predint):
f = fit(x, y, 'polyN'), ci = confint(f, level),
[pi, yhat] = predint(f, xp, level, interval, 'off')
With b the least-squares coefficients, SSE the sum of squared residuals, dfe = W − (N+1) and t the Student quantile for the level, the coefficient bounds are bj ± t·√(cj·SSE/dfe), where cj is fixed by the sites; the prediction bounds are ŷ(x) ± t·k(x)·√(SSE/dfe), with k(x) fixed by the sites and x.
Ports
- y – the window, a column [W,1]: entry i is the sample taken at the i-th value of Abscissa. A row vector is refused.
- b – the fitted coefficients, [N+1,1], in
descending powers – the order
polyNnames them p1 .. pN+1. - ci lo –
confint's first row: the lower bound of each coefficient, [N+1,1]. - ci hi –
confint's second row: the upper bound of each coefficient, [N+1,1]. - yhat – the fitted curve at each Prediction Points entry, [P,1].
- pi lo –
predint's first column: the lower bound at each prediction point, [P,1]. - pi hi –
predint's second column: the upper bound at each prediction point, [P,1].
Parameters
- Abscissa – the W sites, a vector of distinct finite numbers in
the order the window arrives in; W is from N+2 to 64. They need not be evenly
spaced. ⚠ Sites far from zero make the polynomial basis badly conditioned, as
they do for
fit, which then warns; centre them if you can. - Polynomial Degree – N, from 1 to 6. There must be more sites
than coefficients: with W = N+1 there is no residual to estimate the error from,
and
confintrefuses the fit. - Confidence Level – strictly between 0 and 1; default 0.95, MATLAB's.
- Prediction Points – the P abscissa values
predintis asked about, 1 to 16 of them. - Prediction Bounds –
predint's interval type:- Observation (the default, MATLAB's) – bounds for a NEW measurement at x: the curve's uncertainty plus the noise's.
- Functional – bounds for the curve itself at x.
- 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, each printing the same statements the simulation runs. The sites' QR factors, the coefficient factors cj, the prediction factors k(x) and t are computed when the configuration loads and written into the code as constants, so they are not tunable on the generated code.
⚠ The three HDL targets carry the square roots in simulation-only real arithmetic, quantizing only at the port boundaries.
Simulink bridge
None (Support::None). Curve Fitting Toolbox ships no
Simulink library, and confint and predint are MATLAB
functions, so there is no block to map onto; the bridge reports this block
rather than dropping it silently, and it has no parity testbench. Code export
verification still covers it across all ten languages.
Notes
- Stateless: every sample is a fresh fit of the window on the port. To fit the last W samples of one signal, build the window upstream (a Tapped Delay, for example).
- Only
predint's non-simultaneous bounds are offered ('Simultaneous','off', MATLAB's default): the simultaneous ones need an F quantile in place of t. - The factory setting – sites 0..9, degree 2, level 0.95, predicting at 4.5 and 10 – on the window [1.1 1.9 3.2 4.1 4.8 6.3 6.9 8.2 8.8 10.1] gives MATLAB's b = [−0.000757575757575697; 1.0019696969697; 1.05272727272727] and its bounds to every digit MATLAB prints.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Curve_Fitting/Confidence_Bounds |
| family | Control_Systems/Curve_Fitting |
| solver environment class | ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Confidence_Bounds |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Confidence_Bounds/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Confidence_Bounds.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Confidence_Bounds/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Confidence_Bounds.h |
| default size on canvas | 160 × 140 px |
| ports at insert | 1 in, 6 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 | y |
| 2 | out | ICoreDouble | b |
| 3 | out | ICoreDouble | ci lo |
| 4 | out | ICoreDouble | ci hi |
| 5 | out | ICoreDouble | yhat |
| 6 | out | ICoreDouble | pi lo |
| 7 | out | ICoreDouble | pi hi |
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 |
|---|---|---|
Abscissa | [0 1 2 3 4 5 6 7 8 9] | — |
Polynomial Degree | 2 | — |
Confidence Level | 0.95 | — |
Prediction Points | [4.5; 10] | — |
Prediction Bounds | Observation%~%Functional~~Observation | — |
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): Curve Fitting Toolbox ships no Simulink library, and confint and predint are MATLAB functions, so there is no block to map onto. The block is reported rather than dropped when a model crosses
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:
B0no sample under docs/generated/samples/ — nothing to cross-check (P8.1)
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).
Confidence Bounds -- confint and predint for a polynomial fit over a window at fixed sites f = fit(x, y, 'polyN'); ci = confint(f, level); [pi, yhat] = predint(f, xp, level, 'observation' | 'functional', 'off')
THE ROW'S QUESTION WAS "WHERE DOES THE COVARIANCE COME FROM?", and for a LINEAR model over FIXED sites the answer is: from the configuration.
cfitkeepsrinv= R \ eye from the QR of the fit's Jacobian -- for polyN the Vandermonde matrix [x.^N ... x 1] -- plussseanddfe; confint and predint need nothing else. With the sites configured, J, R, rinv, every sum(rinv.^2), every predint factor sqrt(1 + sum(E.^2)) and the Student quantile t are constants, and only the SSE moves with the data. So no fit block has to carry anything: this block fits the window itself, the wayfitdoes -- b = R \ (Q'y), then the residuals J*b - y and their sum of squares -- and applies confint.m's and predint.m's formulas in their order.⚠ MEASURED AGAINST R2026a over 400 random windows (degree 1..6, 3..31 sites evenly spaced, random or growing, five confidence levels, both predint interval types), every one of the six outputs against fit/confint/predint: within 2.3e-13 relative where the Vandermonde matrix is well conditioned (cond < 1e3, 249 windows), 1.3e-11 below 1e5 (106), and at worst 5.1 times cond(J)*eps everywhere -- which is what two correct least-squares solvers differ by on an ill-conditioned basis, and why a badly spaced window draws MATLAB's own conditioning warning. t is cftinv.m/cfbetainv.m's Newton, matched to R2026a within 5.9e-13 over v = 1..200 and ten levels. The emitted Python is bit-identical to the live run over 200 windows.
At the factory setting -- sites 0..9, degree 2, level 0.95, predicting at 4.5 and 10 -- the window [1.1 1.9 3.2 4.1 4.8 6.3 6.9 8.2 8.8 10.1] gives MATLAB's figures to every digit it prints: b = [-0.000757575757575697 1.0019696969697 1.05272727272727].
Only predint's NON-simultaneous bounds are offered: 'Simultaneous','on' needs an F quantile (cffinv) rather than t, and the description says so. The three HDL targets carry the square roots in
real: SIMULATION-ONLY, quantized at the ports.
Sample results#
No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.