Rotation Matrices¶
import sys, os
cwd = os.getcwd()
sys.path.insert(0, f'{cwd}/../../src')
sys.path.insert(0, f'{cwd}/../../src/itetoolbox')
import numpy as np
import ite
from sklearn.utils import check_random_state
from data.toy import entropy_marginal
from scipy import stats
%matplotlib inline
%load_ext autoreload
%autoreload 2
Random Rotation¶
d_dimensions = 2
seed = 123
A_rand = stats.special_ortho_group.rvs(dim=d_dimensions, random_state=seed)
print(A_rand.shape)
# Calculate the log determinant
np.linalg.slogdet(A_rand)[1]
Random Orthogonal Matrix¶
d_dimensions = 2
seed = 123
A_ortho = stats.ortho_group.rvs(dim=d_dimensions, random_state=seed)
A_ortho.shape
# Calculate the log determinant
np.linalg.slogdet(A_ortho)[1]
Random Unitary Matrix¶
d_dimensions = 2
seed = 123
A_unitary = stats.unitary_group.rvs(dim=d_dimensions, random_state=seed)
A_unitary.shape
# Calculate the log determinant
np.linalg.slogdet(A_unitary)[1]
Random Correlation Matrix¶
d_dimensions = 2
seed = 123
eigs = np.array([1.2, 0.8])
A_corr = stats.random_correlation.rvs(eigs=eigs, random_state=seed)
A_corr.shape
# Calculate the log determinant
np.linalg.slogdet(A_corr)[1]
PCA Transformation¶
# generate complete random matrix
n_samples = 100
d_dimensions = 2
X = np.random.rand(n_samples, d_dimensions)
from sklearn.decomposition import PCA
pca_model = PCA().fit(X)
# get components, V
V = pca_model.components_
# find log determinant transform of components
np.linalg.slogdet(V)[1]
ICA Transformation¶
# generate complete random matrix
n_samples = 100
d_dimensions = 2
X = np.random.rand(n_samples, d_dimensions)
from sklearn.decomposition import FastICA
ica_model = FastICA(whiten=True, random_state=seed).fit(X)
# get components, V
V = ica_model.components_
# find log determinant transform of components
np.linalg.slogdet(V)[1]
#!pip install picard
from picard import picard
ortho = True
seed = 123
K, W, Y = picard(X, ortho=True, random_state=123, whiten=True)
components = W @ K
print(components.shape)
X_trans = X @ components.T
# find log determinant transform of components
# np.linalg.slogdet(W @ K)[1]
X_trans.shape, components.shape, W.shape
np.linalg.slogdet(W)[1]
Can we go back??
# can we go back?
X_ori = (W @ X_trans).T
X_ori.shape