Polynomial regression

We'll use a Clifford algebra library. Very slow.

Rationale (in French for some reason):

Le système d'équations peut s'écrire : ( a + b x i + c x i 2 = y i ) i = 1 … N {\displaystyle \left(a+bx_{i}+cx_{i}^{2}=y_{i}\right)_{i=1\ldots N}} , où on cherche ( a , b , c ) ∈ R 3 {\displaystyle (a,b,c)\in \mathbb {R} ^{3}} . On considère R N {\displaystyle \mathbb {R} ^{N}} et on répartit chaque équation sur chaque dimension:

( a + b x i + c x i 2 ) e i = y i e i {\displaystyle (a+bx_{i}+cx_{i}^{2})\mathbf {e} _{i}=y_{i}\mathbf {e} _{i}}

Posons alors :

x 0 = ∑ i = 1 N e i , x 1 = ∑ i = 1 N x i e i , x 2 = ∑ i = 1 N x i 2 e i , y = ∑ i = 1 N y i e i {\displaystyle \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}}

Le système d'équations devient : a x 0 + b x 1 + c x 2 = y {\displaystyle a\mathbf {x} _{0}+b\mathbf {x} _{1}+c\mathbf {x} _{2}=\mathbf {y} } .

D'où : a = y ∧ x 1 ∧ x 2 / ( x 0 ∧ x 1 ∧ x 2 ) b = y ∧ x 2 ∧ x 0 / ( x 1 ∧ x 2 ∧ x 0 ) c = y ∧ x 0 ∧ x 1 / ( x 2 ∧ x 0 ∧ x 1 ) {\displaystyle {\begin{aligned}a=\mathbf {y} \land \mathbf {x} _{1}\land \mathbf {x} _{2}/(\mathbf {x} _{0}\land \mathbf {x_{1}} \land \mathbf {x_{2}} )\b=\mathbf {y} \land \mathbf {x} _{2}\land \mathbf {x} _{0}/(\mathbf {x} _{1}\land \mathbf {x_{2}} \land \mathbf {x_{0}} )\c=\mathbf {y} \land \mathbf {x} _{0}\land \mathbf {x} _{1}/(\mathbf {x} _{2}\land \mathbf {x_{0}} \land \mathbf {x_{1}} )\\end{aligned}}}

use MultiVector;

constant @x1 = <0 1 2 3 4 5 6 7 8 9 10>;
constant @y = <1 6 17 34 57 86 121 162 209 262 321>;

constant $x0 = [+] @e[^@x1];
constant $x1 = [+] @x1 Z* @e;
constant $x2 = [+] @x1 »**» 2  Z* @e;

constant $y  = [+] @y Z* @e;

.say for
  $y∧$x1∧$x2/($x0∧$x1∧$x2),
  $y∧$x2∧$x0/($x1∧$x2∧$x0),
  $y∧$x0∧$x1/($x2∧$x0∧$x1);

Output:

1
2
3

Last updated

Was this helpful?