\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
llsq_obj¶
View page sourceLinear Least Squares Objective¶
Function¶
\[y(x) = \frac{1}{2} \sum_{i=0}^{n-1} \left(
s_i - x_0 - x_1 t_i - x_2 t_i^2 - \cdots
\right)^2\]
where s and t in \({\bf R}^n\) are given by:
\[\begin{split}t_i & = -1 + i * 2 / (n - 1)
\\
s_i & = \mathrm{sign} ( t_i )
=
\cases{
-1 & if $t_i < 0$ \\
0 & if $t_i = 0$ \\
+1 & if $t_i > 0$
}\end{split}\]
Vector Operations¶
The calculation of this objective can be vectorized with respect to the index j above. The intent is to enable AD packages that have vector operators to use them reduce memory and speed up the calculation of derivatives.
option¶
This algorithm uses the n_arg and n_other options; see below:
n_arg¶
This is the size of the vector x above . There is an assert checking that n_arg > 0.
n_other¶
This is the size of the vector t above . There is an assert checking that n_other > 0.
Implementation¶
Derivative¶
The partial derivative of \(y(x)\) with respect to \(x_j\) is
\[\frac{ \partial y(x)} { \partial x_j }
=
- \sum_{i=0}^{n-1} \left(
s_i - x_0 - x_1 t_i - x_2 t_i^2 - \cdots
\right) t_i^j\]