Linear Transformations

Simple Linear Layer

In neural networks, linear transformations are represented as: $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 = [[2, -1], [1, 3]];  // Weight matrix W
$inputVector = [1, 2];              // Input vector x
$bias = [1, 0];                     // Bias vector b

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

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

Chart:


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

Result: Memory: 0.002 Mb Time running: < 0.001 sec.
Output after Linear Layer: [1, 7]