This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate orthonormal transformations
- Loading branch information
1 parent
44759b1
commit 5eaf629
Showing
3 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) 2024 Graphcore Ltd. All rights reserved. | ||
import jax.numpy as jnp | ||
import jax.numpy.linalg as jnl | ||
|
||
from mess.types import FloatNxN | ||
|
||
"""Orthonormal transformation. | ||
Evaluates the transformation matrix :math:`X` that satisfies | ||
.. math:: \mathbf{X}^T \mathbf{S} \mathbf{X} = \mathbb{I} | ||
where :math:`\mathbf{S}` is the overlap matrix of the non-orthonormal basis and | ||
:math:`\mathbb{I}` is the identity matrix. | ||
This module implements a few commonly used orthonormalisation transforms. | ||
""" | ||
|
||
|
||
def canonical(S: FloatNxN) -> FloatNxN: | ||
"""Canonical orthonormal transformation | ||
.. math:: \mathbf{X} = \mathbf{U} \mathbf{s}^{-1/2} | ||
where :math:`\mathbf{U}` and :math:`\mathbf{s}` are the eigenvectors and | ||
eigenvalues of the overlap matrix :math:`\mathbf{S}`. | ||
Args: | ||
S (FloatNxN): overlap matrix for the non-orthonormal basis. | ||
Returns: | ||
FloatNxN: canonical orthonormal transformation matrix | ||
""" | ||
s, U = jnl.eigh(S) | ||
s = jnp.diag(jnp.power(s, -0.5)) | ||
return U @ s | ||
|
||
|
||
def symmetric(S: FloatNxN) -> FloatNxN: | ||
"""Symmetric orthonormal transformation | ||
.. math:: \mathbf{X} = \mathbf{U} \mathbf{s}^{-1/2} \mathbf{U}^T | ||
where :math:`\mathbf{U}` and :math:`\mathbf{s}` are the eigenvectors and | ||
eigenvalues of the overlap matrix :math:`\mathbf{S}`. | ||
Args: | ||
S (FloatNxN): overlap matrix for the non-orthonormal basis. | ||
Returns: | ||
FloatNxN: symmetric orthonormal transformation matrix | ||
""" | ||
s, U = jnl.eigh(S) | ||
s = jnp.diag(jnp.power(s, -0.5)) | ||
return U @ s @ U.T | ||
|
||
|
||
def cholesky(S: FloatNxN) -> FloatNxN: | ||
"""Cholesky orthonormal transformation | ||
.. math:: \mathbf{X} = (\mathbf{L}^{-1})^T | ||
where :math:`\mathbf{L}` is the lower triangular matrix the satisfies the Cholesky | ||
decomposition of the overlap matrix :math:`\mathbf{S}`. | ||
Args: | ||
S (FloatNxN): overlap matrix for the non-orthonormal basis. | ||
Returns: | ||
FloatNxN: cholesky orthonormal transformation matrix | ||
""" | ||
L = jnl.cholesky(S) | ||
return jnl.inv(L).T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters