Generated reference › Batch Normalization — Machine Learning/Neural Networks
kind: generated#block#machine-learning-neural-networks

Batch Normalization — Machine Learning/Neural Networks

Machine_Learning/Neural_Networks/Batch_Normalization · 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.

Batch Normalization

Machine Learning / Neural Networks

Batch normalization evaluated at inference, elementwise over the input vector:

yi = (ui − meani) ÷ √(vari + ε) × gammai + betai

At training time the statistics are taken from the batch and move on every step; at inference they are frozenrunning_mean/running_var in a trained torch.nn.BatchNorm1d, moving_mean/ moving_variance in Keras – so all four arrays are constants you paste in. This block is the inference form only; it never estimates anything from the signal.

Because the four arrays are constants, the layer is exactly a per-element affine map, and the block folds it to one once per configuration: scalei = gammai ÷ √(vari + ε) and shifti = betai − meani · scalei, leaving yi = scalei·ui + shifti.

Ports

  • u – the layer input, a column [m,1]. m must equal the height of the four arrays, and it is checked rather than broadcast.
  • Outputy, the same [m,1] column: the map is elementwise, so it never changes the signal's shape.

Parameters

  • Running Meanmean, an [m,1] column, one entry per channel. layer.running_mean in PyTorch.
  • Running Variancevar, an [m,1] column of variances, not standard deviations. layer.running_var in PyTorch. Every entry must be ≥ 0.
  • Gamma – the learned scale, an [m,1] column (layer.weight). Use a column of ones for a layer trained with affine=False.
  • Beta – the learned offset, an [m,1] column (layer.bias). Use a zero column for affine=False.
  • Epsilon – the numerical guard added to the variance before the square root. Default 1e-5, matching PyTorch and Keras; it must match the value the layer was trained with, since the fold bakes it in.
  • 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 folded scale and shift are baked in as literals at full setprecision(17), so the exported layer is bit-comparable with the in-app run; there is no tunable parameter, because a trained statistic is not something to retune on the target.

The three HDL targets are ordinary Q16.16 fixed point and are offered for synthesis, unlike the rest of this family. That follows from the fold: with the square root evaluated at export time the emitted datapath is one multiply and one add per element, with no transcendental anywhere in it.

Simulink bridge

None. Simulink's Deep Learning blocks take a trained network object, not a set of arrays, and no config value can carry an object across the bridge. The bridge reports the block rather than dropping it silently, and it has no parity testbench, which is the documented consequence of Support::None rather than a gap. Code export verification still covers it across all ten languages.

Notes

  • Algebraic and stateless: the output depends only on the current input, so the layer cannot break an algebraic loop.
  • No state space, deliberately. The shift makes the map affine rather than linear, and ICoreStateSpace's feed-through y = D·u has nowhere to put it. Model reduction reports the block as unmergeable, which is the honest answer.
  • Distinct from Layer Normalization, which computes its mean and variance from the input vector on every step. Here they are frozen constants, which is why this block folds and that one cannot.

Code facts#

FactValue
registered typeMachine_Learning/Neural_Networks/Batch_Normalization
familyMachine_Learning/Neural_Networks
solver environment classICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Batch_Normalization
sourcesrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Neural_Networks/Batch_Normalization/ICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Batch_Normalization.cpp
headersrc/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Neural_Networks/Batch_Normalization/ICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Batch_Normalization.h
default size on canvas120 × 80 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
1inICoreDoubleu
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
Running Mean[0.1; -0.2; 0.05]
Running Variance[0.9; 1.4; 0.6]
Gamma[1.2; 0.8; 1.5]
Beta[0.05; -0.1; 0.3]
Epsilon0.00001

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 that could carry the frozen statistics: its Deep Learning blocks take a trained network OBJECT rather than arrays, and no config value crosses the bridge as an object. Re-create the layer on the Simulink side and paste the same running mean, running variance, gamma and beta in

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).

Batch Normalization — the INFERENCE form, folded to an affine map y_i = (u_i - mean_i) / sqrt(var_i + eps) * gamma_i + beta_i = scale_i * u_i + shift_i

All four arrays are frozen at inference, so the fold is exact and is done once per loadBlockConfig(). See the header for why that matters beyond tidiness: it is what keeps the square root out of all ten backends, and it is why this block's three HDL targets are real Q16.16 fixed point rather than the simulation-only real arithmetic the rest of the Machine_Learning family needs.

Sample results#

No stimulus produced a sampled output in this rig — Invalid input size at: ICore Blocks/Home/Batch Normalization. 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__Neural_Networks__Batch_Normalization.json