Polynomial regression: Difference between revisions
Content added Content deleted
(→{{header|Raku}}: fix code) |
(→{{header|Raku}}: rationale) |
||
Line 2,102: | Line 2,102: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
We'll use a Clifford algebra library. Very slow. |
We'll use a Clifford algebra library. Very slow. |
||
Rationale: |
|||
Le système d'équations peut s'écrire : |
|||
<math>\left(a + b x_i + cx_i^2 = y_i\right)_{i=1\ldots N}</math>, où on cherche <math>(a,b,c)</math>. On considère <math>\mathbb{R}^N</math> et on répartit chaque équation sur chaque dimension: |
|||
<math> (a + b x_i + cx_i^2)\mathbf{e}_i = y_i\mathbf{e}_i</math> |
|||
Posons alors : |
|||
<math> |
|||
\mathbf{x}_0 = \sum_{i=1}^N \mathbf{e}_i,\, |
|||
\mathbf{x}_1 = \sum_{i=1}^N x_i\mathbf{e}_i,\, |
|||
\mathbf{x}_2 = \sum_{i=1}^N x_i^2\mathbf{e}_i,\, |
|||
\mathbf{y} = \sum_{i=1}^N y_i\mathbf{e}_i |
|||
</math> |
|||
Le système d'équations devient : <math>a\mathbf{x}_0+b\mathbf{x}_1+c\mathbf{x}_2 = \mathbf{y}</math>. |
|||
D'où : |
|||
<math>\begin{align} |
|||
a = \mathbf{y}\and\mathbf{x}_1\and\mathbf{x}_2/(\mathbf{x}_0\and\mathbf{x_1}\and\mathbf{x_2})\\ |
|||
b = \mathbf{y}\and\mathbf{x}_2\and\mathbf{x}_0/(\mathbf{x}_1\and\mathbf{x_2}\and\mathbf{x_0})\\ |
|||
c = \mathbf{y}\and\mathbf{x}_0\and\mathbf{x}_1/(\mathbf{x}_2\and\mathbf{x_0}\and\mathbf{x_1})\\ |
|||
\end{align}</math> |
|||
<syntaxhighlight lang="raku" line>use Clifford; |
<syntaxhighlight lang="raku" line>use Clifford; |