<jupyter_start><jupyter_text>Generate sources using MGGD (multivariate generalized Gaussian distribution)<jupyter_code>N = 3  # components
K = 5  # datasets
T = 100  # samples
rho = 0.7  # correlation value

# generate sources using different correlation structures
# see docstring of MGGD for further information on the input parameters
S = np.zeros((N, T, K))
for idx in range(N):
#     S[idx, :, :] = MGGD_generation(T, K, 'uniform', rho, 1)[0].T
#     S[idx, :, :] = MGGD_generation(T, K, 'ar', rho, 1)[0].T
#     S[idx, :, :] = MGGD_generation(T, K, 'two_rho',
#                         {'val': np.array([0.5, 0.8]), 'idx': np.array([0, 2, 3, 4])}, 1)[0].T
#     S[idx, :, :] = MGGD_generation(T, K, 'q_qt', rho, 1)[0].T
#     S[idx, :, :] = MGGD_generation(T, K, 'rho_list', np.array([0.8, 0.7, 0.6, 0.8]), 1)[0].T
    S[idx, :, :] = MGGD_generation(T, K, 'block', {'val': 0.3, 'blocks': [(rho, 0, 2), (rho, 2,4)]}, 1)[0].T
    
# plot true SCV covariance matrices
cov = calculate_cov(S)
plot_scv_covs(cov, n_cols=3)<jupyter_output><empty_output><jupyter_text>Generate observations<jupyter_code># observations X are generated by a linear mixing of the sources S and randomly generated mixing matrices A
A = np.random.randn(N,N,K)
X = np.einsum('MNK, NTK -> MTK', A, S)

# plot covariance matrices of observed data
x_cov = calculate_cov(X)
plot_scv_covs(x_cov, n_cols=3)<jupyter_output><empty_output><jupyter_text>Apply IVA-G<jupyter_code># find most consistent of 50 runs
iva_results = consistent_iva(X, which_iva='iva_g', n_runs=50)<jupyter_output>100%|██████████████████████████████████████████████████████████████████████████████████| 50/50 [00:08<00:00,  6.06it/s]
c:\users\isi\documents\research\iva\independent_vector_analysis\independent_vector_analysis\consistent_iva.py:163: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
  A_hat[:, :, k] = np.linalg.lstsq(S[:, :, k].T, X[:, :, k].T)[0].T<jupyter_text>Plot IVA-G results<jupyter_code>plt.figure()
plt.hist(iva_results['cross_isi'])
plt.title('Distribution of cross ISI of 50 runs. \n'
          'Run with smallest cross ISI is most consistent.')
plt.figure()
plt.plot(iva_results['W_change'])
plt.title('Convergence / Change in W of the most consistent run')
plt.show()

# plot covariance matrices of estimated sources
print('Estimated SCV covariance matrices of the most consistent run:')
plot_scv_covs(iva_results['scv_cov'], n_cols=3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18140929535232383, 'fraction_numerical': 0.027361319340329836, 'mean_word_length': 5.135632183908046, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '517524', 'license': 'MIT', 'n_tokens_mistral': 1114, 'n_tokens_neox': 996, 'n_words': 258, 'path': 'notebooks/Example.ipynb', 'repo_name': 'SSTGroup/independent_vector_analysis', 'size': '2668'}