Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: least_squares implementation #1550

Merged
merged 2 commits into from
Oct 29, 2024
Merged

fix: least_squares implementation #1550

merged 2 commits into from
Oct 29, 2024

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.

2 participants