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.
Example of use
<?php
// Example usage:
$weightMatrix = [[3, 2], [-1, 4]]; // Weight matrix W
$inputVector = [1, 2]; // 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:
Result:
Memory: 0.002 Mb
Time running: < 0.001 sec.
Output after Fully Connected Layer: [8, 5]