Simple RNN Cell — Machine Learning/Neural Networks
Machine_Learning/Neural_Networks/Simple_RNN_Cell · 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.
Simple RNN Cell
Machine Learning / Neural Networks
One recurrent step of an Elman network, evaluated at inference:
h[k] = tanh( Wx·u[k] + Wh·h[k−1] + b )
This is torch.nn.RNNCell / Keras SimpleRNNCell with
the trained weights pasted in. The hidden state is also the output, so a
single block is a complete recurrent layer: feed it a sample per step and it
carries context between them, which is what a plain Dense Layer cannot
do.
Stateful and discrete by nature. A network step advances per sample and has no derivative to integrate, so the block declares itself discrete-only and always steps at its own rate rather than being pushed through the continuous solver.
Ports
- u – the input sample, a column [m,1]. m must equal the number of COLUMNS of Input Weights, and it is checked rather than broadcast.
- Output – h, a column [n,1] where n is the number of ROWS of Input Weights: the new hidden state. The layer's width is read off Wx alone, and the block resizes its output when you change it.
Parameters
- Input Weights – Wx, an [n,m] matrix.
cell.weight_ihin PyTorch. - Recurrent Weights – Wh, an [n,n]
matrix.
cell.weight_hh. This is what makes the block recurrent; a zero matrix here reduces it to a Dense Layer with a tanh. - Bias – b, an [n,1] column. PyTorch keeps two bias
vectors (
bias_ihandbias_hh); they are only ever added together, so paste their sum. - Initial Hidden State – h[−1], an [n,1] column: where the recurrence starts, re-applied at the start of every run. Zero is the usual choice for a freshly started sequence.
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period. Being discrete-only, a non-positive value falls back to the model's global sampling time rather than to the surrounding rate.
Code export
All ten targets: Python, MATLAB, Java, Rust,
C, C++, VHDL, Verilog, SystemVerilog and
PLC Structured Text. Both weight matrices, the bias and the initial state
are baked in as literals at full setprecision(17), and each backend
carries the hidden state in its own persistent form – a struct field, a
core state member, a registered signal, a retained ST variable – seeded
with Initial Hidden State.
The three HDL targets are simulation-only: they carry the step
in real arithmetic and quantize only at the port boundary, because
tanh is transcendental and has no place in a Q16.16 datapath.
PLC Structured Text has no TANH, so it is emitted through
2 ÷ (1 + EXP(−2z)) − 1 – the same function
written in terms of EXP alone.
Simulink bridge
None. Simulink's recurrent layers live inside its Deep Learning
blocks, which take a trained network object rather than weight matrices,
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
- Stateful, so unlike every other block in this family it is not algebraic: the same input gives a different output depending on what came before. Chain it with a Dense Layer readout to build a small recurrent model.
- No state space, deliberately: tanh makes the recurrence nonlinear, so no A/B/C/D describes it and model reduction correctly refuses the block.
- The state is read before it is written. h[k] depends on every element of h[k−1], so an implementation that updated the vector in place would feed already-updated components into later rows. The generated code computes the new vector into a temporary and copies it back – except on the three HDL targets, where the state is a registered signal and pre-clock reads give this for free.
- Ten backends, one seed. The initial state written into every exported core comes from the configuration, never from wherever the in-app run had got to when you pressed export.
Code facts#
| Fact | Value |
|---|---|
| registered type | Machine_Learning/Neural_Networks/Simple_RNN_Cell |
| family | Machine_Learning/Neural_Networks |
| solver environment class | ICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Simple_RNN_Cell |
| source | src/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Neural_Networks/Simple_RNN_Cell/ICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Simple_RNN_Cell.cpp |
| header | src/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Neural_Networks/Simple_RNN_Cell/ICoreBlock_0_Machine_Learning_1_Neural_Networks_2_Simple_RNN_Cell.h |
| default size on canvas | 126 × 88 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 | u |
| 2 | out | ICoreDouble | h |
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 |
|---|---|---|
Input Weights | [0.8 -0.4 0.55; -0.3 0.7 0.15] | — |
Recurrent Weights | [0.6 -0.35; 0.25 0.5] | — |
Bias | [0.1; -0.2] | — |
Initial Hidden State | [0; 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 Simulink equivalent that could carry the weights: its recurrent layers exist only inside the Deep Learning blocks, which take a trained network OBJECT rather than weight matrices, and no config value crosses the bridge as an object
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:
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).
Simple RNN Cell — one Elman recurrent step, and this family's first STATEFUL block h[k] = tanh( Wx*u[k] + Wh*h[k-1] + b )
Read the header before this file: it records the two members (config seed vs running state) and why only one of them may ever reach a generator, and it records the split between the three HDL targets (registered state, pre-clock reads are free) and the eight immediate- assignment targets (must compute into a temporary).
The three HDL targets are SIMULATION-ONLY
real: tanh is transcendental. Same choice as Dense_Layer and Activation_Function, and stated in the description.
Sample results#
No stimulus produced a sampled output in this rig — Invalid input size at: ICore Blocks/Home/Simple RNN Cell. 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__Simple_RNN_Cell.json