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], [13]];  // Weight matrix W
$inputVector = [12];              // Input vector x
$bias = [10];                     // 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]