Skip to content

Conversation

@polvalente
Copy link
Contributor

The Nx.LinAlg.least_squares implementation assumed that for square matrices, it should fall back to Nx.LinAlg.solve.

However, the least squares solution is to minimize norm(Ax - b, 2), which isn't necessarily equal to solving Ax = b.
For example, if A = [[1, 2], [2, 4]] and b = [[3], [5]], Nx.LinAlg.solve will not be able to find a solution as the system doesn't have a valid solution. By going the pinv route, the minimal solution will be found.

@polvalente polvalente self-assigned this Oct 29, 2024
@polvalente
Copy link
Contributor Author

@msluszniak This might be relevant to Scholar.

@polvalente polvalente merged commit 9d73de2 into main Oct 29, 2024
8 checks passed
@polvalente polvalente deleted the pv-fix/least-squares branch October 29, 2024 17:26
josevalim pushed a commit that referenced this pull request Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants