<jupyter_start><jupyter_text>Hypergeometric sampling resembles nested hypergeometric sampling<jupyter_code>import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>simulations<jupyter_code>N = 10000
p1 = 0.1
p2 = 0.5
data = np.random.choice(['A' for i in range(1000)] + ['E'], size=N)
vals, counts = np.unique(data, return_counts=True)
counts
N_total = []
N_sequential = []
for trial in range(100000):
    N_total.append(stats.hypergeom.rvs(N, counts[-1], int(N*p1*p2)))
    temp = stats.hypergeom.rvs(N, counts[-1], int(N*p1))
    N_sequential.append(stats.hypergeom.rvs(int(N*p1), temp, int(N*p1*p2)))
N_total = []
N_sequential = []
for trial in range(100000):
    N_total.append(stats.hypergeom.rvs(N, counts[-1], int(N*p1*p2)))
    temp = stats.hypergeom.rvs(N, counts[-1], int(N*p1))
    N_sequential.append(stats.binom.rvs(temp, p2))
# N_total = []
# N_sequential = []
# for trial in range(100000):
#     N_total.append(stats.binom.rvs(N, p1*p2))
#     N_sequential.append(stats.binom.rvs(stats.binom.rvs(N, p1), p2))
print(np.array(N_total).mean(), np.array(N_sequential).mean())
print(np.array(N_total).var(), np.array(N_sequential).var())
plt.hist([N_total,N_sequential], bins=30);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17509727626459143, 'fraction_numerical': 0.04124513618677043, 'mean_word_length': 5.989130434782608, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '465523', 'license': 'MIT', 'n_tokens_mistral': 561, 'n_tokens_neox': 524, 'n_words': 83, 'path': 'analysis/simulation/legacy/simple/nested_approximation_simulation.ipynb', 'repo_name': 'yelabucsf/scrna-parameter-estimation', 'size': '1285'}