4
$\begingroup$

The following question is related to research I am doing on reinforcement learning on manifolds.

I have a set of basis vectors $\boldsymbol{B} = \{\boldsymbol{b}_1,\dots,\boldsymbol{b}_k\}$ that span a $k$-dimensional linear subspace of $\mathbb{R}^n$ ($\boldsymbol{b}_i \in \mathbb{R}^n$ $\forall \ i \in \{1,\dots,k\}$ and $k<n$). The basis vectors can change. I want a map that converts the basis vectors to an orthonormal basis that spans the same subspace as the original basis vectors with the requirement that the map is smooth.

I have considered the Gram–Schmidt process, but it seems to have problems. For example, consider two basis vectors in $\mathbb{R}^2$. Imagine the first vector points in the positive x-axis direction, and the second is a rotation of the first by a small angle of + or - $\epsilon$. Depending on the sign of the rotation, I will get a second orthonormal vector pointing in the direction of the either positive or negative y-axis. Therefore, slightly changing $\boldsymbol{B}$ can lead to very different orthonormal vectors. Are there other methods that don't have problems like this?

EDIT: I am looking for a practical solution to an applied problem. It is ok to assume that the basis vectors are always linearly independent and have nonzero magnitude.

$\endgroup$
22
  • 15
    $\begingroup$ The Gram-Schmidt process is smooth (you can tell that just by looking at the formulae) - what is happening in your example is that the two bases in $\mathbb{R}^2$ provided in the second paragraph of the OP have different orientations and thus lie in two different connected components of the space of all bases in $\mathbb{R}^2$. In that case, the corresponding GS orthonormalizations will have opposite orientations as well (recall that the GS procedure preserves orientation) and thus don't need to be close to each other. The same is true for any finite-dimensional vector space. $\endgroup$ Commented Sep 24 at 17:55
  • 5
    $\begingroup$ In your example, there is no continuous path between these two bases in the space of bases of a given 2-dim space (it must go through a a spanning set of a 1-dim subspace). If you allow extra dimensions (say, rotate the plane around x-axis), it works (GS gives an ONB for each of the intermediate planes, preserving the orientation - the latter changes along the path). $\endgroup$ Commented Sep 24 at 18:48
  • 6
    $\begingroup$ Your question appears mis-formulated. You say 𝐵 is a basis and you are changing it slightly, but your $\pm \epsilon$ perturbations are not a basis when $\epsilon=0$. So it's unclear what you are looking for, as your formulation is contradicting the language you are using to discuss the problem. $\endgroup$ Commented Sep 24 at 20:03
  • 3
    $\begingroup$ Your edit seems to be superfluous. By definition, basis vectors must be linearly independent and thus are nonzero. The GS procedure always takes bases to bases, but if you pick a finite set of linearly dependent vectors (particularly, if the set contains the zero vector) the GS procedure is no longer defined there because the orthogonalization part of the GS algorithm will then necessarily produce the zero vector, which cannot be normalized. Maybe this is at the root of some of your concerns in the OP...? $\endgroup$ Commented Sep 25 at 19:48
  • 3
    $\begingroup$ Your problem sounds closer to a rounding error issue than an issue with Gram-Schmidt. For matrices that are near-degenerate, i.e. $det(A)$ small but non-zero, it can be a subtle problem to decide if $det(A)>0$ or $det(A)<0$, in part because the determinant is a high-degree polynomial so it intensifies the ambiguity. Presumably the best solution is to consider how your matrix $A$ is created, and how that process may lead it to be near-degenerate. You could then maybe fix the problem before it happens. $\endgroup$ Commented Sep 25 at 19:59

4 Answers 4

12
$\begingroup$

This is not possible as you formulate it. Consider the following two bases in $\mathbb R^3$:

\begin{gather*} (e_1,\ e_1+\epsilon\, e_2) \\ (e_1,\ e_1+\epsilon\, e_3). \end{gather*}

These are close together by your definition. However, there is no orthonormal basis of the first subspace that is close to any orthonormal basis of the second subspace (in the topology of the Stiefel manifold, or in any reasonable sense of closeness).

