Code Monkey home page Code Monkey logo

Comments (5)

chrispahm avatar chrispahm commented on June 19, 2024 1

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.

BertrandBev avatar BertrandBev commented on June 19, 2024

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.

chrispahm avatar chrispahm commented on June 19, 2024

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.

BertrandBev avatar BertrandBev commented on June 19, 2024

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.

BertrandBev avatar BertrandBev commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.