Linear Transformations

Fully Connected Layer

In a neural network, each layer applies a linear transformation followed by an activation function: $y = Wx + b$. Here, $W$ is a weight matrix, $x$ is the input, and $b$ is the bias vector.
In PHP it can be written as a class LinearTransformation with implementation of linear transformation operations.

 
<?php

// Example usage:
$weightMatrix = [[32], [-14]];  // Weight matrix W
$inputVector = [12];              // Input vector x
$bias = [1, -2];                    // Bias vector b

$linearTransform = new LinearTransformation($weightMatrix);
$resultVector $linearTransform->linearTransform($weightMatrix$bias$inputVector);

echo 
"Output after Fully Connected Layer: [<span id='output-vector'>" implode(', '$resultVector) . '</span>]';

Chart:


Weight Matrix ($W$)
Input Vector ($x$)
Bias Vector ($b$)
Output Vector ($y = Wx + b$)
8
5

Result: Memory: 0.002 Mb Time running: < 0.001 sec.
Output after Fully Connected Layer: [8, 5]