<jupyter_start><jupyter_text>Mixture of GaussiansThis is a simple concept - we create a mixture of Gaussians as a weighted sum of a set of Gaussians:$$p(x) = \sum\limits_{k=1}^N w_k \mathcal{N}(\mu_k, \sigma_k^2)$$with the constraint that the weights are all positive and sum to one: $\sum\limits_{k=1}^N w_k=1$.Here is some code to visualize this for 1D Gaussians<jupyter_code>%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm

def plot_mog(gaussians, weights):
    ys = []
    
    # find range for x
    min_x, max_x = 1e308, -1e308
    for g in gaussians:
        min_x = min(min_x, norm.ppf(.001, g[0], g[1]))
        max_x = max(max_x, norm.ppf(.999, g[0], g[1]))
        
    xs = np.linspace(min_x, max_x, 500)
    ys = np.zeros(len(xs))
    for g, w in zip(gaussians, weights):
        ys += w * norm.pdf(xs, loc=g[0], scale=g[1])
        
    plt.plot(xs, ys)

gaussians = [[1, 1.5], 
             [5, 1],
             [8, .8]]

weights = [.3, .3, .4]

plot_mog(gaussians, weights)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14098972922502334, 'fraction_numerical': 0.035480859010270774, 'mean_word_length': 2.9703703703703703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '264730', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 451, 'n_tokens_neox': 420, 'n_words': 120, 'path': 'Mixture_of_Gaussians.ipynb', 'repo_name': 'ngocfam/Bayses-tutorials', 'size': '1071'}