Comments (6)
What you want is the Schur decomposition yes?
https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix.html#method.schur
If this doesn't work and you need the classical eigen decomp then the Lapack version of the crate has:
https://docs.rs/nalgebra-lapack/latest/nalgebra_lapack/struct.Eigen.html
from nalgebra.
How can we implement this in rust though, seems a bit too complex tbh
from nalgebra.
I believe the current implementation of the Schur Decomposition uses an Arnodli iteration so it is already implemented in Nalgebra! This Schur decomposition is a generalization of the Spectral Decomposition.
I believe the Lapack implementation uses Householder transformations? The Lapack API and algorithm is well studied and documented if you want to RWIR. The Nalgebra-Lapack bindings are quite simple to use, though, and works great for integrating Rust code with existing numerical implementations.
I see that @sebcrozet added some tags to this issue, I'm wondering what kind of algorithms or enhancements you would like to see in this area? Maybe a simpler API for generalized eigen problems using the available tools?
from nalgebra.
Nalgebra already has a method to calculate the eigen values of a matrix. Why not use it to find the eigenvalues and then create the diagonal matrix corresponding and return it or there is some problem?
from nalgebra.
I would prefer a pure Rust verrsion for compatibility with Wasm. For now, I'm able to use nalgebra_lapack
but I get slightly different results between nalgebra_lapack
, ndarray-linalg
and custom code to retrieve the vectors. I'm not super familiar with the different algorithms so I'm not sure if those are just precision issues or errors.
from nalgebra.
get slightly different results between nalgebra_lapack, ndarray-linalg
This is likely a difference in implementation and probably isn't a bug, especially if the results are similar. Also note, if you have repeated eigenvalues the decomposition isn't unique, so this could be why you get different results.
There are a lot of things to consider here when choosing an API for your task. For instance, you mention that you want the entire decomposition for a non-symmetric matrix, but not all non-symmetric matrices are diagonalizable unless you allow for the complex values.
Computing eigenvectors for ill-conditioned non-symmetric matrices is a complicated task and there are many specialized algorithms and parameters built into lapack for it, see this and this from the lapack guide.
ndarray-linalg
probably uses _geev
(docs), I don't think there exists a pure rust implementation but the tools to build a naive version definitely exist in these libraries. It would be cool to try and put together an implementation in nalgebra
based off what is documented above. If anyone wants help with that I can help when I have time.
If no one has done it yet, it is likely because generalizations such as the SVD or Schur Decomposition can often be used instead and have consistent, stable, and fast algorithms. If you provide more context for your problem I might be able to suggest a way to use these existing tools instead.
If your matrices are small, do the easy thing taught in into linear by computing the eigenvalues, subtract from diagonal, and then solve for Av=0
. Using the available solve
and eigs
functions you could stay in pure rust this way, just be aware of the footguns like:
- needing complex entries
- could have multiple eigenvectors for an eigenvalue
- if you have repeated eigenvalues then the decomposition is not unique, as any orthogonal basis of the associated eigenspace are valid eigenvectors
from nalgebra.
Related Issues (20)
- Export crates used in public APIs
- unit quaternions and orthonormal matrices are only closed under successive multiplications in theory HOT 1
- Memory leak in generic_resize/reallocate_copy HOT 2
- Inverting a 4x4 matrix with `try_inverse_mut` doesn't leave `self` unchanged if the inversion fails.
- Numerically vulnerable axis calculation in Rotation3
- How to construct a symmetric matrix in nalgebra? HOT 3
- `from_iter` implementation may run indefinitely HOT 8
- Request: Allow the multiplication of matrices of matrices HOT 1
- Owned MatrixView Lifetime issues HOT 2
- GAT in Allocator Trait HOT 3
- Matrix should have `sub_scalar` and `sub_scalar_mut` methods. HOT 3
- Update to syn 2.0
- Proposal: Add helper methods `is_hermitian` and `is_unitary` for the `Matrix` struct HOT 3
- Alias 'RowDVectorView<>' is missing for the result of DMatrix<T>.row() HOT 1
- Add `map_to` just like `add_to`, and `map_assign` just like `add_assign` HOT 3
- `add_to` others `*_to` methods should be a trait and return the destination reference HOT 2
- unhandled integer overflow in matrix view construction HOT 1
- Concept for reducing the verbosity of generics
- Update user guide to include matrix, stack macros
- New stack macro implementation triggers clippy::toplevel_ref_arg warning HOT 3
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 nalgebra.