Per Observation Loss — Machine Learning/Incremental Learning
Machine_Learning/Incremental_Learning/Per_Observation_Loss · 3 input / 2 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++
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.
Per Observation Loss
Machine Learning / Incremental Learning
The loss of one observation under an incremental learner's current model: loss = L(f, y) once the model is warm, and −1 before, where f = z(xs)·β + b is the model's score of x, read off the bus of an Incremental Learning Fit block. xs is x standardized by the bus's Mu and Sigma, and z is the identity for a linear learner and the Fastfood expansion for a kernel one. This is Simulink's Per Observation Loss block (Statistics and Machine Learning Toolbox, Drift Detection), the signal a drift detector watches.
Ports
- mdl (
bus) – the model, from the Fit block named by Model. A bus of any other shape is refused when the model is built. - x – one observation of the P predictors, a row [1,P].
- y – its response (regression) or label (classification), [1,1].
- IsWarm (
bool) – the bus's IsWarm, passed through, [1,1]. - loss – the observation's loss, [1,1]; −1 while IsWarm is false.
Parameters
- Model – which Fit block's bus arrives: Incremental Regression Linear (the default), Incremental Regression Kernel, Incremental Classification Linear or Incremental Classification Kernel.
- Learner – the Fit block's: svm (the default) or leastsquares for regression, svm or logistic for classification. For a classifier it decides the score transform the losses act on.
- Loss Function – L, with sy the transformed score of
the true class ([−f, f] for svm, [1/(1+ef),
1/(1+e−f)] for logistic):
- squarederror (the default) – (y − f)2 (regression);
- epsiloninsensitive – max(0, |y − f| − Epsilon), Epsilon off the bus (regression, svm only);
- classiferror – 1 when the predicted label (the second class when f ≥ 0) is not y, else 0;
- binodeviance – log(1 + e−2sy);
- exponential – e−sy;
- hinge – max(0, 1 − sy);
- logit – log(1 + e−sy);
- quadratic – (1 − sy)2.
- Class Names – the two class labels, [0 1] by default; the Fit block's. Used by the classification losses.
- Num Expansion Dimensions, Kernel Scale, Feature Map S, Feature Map G, Feature Map B and Feature Map P – a kernel learner's Fastfood map, which is not on the bus: the kernel Fit block's six configs, copied. Not used for a linear model.
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
When a run is refused
A loss that does not belong to the model (a classification loss on a regression model or the reverse, or epsiloninsensitive with leastsquares, as Simulink refuses it), a learner that does not belong to the model, Class Names that are not two different numbers, an x that is not a row, a y that is not [1,1], a kernel map that does not fit P, or a bus that is not the shape the configs imply.
Code export
Six targets: Python, MATLAB, Java, Rust, C and C++, reading the bus's elements by name, writing a kernel map out feature by feature, and keeping the last valid label as state. The hardware targets (VHDL, Verilog, SystemVerilog) and PLC Structured Text carry no bus, so an export to one stops and names the block.
Simulink bridge
None. Simulink's block takes its learner as InitialLearner, the name of an incremental model object in the MATLAB workspace, rather than as dialog parameters, so there is nothing in its dialog to map these configs onto or read them back from.
Notes
- A label that is neither class name, NaN included, is scored as the last valid label seen while the model was warm (the first class before any), as Simulink's block scores it (measured): the block keeps that label as its one state.
- The loss is the model's AFTER this observation when the bus comes from a Fit block fed the same x and y, as in Simulink: the Fit block's bus has already learnt it.
- The ECOC and naive Bayes learners are not offered: Simulink's block forces classiferror on ECOC and refuses naive Bayes.
- Verified against R2026a, by the
incremental_learner_lossregression suite: behind an Incremental Learning Fit block, every loss of all four models agrees with Simulink's block within 10−11 at every step, −1 while cold included.
Code facts#
| Fact | Value |
|---|---|
| registered type | Machine_Learning/Incremental_Learning/Per_Observation_Loss |
| family | Machine_Learning/Incremental_Learning |
| solver environment class | ICoreBlock_0_Machine_Learning_1_Incremental_Learning_2_Per_Observation_Loss |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Incremental_Learning/Per_Observation_Loss/ICoreBlock_0_Machine_Learning_1_Incremental_Learning_2_Per_Observation_Loss.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Machine_Learning/Incremental_Learning/Per_Observation_Loss/ICoreBlock_0_Machine_Learning_1_Incremental_Learning_2_Per_Observation_Loss.h |
| default size on canvas | 150 × 80 px |
| ports at insert | 3 in, 2 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++ |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreBus | mdl |
| 2 | in | ICoreDouble | x |
| 3 | in | ICoreDouble | y |
| 4 | out | ICoreBool | IsWarm |
| 5 | out | ICoreDouble | loss |
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 |
|---|---|---|
Model | Incremental Regression Linear%~%Incremental Regression Ke… | — |
Learner | svm%~%leastsquares%~%logistic~~svm | — |
Loss Function | squarederror%~%epsiloninsensitive%~%classiferror%~%binode… | — |
Class Names | [0 1] | — |
Num Expansion Dimensions | ICoreIncrementalKernel::DEFAULT_EXPANSION | — |
Kernel Scale | ICoreIncrementalKernel::DEFAULT_KERNEL_SCALE | — |
Feature Map S | ICoreIncrementalKernel::DEFAULT_S | — |
Feature Map G | ICoreIncrementalKernel::DEFAULT_G | — |
Feature Map B | ICoreIncrementalKernel::DEFAULT_B | — |
Feature Map P | ICoreIncrementalKernel::DEFAULT_P | — |
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 | statsDrift/Per Observation Loss |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): no bridge: Simulink's Per Observation Loss block takes its learner as InitialLearner, the NAME of an incremental model object in the MATLAB workspace, not as dialog parameters -- there is nothing in its dialog to map the configs onto, or read them back from
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).
Per Observation Loss -- one observation's loss under an incremental learner's current model statsDrift/Per Observation Loss, MEASURED on R2026a 2026-10-03 (BLOCKS_TO_ADD_TOOLBOXES.md statsDrift, on FEATURES_TO_ADD.md BF1) behind Simulink's linear and kernel Fit blocks, twelve (learner, loss) runs, every sample within 1.8e-15:
loss = IsWarm ? L(f, y) : -1, f = z(xs) . Beta + Bias off the bus
with xs the predictors standardized by the bus's Mu and Sigma and z the kernel learner's Fastfood map (the identity for a linear learner). IsWarm is the bus's own, passed through. Regression: squarederror (y - f)^2, epsiloninsensitive max(0, |y - f| - Epsilon), Epsilon off the bus. Classification acts on the TRANSFORMED score of the true class, s_y ([-f, f] for svm, the logistic pair for logistic): binodeviance log(1 + exp(-2 s_y)), exponential exp(-s_y), hinge max(0, 1 - s_y), logit log(1 + exp(-s_y)), quadratic (1 - s_y)^2, and classiferror whether the label (the second class when f >= 0) differs from y.
A label that is neither class name, NaN included, is scored as the LAST VALID label seen while the model was warm (the first class before any): measured, so the block keeps that one number as state. Only warm steps count because Simulink scores inside a subsystem enabled by IsWarm.
Sample results#
No stimulus produced a sampled output in this rig — Incorrect bus shape reaching port: ICore Blocks/Home/Per Observation Loss/ICoreBus-In-0 requires { Beta: ICoreDouble [1x1], Bias: ICoreDouble [1x1], IsWarm: ICoreBool [1x1], CanPredict: ICoreBool [1x1], Mu: ICoreDouble [1x1], Sigma: ICoreDouble [1x1], Epsilon: ICoreDouble [1x1] }, ICore Blocks/Home/Bus Creator/ICoreBus-Out-0 carries { a: ICoreDouble [1x1], b: ICoreDouble [1x1] }. 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 9bb07c6c1 · produced by docsSample --out <folder> --blocks Incremental_Regression_Kernel_Fit Incremental_Classification_Kernel_Fit Incremental_Regression_Kernel_Predict Incremental_Classification_Kernel_Predict Per_Observation_Loss --steps 60
Sample data: docs/generated/samples/Machine_Learning__Incremental_Learning__Per_Observation_Loss.json