This is equivalent to returning the Principal Component in PCA, or the eigenvector corresponding to the largest eigenvalue in the covariance matrix. However, atan2 is much simpler! The one reference I found that uses this formula is http://web.mit.edu/18.06/www/Essays/tlsfit.pdf but that is still a much more complex derivation. It seems Pearson had already found this simple solution in 1901. http
| 250 | // found this simple solution in 1901. |
| 251 | // http://books.google.com/books?id=WXwvAQAAIAAJ&pg=PA559 |
| 252 | FCOORD LLSQ::vector_fit() const { |
| 253 | double x_var = x_variance(); |
| 254 | double y_var = y_variance(); |
| 255 | double covar = covariance(); |
| 256 | double theta = 0.5 * atan2(2.0 * covar, x_var - y_var); |
| 257 | FCOORD result(cos(theta), sin(theta)); |
| 258 | return result; |
| 259 | } |
no outgoing calls
no test coverage detected