19 votes

Robust algorithm for $2 \times 2$ SVD

See https://math.stackexchange.com/questions/861674/decompose-a-2d-arbitrary-transform-into-only-scaling-and-rotation (sorry, I would have put that in a comment but I've registered just to post this ...
user avatar
10 votes

Robust algorithm for $2 \times 2$ SVD

@Pedro Gimeno "I doubt it can be any more robust than that." Challenge accepted. I noticed the usual approach is to use trig functions like atan2. Intuitively, there shouldn't be a need to use trig ...
user avatar
10 votes
Accepted

Computational method to compute both the (log) determinant and inverse of a matrix

The LU decomposition will give you what you want with only $\tfrac{2}{3}n^3 + \mathcal{O}(n^2)$ FLOPs. The linear system is solved by solving two triangular systems. The determinant is the product ...
user avatar
8 votes

Robust algorithm for $2 \times 2$ SVD

I needed an algorithm that has little branching (hopefully CMOVs) no trigonometric function calls high numerical accuracy even with 32 bit floats We want to calculate $c_1, s_1, c_2, s_2, \sigma_1$ ...
user avatar
8 votes
Accepted

Solving $A=B+AB$ without matrix inverse

If $A$ and $B$ are real symmetric, then $A=B+AB$ if and only if the product $AB$ is also real symmetric. In turn, $AB=BA$ holds if any only if $A$ and $B$ share a common eigendecomposition. This ...
user avatar
8 votes

Rapidly determining whether or not a dense matrix is of low rank

The problem, of course, is that computing the true rank (e.g., via a QR decomposition) is not really any cheaper than computing a low-rank representation of the matrix. The best you can probably do ...
user avatar
8 votes

Rapidly determining whether or not a dense matrix is of low rank

