Repository navigation
v15.0 — Neuro-Fuzzy Inference (ANFIS) across every tier
v15.0 — Neuro-Fuzzy Inference (ANFIS) across every tier
tinymind gains a new model family. ANFIS — the Adaptive Neuro-Fuzzy Inference System of Jang (1993) — is a Takagi-Sugeno fuzzy system whose membership functions and rule consequents are learned from data. It sits between a rule base you hand-write and a dense net you cannot interrogate: the rules are readable back after every inference, and the whole model is a few hundred bytes.
This release ships it end to end — float, Q-format, and int8 — plus the host trainer that produces the parameters.
New architectures
-
cpp/anfis.hpp— Takagi-Sugeno ANFIS, inference only. Five feed-forward stages, no state between calls, no dynamic allocation, and a latency that does not depend on the input data. Zeroth- and first-order consequents, multiple outputs sharing one premise layer. Four membership-function policies: triangular, trapezoidal, generalized bell (compile-time exponent, so nopow()), and Gaussian (integer exp lookup table). The first three are arithmetic-only and hold atTINYMIND_ENABLE_FLOAT=0/TINYMIND_ENABLE_STD=0.Normalization and defuzzification are fused into one divide per output rather than a reciprocal per rule — both faster and markedly more accurate in a narrow Q format. The rule base is an explicit
uint8_tantecedent table rather than an implicitM^Ngrid, which is what makes offline rule pruning possible. -
cpp/qanfis.hpp— the int8 tier, behindTINYMIND_ENABLE_QUANTIZATION=1. Membership grades areuint16on a 2^-16 grid with the running product renormalized after each multiply; 8-bit grades were measured and rejected (21x worse on a bell model, 82x on a triangular one). The grade scale cancels in the fused divide, so no ANFIS-specific calibration machinery is needed for it. Consequents are quantized per rule, because a least-squares solve spans a 49,000x coefficient ratio and one shared scale annihilates the small-coefficient rules. -
cpp/upsample1d.hpp—UpsampleNearest1DandUpsampleLinear1D, the decoder-side counterpart topool1d.hpp. A cheap, checkerboard-free alternative to a transposed convolution. Nearest uses no arithmetic and holds atFLOAT=0/STD=0.
New tooling
-
apps/anfis_train— host-side trainer (numpy only). Jang's hybrid scheme: consequents solved exactly by least squares, premises descended on the gradient. Two rule-base layouts — the Cartesian grid, and a scatter partition built from Chiu subtractive clustering where the rule count follows the data rather than the input count. At three membership functions per input, eight inputs need 6561 grid rules against 14 clustered ones.Rule pruning by mean firing strength, bell and triangular membership policies with analytic gradients, multi-output training (all outputs share one pseudo-inverse), and a
ridgeparameter that matters specifically for int8.
New examples
-
examples/anfis_mackey_glass— Jang's own 1993 benchmark: predictx(t+6)of the Mackey-Glass chaotic series from four delayed samples. 16 rules, 448 bytes in Q16.16, test RMSE 0.004066 in double against 0.004081 in Q16.16 over 500 held-out samples. Reads the rule base back: rule 0 carries 18% of the output while the eight odd-numbered rules together carry under 10%.Also carries the pruning study that justifies the explicit rule table — an oversized 81-rule grid overfits by orders of magnitude, and pruning to 21 rules recovers it to 0.004793.
-
examples/anfis_mackey_glass_int8— the same model on the int8 tier, and a deliberate negative result: int8 is 9.9x larger than Q16.16 here (4428 bytes against 448), because membership functions become 256-entry lookup tables costing 512 bytes each regardless of the shape they replaced. Those tables are 92.5% of the int8 model, and int8 only overtakes Q16.16 at about 1024 rules. Accuracy holds — 0.008584 against a float reference of 0.003997 — so the int8 tier's argument here is pipeline consistency, not footprint. Documented in those terms rather than implied otherwise.
Verification
- Every
cpp/**/*.hppheader is now compiled standalone by a hard CI gate (141 self-contained, 0 not). - New CI gates for ARM cross-compilation across Cortex-M0+/M4/M33, a heap-free guarantee that
nm-asserts nomallocoroperator new, and supply-chain safety. - The ANFIS exemplars are locked byte-for-byte by
unit_test/integration, carrying raw Q16.16 integers and rule indices rather than formatted floating point so the streams hold across-O0,-g,-O3, and-ffast-math. - Adding all of this changes no existing binary. Every example whose source is unchanged since v14.0 — 38 of them — compiles to byte-identical object code, on both host x86-64 and a cross-compiled Cortex-M4, including translation units that now transitively include
qanfis.hpp.
Docs and fixes
- New architecture and example pages for ANFIS on the documentation site, plus gallery entries.
- Corrected the PINN example's description of how it computes weight gradients: it uses exact one-pass vector forward-mode (
MultiDual), not finite differences, and the feasibility page's status table no longer contradicts itself. - Corrected the KAN page to match the shipped example and its measured sizes.
- Added an int8 RNN calibration walkthrough with a footprint table and the lookup-table rationale.
- CI: apt installs are now bounded by timeouts as well as retries, so a hung package mirror degrades into a retry instead of blocking a job indefinitely.
Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/
Full changelog: v14.0...v15.0