This is because, regardless of $\epsilon$, the first basis spans $(e_1,e_2)$ and the second basis spans $(e_1, e_3)$. These are different subspaces, corresponding to different points on the Grassmanian, and so the fibers over them in the Stiefel manifold are separated by a nonzero distance.

$\endgroup$
2
  • $\begingroup$ I think my epsilon example may have been misleading. In practice, I don't expect my vectors to be so close to each other. I expect the vectors to be sufficiently large in magnitude and for the angles between all of the vectors to be sufficiently large such that small changes in the vectors produce small changes in the subspace orientation. I'm now wondering if Gram Schmidt is fine if I assume this? Are you able to state what I would have to assume to avoid the problems I am concerned with about Gram Schmit (orthonormal basis vectors discontinuously jumping). $\endgroup$
    – Jabby
    Commented Sep 25 at 9:22
  • 2
    $\begingroup$ @Jabby If the vectors all have magnitude $\leq B$ and $\geq C$ for constants $B$ and $C$ and determinant $\geq \delta$ then Grahm-Schmidt, and every other orthonormalization procedure, will be uniform continuous in the vectors (because these conditions make the set of bases compact and compactness and continuity imply uniformly continuous). If you want more precise guarantees it may matter which procedure you choose and it depends on if you want abstract continuity or numerical stability (which I am not an expert on). $\endgroup$
    – Will Sawin
    Commented Sep 25 at 12:52
11
$\begingroup$

You want a function $f$ that assigns to each linearly independent $k$-tuple of vectors $B$ an orthonormal $k$-tuple of vectors $f(B)$ such that these span the same subspace. As others have pointed out, you cannot expect the function $f$ to be continuous at points where it is not defined. You cannot even expect it to be uniformly continuous. Think of the case when $k=1$.

On a different note, you might find that you prefer something else to Gram-Schmidt for a different reason. Write $B$ as a $k$ by $n$ matrix. The problem is, for a rank $k$ matrix $B$, to find an invertible $k$ by $k$ matrix $M$ such that the matrix $MB$ satisfies $(MB)(MB)^t=I$. Gram-Schmidt says take $M$ to be the unique lower-triangular matrix with positive diagonal entries that satisfies this. Another way is to consider the positive-definite symmetric matrix $BB^t$ and let $M$ be the inverse of the unique positive-definite symmetric matrix $A$ such that $A^2=BB^t$. I could imagine that for your application you might prefer this to G-M, either because it tends to distort the basis less in some sense or because it works for unordered bases.

$\endgroup$
2
  • $\begingroup$ I don't want to be nitpicking but is there a good reason for the sought mapping to be of the form $B \to MB$? $\endgroup$ Commented Sep 25 at 16:12
  • $\begingroup$ If two kxn matrices of rank k are such that their rows span the same k-dimensional vector space, then they must be related in this way, for a unique M. $\endgroup$ Commented Sep 25 at 23:17
8
$\begingroup$

The Gram–Schmidt process is locally smooth, i.e. there is a small neighborhood around every basis where you don't encounter the problem you mention and where the orthonromal basis from produced depends smoothly on the input data. The problem that you describe appears only when you consider it globally, as was noted in other answers and comments.

There are other algorithms for QR decomposition apart from GS based on Householder or Givens rotations and they have some advantages (numerical stability, paralellizability). The appropriate search term would be "thin QR decomposition" or "reduced QR decomposition".

Please note that QR decompositions actually produce orthogonal basis with a rather strong property: first $l$-tuples of vectors $\{q_1, \dotsc, q_l\}$ generate the same subspace as $\{b_1, \dotsc, b_l\}$ for all $l\leq k$.

The method proposed by Tom Goodwillie is sometimes called "symmetric orthogonalization" or "SVD based orthogonalization". If you consider SVD of $B = U\Sigma V^t$, then the orthogonal basis is given by rows of $UV^t$. This solution has a remarkable property that it is the nearest "orthogonal" matrix to $B$. You can find more under the name polar decomposition.

Kind of midway between these two approaches is QR decomposition with pivoting or rank revealing QR decomposition which tackles the problem of $BB^t$ having small eigenvalues (which corresponds to the basis being close to a degenerate one).

