<jupyter_start><jupyter_text>Synthesizing a Gaussian Mixture Model (GMM) dataset Dr. <NAME>, Fremont, CA 94536Gaussian mixture models are a probabilistic model for representing normally distributed subpopulations within an overall population. Mixture models in general don't require knowing which subpopulation a data point belongs to, allowing the model to learn the subpopulations automatically. Since subpopulation assignment is not known, this constitutes a form of unsupervised learning.  Libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import random
import seaborn as sns<jupyter_output><empty_output><jupyter_text>The generating function<jupyter_code>def gen_GMM(N=1000,n_comp=3, mu=[-1,0,1],sigma=[1,1,1],mult=[1,1,1]):
    """
    Generates a Gaussian mixture model data, from a given list of Gaussian components
    N: Number of total samples (data points)
    n_comp: Number of Gaussian components
    mu: List of mean values of the Gaussian components
    sigma: List of sigma (std. dev) values of the Gaussian components
    mult: (Optional) list of multiplier for the Gaussian components
    """
    assert n_comp == len(mu), "The length of the list of mean values does not match number of Gaussian components"
    assert n_comp == len(sigma), "The length of the list of sigma values does not match number of Gaussian components"
    assert n_comp == len(mult), "The length of the list of multiplier values does not match number of Gaussian components"
    rand_samples = []
    for i in range(N):
        pivot = random.uniform(0,n_comp)
        j = int(pivot)
        rand_samples.append(mult[j]*random.gauss(mu[j],sigma[j]))
        
    return np.array(rand_samples)<jupyter_output><empty_output><jupyter_text>Testing the function including `AssertionError`<jupyter_code>gen_GMM(10)
gen_GMM(N=10,n_comp=4,mu=[1,2,0],sigma=[1,1,1,2])
gen_GMM(N=10,n_comp=4,mu=[1,2,0,-1],sigma=[1,1,2])<jupyter_output><empty_output><jupyter_text>Data and plot examples<jupyter_code>data = gen_GMM(N=100,mu=[-6,0,6])
plt.scatter(x=np.arange(100),y=data,color='k')
plt.grid(True)
plt.show()
data = gen_GMM(N=10000,mu=[-6,0,6])
sns.distplot(data,bins=50,hist_kws={'color':'blue','edgecolor':'k'},kde_kws={'lw':3,'color':'k'})
plt.show()
data = gen_GMM(N=10000,mu=[-3,0,3])
sns.distplot(data,bins=50,hist_kws={'color':'blue','edgecolor':'k'},kde_kws={'lw':3,'color':'k'})
plt.show()
data = gen_GMM(N=10000,mu=[-5,0,5],sigma=[1,2,1.5])
sns.distplot(data,bins=50,hist_kws={'color':'blue','edgecolor':'k'},kde_kws={'lw':3,'color':'k'})
plt.show()
data = gen_GMM(N=10000,mu=[-5,0,5],sigma=[1.8,0.3,1.1],mult=[0.7,1.8,1.1])
sns.distplot(data,bins=50,hist_kws={'color':'blue','edgecolor':'k'},kde_kws={'lw':3,'color':'k'})
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15406767458603313, 'fraction_numerical': 0.03995680345572354, 'mean_word_length': 6.531165311653116, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '104438', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1058, 'n_tokens_neox': 993, 'n_words': 229, 'path': 'Notebooks/GMM_generator.ipynb', 'repo_name': 'user9990/Synthetic-data-gen', 'size': '2790'}