<jupyter_start><jupyter_text>Discrete Mixture of PDFs<jupyter_code>%load_ext autoreload
%autoreload 2
import numpy as np
from matplotlib import pyplot as plt
import torch
from torch.distributions import Normal, Independent
from probabll.distributions import MixtureSameFamily, MixtureOfGaussians
B = 4 
K = 3
D = 1
gaussians = Normal(
    #torch.zeros([B, K, D]), torch.ones([B, K, D])
    torch.tensor(np.array([np.ones(D) * k for k in np.arange(K) - K // 2], dtype=np.float32)), 
    torch.ones([K, D]) * 0.2
)

components = Independent(gaussians, 1)
#components = gaussians
logits = torch.ones([K])
print(components.batch_shape, components.event_shape, logits.shape)
mog = MixtureSameFamily(    
    logits=logits, 
    components=components)
_ = plt.hist(mog.sample(torch.Size([1000])).numpy().flatten(), 50, density=False)     
Independent(Normal(0, 1), 0).base_dist.cdf(0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13656387665198239, 'fraction_numerical': 0.022026431718061675, 'mean_word_length': 5.141891891891892, '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': '458469', 'license': 'MIT', 'n_tokens_mistral': 347, 'n_tokens_neox': 331, 'n_words': 75, 'path': 'notebooks/MixtureSameFamily.ipynb', 'repo_name': 'EelcovdW/dists.pt', 'size': '908'}