micropython-ulab icon indicating copy to clipboard operation
micropython-ulab copied to clipboard

[FEATURE REQUEST] Least Squares solver

Open furbrain opened this issue 3 years ago • 1 comments

I'd like to implement a least squares solver, similar to https://numpy.org/doc/stable/reference/generated/numpy.linalg.lstsq.html

I can do it now with the following

from ulab import numpy as np
from ulab import scipy as spy

# ... 
# generate our matrices a and b to solve, finding x where ax = b
#

q,r = np.linalg.qr(a)
x = spy.linalg.solve_triangular(r,np.dot(q.T,b))

What I'd like is a simple convenience function to access this algorithm. For context, I'm writing code to enable calibrating a magnetometer - this involves fitting a cloud of points to a rotated ellipsoid, and then fitting another cloud of points to a plane. I've got the algorithm working on my laptop using the lstsq function, but now I want to use it in an embedded device, using ulab.

furbrain avatar Nov 09 '22 13:11 furbrain

I'm not sure I follow your argument. If I understand correctly, then

q,r = np.linalg.qr(a)
x = spy.linalg.solve_triangular(r,np.dot(q.T,b))

does what you need. If that is the case, what do you mean by convenience function?

v923z avatar Nov 09 '22 20:11 v923z