Using a QR decomposition is a very generic approach that can deliver least squares regression solutions to any function with linear parameters, no matter how complicated it is. It is therefore not surprising that it cannot compete with a very specific straight implementation (on computation time), especially not in the simple case of y:x->a+b*x
. Unfortunately Math.NET Numerics does not provide direct regression routines yet you could use instead.
However, there are still a couple things you can try for better speed:
- Use thin instead of full QR decompositon, i.e. pass
QRMethod.Thin
to theQR
method - Use our native MKL provider (much faster QR, but no longer purely managed code)
- Tweak threading, e.g. try to disable multi-threading completely (
Control.ConfigureSingleThread()
) or tweak its parameters
If the data set is very large there are also more efficient ways to build the matrix, but that's likely not very relevant beside of the QR (-> perf analysis!).