llsq_obj

View page source

Linear 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

cpp_llsq_obj , py_llsq_obj .

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\]