<jupyter_start><jupyter_text>sample data from a multi-view mixture model<jupyter_code># setup two view Gaussian mixture model with 10 features in each view
# 4 clusters in the first view and 5 clusters in the second view
# each cluster has an identity covariance matrix
clust_param_config = {'n_features': [10, 10],
                      'clust_mean_std': 1.5,  # controls how far apart the cluster means are
                      'cluster_std': 1,  # how noisey each cluster is
                      'random_state': 43}

# Pi has equal entries
Pi_true = np.ones((4, 5))
Pi_true = Pi_true / Pi_true.sum()

# plot Pi
sns.heatmap(Pi_true.T,  # transpose so the first view is on the rows
            annot=True, cmap='Blues', vmin=0)
plt.xlabel("First view clusters")
plt.ylabel("Second view clusters")
plt.title("True Pi matrix")


# setup each view's cluster parameters
n_view_components = Pi_true.shape
view_params = setup_rand_view_params(n_view_components,
                                     **clust_param_config)

# sample data
view_data, Y_true = sample_gmm(view_params, Pi_true, n_samples=1000, random_state=234)

# view_data is a list containing the data for each view
print(len(view_data))
print(view_data[0].shape)
print(view_data[1].shape)<jupyter_output>2
(1000, 10)
(1000, 10)<jupyter_text>Fit a MVMM<jupyter_code># setup a Gaussian mixture model for each view
base_view_models = [GaussianMixture(n_components=n_view_components[v], # specify the number of view components
                                    covariance_type='diag', reg_covar=1e-6) for v in range(2)]

# setup and fit the multi-view mixture model
mvmm = MVMM(base_view_models=base_view_models, n_init=10)
mvmm.fit(view_data)
# the MVMM class has a similar API to the single view mixture model class 
mvmm.predict_proba(view_data)
mvmm.predict(view_data)
mvmm.sample(n_samples=100)
mvmm._n_parameters()


# plot the estimated Pi matrix
Pi_est = mvmm.weights_mat_
sns.heatmap(Pi_est.T,  # transpose so the first view is on the rows
            annot=True, cmap='Blues', vmin=0)
plt.xlabel("First view clusters")
plt.ylabel("Second view clusters")
plt.title("Estimated Pi matrix")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09240622140896615, 'fraction_numerical': 0.021500457456541628, 'mean_word_length': 3.9591836734693877, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '234171', 'license': 'MIT', 'n_tokens_mistral': 763, 'n_tokens_neox': 703, 'n_words': 213, 'path': 'doc/example_notebooks/Multi-view mixture model.ipynb', 'repo_name': 'idc9/mvmm', 'size': '2186'}