<jupyter_start><jupyter_text>COMPARISONS:<jupyter_code>def add_results(res_dict, name, labels, prediction):
                            
    results["method"].append(name)
    results["k_mae"].append(np.abs(len(np.unique(labels)))-len(np.unique(prediction)))
    results["NMI"].append(normalized_mutual_info_score(prediction.astype(int), np.array(labels),average_method='arithmetic'))
    results["ARI"].append(ari_score(np.array(labels), prediction.astype(int)))

    return res_dict

D = 2 # Dimension
K = 20 # Number of Clusters
N = 10000 #Number of points
var_scale = 100 # The variance of the MV-Normal distribution where the clusters means are sampled from.
ITERS = 400

Repeats = 10

results = {
    "method": [],
    "k_mae": [],
    "NMI": [],
    "ARI": [],
}

prior = niw(1,np.zeros(D),2,np.eye(D)*0.1)
alpha = 100.0

for i in range(Repeats):
    # generate dataset
    data, labels = DPMMPython.generate_gaussian_data(N, D, K, var_scale)
    
    # run kmeans
    kmeans = KMeans(n_clusters=K).fit(data.T)
    kmeans_labels = kmeans.labels_
    
    # run GMM
    gmm = GaussianMixture(n_components=K,covariance_type='full').fit(data.T)
    gmm_labels = gmm.predict(data.T)
    
    # sklearn DPGMM
    dpgmm = BayesianGaussianMixture(
        n_components=K, covariance_type='full', weight_concentration_prior=1e+2,
        weight_concentration_prior_type='dirichlet_process',
        mean_precision_prior=1e2, covariance_prior=1e0 * np.eye(D),
        init_params="kmeans", max_iter=ITERS, verbose=0).fit(data.T)
    dpgmm_labels = dpgmm.predict(data.T)
    
    # run DPGMM
    dpmm_rand_results = DPMMPython.fit(data,alpha, gt=labels, iterations=ITERS, burnout=5, verbose=False)[0]
    
#     if len(np.unique(dpmm_rand_results)) < int(K*0.2):
#         break
        
    # calc metrics and aggregate
    results = add_results(results, "k-means", labels, kmeans_labels)
    results = add_results(results, "EM-GMM", labels, gmm_labels)
    results = add_results(results, "DPGMM (SKlearn's)", labels, dpgmm_labels)    
    results = add_results(results, "DPGMM-Random", labels, dpmm_rand_results)
    
    print(f"Finished iteration {i}")<jupyter_output>Finished iteration 0
Finished iteration 1
Finished iteration 2
Finished iteration 3
Finished iteration 4
Finished iteration 5
Finished iteration 6
Finished iteration 7
Finished iteration 8
Finished iteration 9<jupyter_text>No user-defined prior:<jupyter_code>res_pd = pd.DataFrame().from_dict(results)
res_pd.groupby("method").agg(['mean', 'std'])<jupyter_output><empty_output><jupyter_text>With wide prior:<jupyter_code>res_pd = pd.DataFrame().from_dict(results)
res_pd.groupby("method").agg(['mean', 'std'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13035450516986707, 'fraction_numerical': 0.016617429837518464, 'mean_word_length': 4.472727272727273, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '245116', 'license': 'MIT', 'n_tokens_mistral': 1022, 'n_tokens_neox': 955, 'n_words': 173, 'path': 'DPMM Vanila Comparisons.ipynb', 'repo_name': 'wiVlad/DPMMSubClusters.jl', 'size': '2708'}