There is a neat trick I have recently learned from this paper. You start doing rank-revealing QR, and stop after the first $k$ Householder reflections, when you have a matrix of the form $$ \begin{...
user avatar
8 votes
Accepted

Does a symmetric positive definite matrix also have $\mathbf{A} = \mathbf{L}^T\mathbf{L}$ (where $\mathbf{L}$ is a lower triangular matrix)?

Let $P$ be the anti-diagonal permutation matrix, $$P = \begin{bmatrix} & & & 1 \\ & & 1 \\ & 1 \\ 1 \end{bmatrix}$$ so that $PAP$ is the version of $A$ with rows and columns ...
user avatar
  • 3,003
8 votes
Accepted

Bareiss algorithm vs. LU-decomposition

Bareiss' algorithm is a better choice if you have to compute exactly determinants of integer matrices, as noted in the comments. When it comes to real (floating-point) or complex matrices, the main ...
user avatar
7 votes
Accepted

Clever ways to update LU factorization for ridge regression

What is the size of your $A$ matrix? Is $A$ sparse? Does $A$ have some other special structure? How many values of $\lambda$ do you want to try? Normally, you'd use the Cholesky factorization of $...
user avatar
7 votes
Accepted

Term for the typical "linear in the larger dimension, quadratic in the smaller" cost for linear algebra

The book "Introduction to Applied Linear Algebra" by Boyd and Vandenberghe has an appendix about complexity of basic operations in linear algebra and they call this case big-times-small-...
user avatar
  • 1,728
7 votes
Accepted

Cholesky for ill-conditioned/singular covariance matrices

If your covariance matrix is singular, then you really should consider why the matrix is singular and come up with a higher-level approach that avoids the singularity. However, if you insist on ...
user avatar
7 votes
Accepted

Do most statistical packages and libraries in high-level programming languages rely on LAPACK for their matrix inversion operations?

tl;dr Yes. But your question doesn't make it clear that you understand what LAPACK is about. LAPACK is both a software as well as an interface. That is, the operations that LAPACK defines are standard ...
user avatar
  • 3,091
7 votes
Accepted

Algorithm to factorize matrix whose many rows are already of upper triangular form?

I believe you can accomplish what you want efficiently using the recursive LU algorithm. In brief, recursive LU on a $M \times N$ matrix $A$ proceeds by partitioning the matrix into 4 blocks: \begin{...
user avatar
  • 876
7 votes
Accepted

Functions from Scipy, Blas, or Lapack that compute only upper triangular matrix

I think you are overestimating the overhead of computing L. There are zero extra operations needed; the only additional cost is writing to RAM some numbers that you ...
user avatar
7 votes
Accepted

Accurate Way to Calculate Matrix Powers and Matrix Exponential for Sparse Positive Semidefinite Matrices

This is a slightly modified version of my response on math.stackexchange. One standard approach to computing matrix functions times a vector $f(M)x$ or quadratic forms $x^Tf(M)x$ when $M$ is symmetric ...
user avatar
  • 186
6 votes
Accepted

What is the cost of factorization for one-dimensional sparse problems?

It may help to define $N$, the number of discretization points along a 1D edge, and relate it to $n$, the number of unknowns in the system. In 2D on a square grid of points, $n = O(N^2)$. Nested ...
user avatar
  • 2,961
6 votes
Accepted

Fastest way to solve a sparse unsymmetric system many times

Generally speaking, for many right-hand side (RHS) problems, a direct solver is a more feasible solution for several reasons: Major computations are performed during the factorization step (which is ...
user avatar
  • 8,287
6 votes
Accepted

Ways to solve $Ax=b$ for a sparse (banded) $A$ with updates

If the only non-zero entries of $A_{ij}$ have $j$ in $\{i - 1, i, i + 1\}$, then $A$ is a banded matrix with bandwidth 1. More generally, you can talk about matrices of bandwidth $k$ where $k$ is any ...
user avatar
6 votes
Accepted

Numerically find the nearest positive semi definite matrix to a symmetric matrix

After you compute $Q$ and $D$, form $D'=\max(D,0)$, and compute $A'=QD'Q^\top$, the algorithms involved in multiplying those matrices do not promise that $A'$ will be exactly $QD'Q^\top$. Most ...
user avatar
  • 11.4k
6 votes

Does a symmetric positive definite matrix also have $\mathbf{A} = \mathbf{L}^T\mathbf{L}$ (where $\mathbf{L}$ is a lower triangular matrix)?

Yes, for an SPD matrix $\mathbf A$ there are a variety of Cholesky-like decompositions, you can derive the $\mathbf A = \mathbf L^T \mathbf L$ variant by first writing down an educated/structured ...
user avatar
  • 4,286
6 votes
Accepted

Block-matrix: optimal fill-in reduction for LU factorization

Unfortunately, optimal reordering is NP-complete, so all the algorithms in this space are kinda heuristic. At first glance my instinct would be to try some variant of minimum degree, mainly because ...
user avatar
  • 4,286
6 votes
Accepted

Numerical Linear Algebra: When to use Direct methods versus iterative methods to solve a linear system - for PDEs in particular

It's a complicated question, which is why I've recorded a whole bunch of video lectures on the topic :-) Take a look at lectures 34 and following here: https://www.math.colostate.edu/~bangerth/videos....
user avatar
6 votes
Accepted

Algorithm for solving systems which are nearly symmetric/adjoint?

Let's express the matrix $A \in \mathbb{R}^{n \times n}$ with which we want to solve linear systems as $$ A = S + U V $$ where $S$ is a symmetric matrix, $U \in \mathbb{R}^{n \times r}$, and $V \in \...
user avatar
5 votes

The fast, and The Backward-Stable (left) $3\times 3$ matrix inverse

I will try to give my thought on the first question regarding fast $3\times 3$ inverse. Consider $$ A=\left[ \begin{array}{ccc} a & d & g\\ b & e & h\\ c & f & i \end{array}\...
user avatar
  • 8,287
5 votes
Accepted

Does $\log(\det(A))$ equals sum of log of diagonal elements of D in LDLT decomposition?

Yes, it is possible. By construction, the $L$ matrix is lower triangular with all its diagonal entries equal to one. Therefore, $\det(L) = \det(L^T) = 1$ and, consequently, $\det(L D L^T) = \det(L) \,...
user avatar
5 votes

Robust algorithm for $2 \times 2$ SVD

This code is based on Blinn's paper, Ellis paper, SVD lecture, and additional calculations. An algorithm is suitable for regular and singular real matrices. All previous versions works 100% as well ...
user avatar
5 votes

Supernodal vs multifrontal factorizations

The scopes of these terms are (in my opinion) somewhat different. I'd use "supernodal" as a broad term, to describe any sparse direct solver that applies sufficient intelligence during the symbolic ...
user avatar
  • 4,286
5 votes

inertia count sparse matrix with dense low-rank perturbation

Upon further examination, I do think the Woodbury identity can be used to solve this problem. With it we can write: $\left( \mathbf K - \sigma \mathbf Z \mathbf Z^T \right)^{-1} = \mathbf K^{-1} - \...
user avatar
  • 4,286
5 votes
Accepted

Why is 'scipy.sparse.linalg.spilu' less efficient than 'scipy.linalg.lu' for sparse matrix?

This particular effect is highly likely to come from parallelization. In many setups, numpy will use multiple threads for invoked BLAS/LAPACK calls. In the default setting on my laptop (Mac OS, ...
user avatar
  • 8,287

Only top scored, non community-wiki answers of a minimum length are eligible