Minimal MLP in PHP: standalone example

One hidden layer and forward pass (standalone run)

A simplified one-hidden-layer MLP without bias terms: this example demonstrates only the forward pass on an input vector.

 
<?php

include 'code.php';

echo 
'Minimal MLP (forward-pass only):' PHP_EOL;
echo 
'-----------' PHP_EOL;
$mlp = new SimpleMLP(230.01);
$input = [1.00.5];
$output $mlp->forward($input);

echo 
'Input: [' implode(', 'array_map(static fn (float $v): string => (string) $v$input)) . ']' PHP_EOL;
echo 
'Hidden layer: ' '[' implode(', 'array_map(static fn (float $v): string => (string) round($v2), $mlp->getHidden())) . ']' PHP_EOL;
echo 
'Output: ' number_format($output6'.''') . PHP_EOL;
Step-by-step forward-pass visualization
See how the signal flows from inputs to hidden neurons and then to output through each neuron step by step.
x1 1.00 x2 0.50 h1 z=0.00 a=0.00 h2 z=0.00 a=0.00 h3 z=0.00 a=0.00 0.0000 w11=0.42, w12=0.85 w21=0.73, w22=0.11 w31=0.25, w32=0.64 v=[0.91, 0.37, 0.58]
zᵢ = wᵢ1 · x1 + wᵢ2 · x2 hᵢ = ReLU(zᵢ) ŷ = Σ(vᵢ · hᵢ)
Current step
-
x = [x1, x2]
[1.00, 0.50]
Hidden vector h
[0.00, 0.00, 0.00]
Output ŷ
0.0000
# Stage Value
Result: Memory: 0.008 Mb Time running: < 0.001 sec.
Minimal MLP (forward-pass only):
-----------
Input: [1, 0.5]
Hidden layer: [1.28, 0.03, 0.03]
Output: 0.143696