## Not to Digress but it’s Time to Regress!

“What is the best way to solve the problem?” This is of course a very context dependent question. The best depends on what you need out of your solution. Often in the embedded context best means fast, low memory and “accurate enough.” This is where regression comes into play.

## Regressions ~= Approximations

I have been doing a lot of coordinate transformation problems over the last couple of months: sine, cosine heavy operations, neither of which are efficient on my target hardware. My first thought was to use a Taylor’s series approximation (cos(x) = 1 – x^2 / 2! + x^4/4! – x^6/6!) however even with precompuation of the factorials (and leveraging the earlier powers to get the higher powers) the performance of this was too intensive.

My solution was to use a piece-wise quadratic regression. While I paid a cost in determining which region I was in, the total execution time was 1/5 the direct cosine call and 1/2 the Taylor series.

## Simple illustrations

As this last simple example shows, you don’t need the highest resolution to represent your target. Regressions need to be “good enough”. But how do you know if it is good enough?