Comments (5)
Thanks a lot Betrand, this is super helpful!
I see I have to go through some more linear algebra lectures to get back on track 😅
Also glad that you like the Observable platform! I'm a huge fan as well 😊
With respect to the original question, I still think it would be helpful (from a user perspective) to expose Eigen's own solve
methods for the decompositions though. What do you think?
Again, I'm sorry for my lack in C++ skills, because I'd just propose a PR then. But I'd need a pointer on where to start...
from eigen-js.
Hi Chris,
Thanks for the encouraging feedback!
Did you check the decomposition class?
https://bertrandbev.github.io/eigen-js/#/decompositions
It currently features LU, QR, SVD & Cholesky decompositions.
from eigen-js.
Thanks for you reply 😊
Sorry for being unclear: My goal is to solve a system of linear equations (Ax = b). I checked the decompositions classes (https://bertrandbev.github.io/eigen-js/#/decompositions), but unfortunately I do not understand how I would use them for solving for x:
const A = new eig.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
const b = new eig.Matrix([5,6,7]);
// solve Ax=b
const qr = eig.Decompositions.qr(A);
// the following fails due to the length of rows in R not being equal to the columns
// furthermore, solving for x should ideally avoid taking the inverse of anything..
// http://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html
const x = qr.R.inverse()
.matMul(qr.Q.transpose())
.matMul(b)
// for this exact purpose, Eigen decompositions export a solve method:
// x = A.colPivHouseholderQr().solve(b)
// or using SVD
// x = A.bdcSvd(ComputeThinU | ComputeThinV).solve(b)
I also made a small Observable notebook to illustrate my confusion:
https://observablehq.com/d/3c9a3e40b6804dff
I'm assuming Eigen uses (back-)substitution for solving the equation system, but I'm not sure. Therefore I'd really appreciate if you could provide a brief example of how this could be done using this library!
Sorry for my lack of knowledge, really appreciate your help!
from eigen-js.
Ok, thanks for sharing that notebook! (I didn't know Observable, it's a really nice platform!)
So solving linear systems with QR decomposition still involves an upper linear triangular system resolution, it's more straightforward to go with SVD.
When performing the SVD, eigen prunes away the zeros form the singular value vector. So you need to instantiate a singular value matrix of the correct dimension first before computing VSigma^tU^t
sigmaCross = {
const sigmaCross = new eigen.Matrix(SVD.U.cols(), SVD.V.rows());
sigmaCross.setBlock(0, 0, eigen.Matrix.diagonal(SVD.sv).inverse());
return sigmaCross.transpose();
}
I took the liberty of forking your notebook to implement that fix
https://observablehq.com/@bbev/hello-eigen-js
Let me know if it makes sense!
from eigen-js.
Yes for sure, it would be a nice addition! I'll take a look at it when I find the time
from eigen-js.
Related Issues (13)
- LU decomposition returns wrong values HOT 4
- One doubt about inverse of this case of matrix HOT 1
- LU Solve Linear Systems HOT 1
- Type declarations HOT 1
- License
- No dist HOT 5
- index.js got an error HOT 1
- Is this supposed to work on Node.js? HOT 4
- Proper way to use Garbage Collector HOT 2
- Yarn build without OSQP broken
- Interested in contributing HOT 2
- The benchmarking of inversing Matrix is with a Matrix of integer numbers or float numbers? HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eigen-js.