Skip to content
Quasi-Newton algorithm for joint-diagonalization
Python MATLAB Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Quasi-Newton algorithm for joint-diagonalization

Travis Codecov


This Python package contains code for fast joint-diagonalization of a set of positive definite symmetric matrices. The main function is qndiag, which takes as input a set of matrices of size (p, p), stored as a (n, p, p) array, C. It outputs a (p, p) array, B, such that the matrices B @ C[i] @ B.T (python), ie B * C(i,:,:) * B' (matlab/octave) are as diagonal as possible.

Installation of Python package

To install the package, do:

$ pip install -U

You can also simply clone it, and then do:

$ pip install -e .

To check that everything worked, the command

$ python -c 'import qndiag'

should not return any error.

Use with Python

Here is a toy example (also available at examples/

import numpy as np
from qndiag import qndiag

n, p = 10, 3
diagonals = np.random.uniform(size=(n, p))
A = np.random.randn(p, p)  # mixing matrix
C = np.array([[:, None] * A.T) for d in diagonals])  # dataset

B, _ = qndiag(C)  # use the algorithm

print(  # Should be a permutation + scale matrix

Use with Matlab or Octave

See qndiag.m and toy_example.m in the folder matlab_octave.


If you use this code please cite:

P. Ablin, J.F. Cardoso and A. Gramfort. Beyond Pham’s algorithm
for joint diagonalization. Proc. ESANN 2019.
You can’t perform that action at this time.