$\endgroup$
14
  • $\begingroup$ I am confused by the statement that Gram–Schmidt is only locally smooth—as you mention, the comments (for example, by @PedroLauridsenRibeiro) discuss that the problem in the statement is not a failure of smoothness, but just a manifestation of moving from one connected component of the domain to another. $\endgroup$
    – LSpice
    Commented Sep 25 at 15:16
  • 2
    $\begingroup$ Smoothness is a local property though. As others have noted, what fails is not smoothness, but uniform continuity. $\endgroup$
    – tomasz
    Commented Sep 25 at 15:33
  • 1
    $\begingroup$ @LSpice I missed that comment, sorry. Of course, smoothness is a local property. I just wanted to explain that to the OP. $\endgroup$ Commented Sep 25 at 16:15
  • 1
    $\begingroup$ I find the $UV^T$ solution very attractive. For reasons I wont go into, the right singular vectors $V$ was the solution I was originally working with, but it wasn't ideal because 1) the sign of the right singular vectors is arbitrary and so can flip, and 2) the ordering of the right singular vectors is based on the ranking of the singular values and so can also flip as the singular values change. Both of these issues, which can cause discontinuities in my basis, are resolved by using $UV^T$, as the signs and orderings of the left/right singular vectors are paired and cancel each other out. $\endgroup$
    – Jabby
    Commented Sep 25 at 16:40
  • $\begingroup$ As far as I know, SVD methods are somewhat preferred in machine learning applications, even as just part of more sophisticated methods. $\endgroup$ Commented Sep 25 at 19:43
1
$\begingroup$

I can not answer the question but maybe the following perspectives helps clarify the obstruction. Let $k \leq n$ and consider $$ \operatorname{GL}(n) \overset{\operatorname{span}}{\longrightarrow} Gr(k, n) \overset{\approx}{\longleftrightarrow} O(n) / (O(k) \times O(n - k)) \overset{\pi_{n,k}}{\longleftarrow} O(n). $$ $\operatorname{GL}(n)$ is the group of invertible matrices on $\mathbb{R}^n$, i.e. this represents your iniital bases. $\operatorname{Gr}(k, n)$ is the Grassmannian, the differentiable manifold of $k$-dimensional subspaces of $\mathbb{R}^n$. One way to construct the Grassmannian is to start with the orthogonal group $O(n)$, i.e. the orthogonal matrices on $\mathbb{R}^n$, and take the quotient by the embedding $(O(k) \times O(n - k)) \longrightarrow O(n)$ given by the matrix which applies the $O(k)$ part to the first $k$ dimensions and the $O(n - k)$ part to the remaining $n - k$ dimensions. Basically, an element of $O(n) / (O(k) \times O(n - k))$ is an equivalence classes of orthogonal matrices on $\mathbb{R}^n$ which leave invariant some $k$-dimensional subspace. What would be natural to do is to invert the projection $\pi_{n,k}$, so that $\pi_{n,k}^{-1} \circ {\approx} \circ \operatorname{span}$ gives you your desired map. Of course $\pi_{n,k}$ is not injective, so you can not invert it. But maybe one can study this map and find an atlas of natural subsets and a natural choice of $\pi_{n,k}^{-1}$ on each, somehow.

Here I don't understand well what happens so I'm guessing, but I think $O(n) / (O(k) \times O(n - k)) \overset{\pi_{n,k}}{\longleftarrow} O(n)$ is indeed a covering and therefore the universal covering space of the Grassmannian $\operatorname{Gr}(k, n)$ should give you information about the obstruction to inverting $\pi_{n,k}$. I read that the universal covering space is the "oriented Grassmannian" and it is a double cover. This would suggest that perhaps by splitting $O(n)$ into two parts (orientation). Then for each half you should be able to choose some inverse of $\pi_{n,k}$ and obtain two orthogonalization procedures, one which produces positive orientation and one which produces negative orientation bases.

$\endgroup$
2
  • 2
    $\begingroup$ The map $\pi_{n,k}$ is not a covering. $\endgroup$ Commented Sep 25 at 14:52
  • $\begingroup$ More precisely, the fibres of $\pi_{n,k}$ are diffeomorphic to $O(k)\times O(n-k)$ with the usual topology. $\endgroup$
    – David Roberts
    Commented Sep 27 at 5:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .