<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0"
  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
  xmlns:atom="http://www.w3.org/2005/Atom">

<channel>

<title>Математик среди биологов: заметки с тегом алгебра</title>
<link>https://antonlyakh.ru/blog/tags/algebra/</link>
<description>Я немного умею складывать, но от вычитания у меня всегда кружится голова</description>
<author>Антон Лях</author>
<language>ru</language>
<generator>E2 (v3559; Aegea)</generator>

<itunes:owner>
<itunes:name>Антон Лях</itunes:name>
<itunes:email></itunes:email>
</itunes:owner>
<itunes:subtitle>Я немного умею складывать, но от вычитания у меня всегда кружится голова</itunes:subtitle>
<itunes:image href="" />
<itunes:explicit></itunes:explicit>

<item>
<title>Сингулярное разложение матрицы на ПХП</title>
<guid isPermaLink="false">522</guid>
<link>https://antonlyakh.ru/blog/all/singulyarnoe-razlozhenie-matricy-na-php/</link>
<pubDate>Tue, 10 Jun 2025 16:04:46 +0300</pubDate>
<author>Антон Лях</author>
<comments>https://antonlyakh.ru/blog/all/singulyarnoe-razlozhenie-matricy-na-php/</comments>
<description>
&lt;p&gt;Это заметка-напоминалка о пхп-библиотеках, позволяющих найти &lt;i&gt;сингулярное разложение матрицы (SVD — singular value decomposition)&lt;/i&gt;.&lt;/p&gt;
&lt;div class="e2-text-picture"&gt;
&lt;img src="https://antonlyakh.ru/blog/pictures/svd-!.png" width="800" height="230" alt="" /&gt;
&lt;div class="e2-text-caption"&gt;Из &lt;i&gt;Bellegarda (2005) &lt;a href="https://doi.org/10.1109/MSP.2005.1511825"&gt;Latent semantic mapping&lt;/a&gt;&lt;/i&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr /&gt;
&lt;p class="foot"&gt;Наилучший вариант ↓&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="https://github.com/vladkolodka/SVD/tree/master"&gt;PHP — Singular value decomposition SVD&lt;/a&gt; Влада Колодки&lt;/b&gt;.&lt;br /&gt;
Без зависимостей. Один файл &lt;kbd&gt;svd.php&lt;/kbd&gt;.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;include &amp;quot;svd.php&amp;quot;;

// Конструирую матрицу
$matrix = [['0.00', '0.00', '0.56', '0.56'. '0.00', '0.00', '1.00'], 
           ['0.49', '0.71', '0.00', '0.00'. '0.00', '0.71', '0.00'],
           ['0.49', '0.71', '0.00', '0.00'. '0.00', '0.71', '0.00'],
           ['0.72', '0.00', '0.00', '0.00'. '1.00', '0.00', '0.00'],
           ['0.00', '0.00', '0.83', '0.83'. '0.00', '0.00', '0.00']];

// Создаю класс для работы с матрицами
$matrixClass = new Matrix;

// Вычисляю SVD
$USV = $matrixClass-&amp;gt;svd($matrix);

/*
 Получаю ассоциативный массив, в котором M = USV.
 ВНИМАНИЕ: матрица V уже транспонирована.

 $matrices['U'] = $U;
 $matrices['S'] = $S;
 $matrices['W'] = $W;
 $matrices['V'] = $this-&amp;gt;matrixTranspose($V);
 $matrices['Rank'] = $rank;
 $matrices['K'] = $k;
*/

// Восстанавливаю исходную матрицу
$input = $matrixClass-&amp;gt;matrixMultiplication($USV['U'] ,$matrixClass-&amp;gt;matrixMultiplication($USV['S'], $USV['V']));
$input = $matrixClass-&amp;gt;matrixRound($input);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;
&lt;p class="foot"&gt;Тяжеловесная библиотека ↓&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="https://github.com/markrogoyski/math-php"&gt;MathPHP&lt;/a&gt; — Powerful modern math library for PHP&lt;/b&gt;&lt;br /&gt;
Огромное число разнообразных функций. Установка через композер.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/markrogoyski/math-php?tab=readme-ov-file#linear-algebra---matrix"&gt;Полный перечень функций для работы с матрицами&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class="php"&gt;use MathPHP\LinearAlgebra\Matrix;
use MathPHP\LinearAlgebra\MatrixFactory;

// Create an m × n matrix from an array of arrays
$matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
];
$A = MatrixFactory::create($matrix);

// Basic matrix data
$array = $A-&amp;gt;getMatrix();  // Original array of arrays
$rows  = $A-&amp;gt;getM();       // number of rows
$cols  = $A-&amp;gt;getN();       // number of columns

// Matrix decompositions
// LU decomposition
$LU = $A-&amp;gt;luDecomposition();
$L  = $LU-&amp;gt;L;  // lower triangular matrix
$U  = $LU-&amp;gt;U;  // upper triangular matrix
$P  = $LU-P;   // permutation matrix

// QR decomposition
$QR = $A-&amp;gt;qrDecomposition();
$Q  = $QR-&amp;gt;Q;  // orthogonal matrix
$R  = $QR-&amp;gt;R;  // upper triangular matrix

// SVD (Singular Value Decomposition)
$SVD = $A-&amp;gt;svd();
$U   = $A-&amp;gt;U;  // m x m orthogonal matrix
$V   = $A-&amp;gt;V;  // n x n orthogonal matrix
$S   = $A-&amp;gt;S;  // m x n diagonal matrix of singular values
$D   = $A-&amp;gt;D;  // Vector of diagonal elements from S

// Crout decomposition
$LU = $A-&amp;gt;croutDecomposition();
$L  = $LU-&amp;gt;L;  // lower triangular matrix
$U  = $LU-&amp;gt;U;  // normalized upper triangular matrix

// Cholesky decomposition
$LLᵀ = $A-&amp;gt;choleskyDecomposition();
$L   = $LLᵀ-&amp;gt;L;   // lower triangular matrix
$LT  = $LLᵀ-&amp;gt;LT;  // transpose of lower triangular matrix

// Eigenvalues and eigenvectors
$eigenvalues   = $A-&amp;gt;eigenvalues();   // array of eigenvalues
$eigenvecetors = $A-&amp;gt;eigenvectors();  // Matrix of eigenvectors

// Solve a linear system of equations: Ax = b
$b = new Vector(1, 2, 3);
$x = $A-&amp;gt;solve($b);&lt;/code&gt;&lt;/pre&gt;&lt;hr /&gt;
&lt;p class="foot"&gt;Библиотека для машинного обучения ↓&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="https://php-ml.readthedocs.io/"&gt;PHP-ML&lt;/a&gt; — Machine learning library for PHP&lt;/b&gt;&lt;br /&gt;
Не по теме. Не понял, есть ли SVD.&lt;/p&gt;
</description>
</item>


</channel>
</rss>