a project by Yinka Vaughan
A neural network framework written from scratch in ~2,000 lines of C99. Zero dependencies — no BLAS, no PyTorch, just raw matrix math, backprop, and an SGD optimizer built by hand. Two finance applications on top: a reinforcement-learning trading agent that beats buy-and-hold, and a synthetic market data generator that preserves the statistical signatures of real returns.
Recorded terminal sessions. They autoplay when this section scrolls into view and loop. Click any demo to switch; the playback controls let you scrub or pause.
The exact same C code, compiled to WebAssembly with Emscripten and executed in a Web Worker. No server — all computation happens locally in your browser.
The other demos run with fixed defaults — their parameters aren't tunable yet.
↑ Pick a demo. Output is read-only — scroll with your mouse wheel over the terminal, or hit stop to kill a running demo.
Tensor → matrix algebra (multiply, transpose, add, hadamard) ↓ Activation → ReLU, Sigmoid, Tanh, Softmax (+ derivatives) ↓ Loss → MSE, Cross-Entropy (+ derivatives, ε-clamped) ↓ Layer → Dense layer: forward + backward, Xavier/He init ↓ Network → Sequential model — stack layers, train, predict ↓ Optimizer → SGD with momentum (per-layer velocity buffers)
Every layer is test-driven. Backpropagation is independently verified against central finite differences (dL/dw ≈ [L(w+ε) − L(w−ε)] / 2ε) — max relative error ≤ 2.3 × 10⁻⁷ across four architectures.
Sigmoid branches on sign of input. Softmax subtracts row-max before exp(). Cross-entropy clamps predictions to [ε, 1−ε]. Weights init via Xavier or He, auto-selected by activation type.
Every tensor op returns a freshly allocated tensor; ownership is explicit. Verified leak-free with AddressSanitizer on the full test suite plus all example binaries.
Plain C with -O2, no SIMD intrinsics or BLAS. 64×64 matmul: 0.22 ms (2.4 GFLOP/s). A full forward + backward + SGD step on a 16→32→1 net: 0.011 ms.
Six modules, ~2,000 lines, built bottom-up TDD over 14 commits. Every function has a test before it has an implementation.
qforge/ ├── include/ # public headers │ ├── tensor.h matrix math │ ├── activation.h ReLU, Sigmoid, Tanh, Softmax │ ├── loss.h MSE, Cross-Entropy │ ├── layer.h dense layer (forward + backward) │ ├── network.h sequential model │ └── optimizer.h SGD + momentum ├── src/ # implementations (one .c per header) ├── tests/ # 51 unit tests │ └── test_harness.h zero-dependency test framework ├── examples/ │ ├── xor.c classic AI proof-of-concept │ ├── benchmark.c performance measurement │ ├── gradient_check.c finite-difference verification │ ├── market_generator.c synthetic market data │ └── dqn_trader.c reinforcement-learning trader └── web/ # this page (asciinema + WASM build)