<jupyter_start><jupyter_text>Univariate tests<jupyter_code># Generate data
rng = 20201124
np.random.seed(rng)
n = 200
norm1 = np.random.normal(loc=-4.0, scale=1.0, size=int(n/2))
norm2 = np.random.normal(loc=+4.0, scale=1.0, size=int(n/2))
data_uni = np.concatenate((norm1, norm2))
np.savetxt("../resources/csv/in/data_uni.csv", data_uni, fmt='%1.5f')
# Generate grid
grid_uni = np.arange(-10, +10, 0.1)
np.savetxt("../resources/csv/in/grid_uni.csv", grid_uni, fmt='%1.5f')
# True density of data
true_pdf = 0.5 * stats.norm.pdf(grid_uni, -4.0, 1.0) + \
           0.5 * stats.norm.pdf(grid_uni, +4.0, 1.0)
# Iterations to plot the density of
iters = [0, 10, 100, 500, 898]<jupyter_output><empty_output><jupyter_text>Fixed values hyperprior<jupyter_code># Run the executable
cmd = ["../build/run",
    "Neal8", str(rng), "1", "6000", "5000",
    "NNIG", "../resources/asciipb/nnig_ngg_prior.asciipb",
    "DP", "../resources/asciipb/dp_gamma_prior.asciipb",
    "",
    "../resources/csv/in/data_uni.csv", "../resources/csv/in/grid_uni.csv",
    "../resources/csv/out/uf_dens.csv", "../resources/csv/out/uf_mass.csv",
    "../resources/csv/out/uf_nclu.csv", "../resources/csv/out/uf_clus.csv"
]
subprocess.run(cmd, capture_output=True)
fig = plt.figure(figsize=(21,7))

# Densities
matr = np.genfromtxt("../resources/csv/out/uf_dens.csv", delimiter=',')
ax1 = fig.add_subplot(131)
for it in iters:
    ax1.plot(grid_uni, np.exp(matr[it, :]), linewidth=0.5)
ax1.plot(grid_uni, np.exp(np.mean(matr, axis=0)), linewidth=1.0,
         linestyle='--', color="black")

ax1.plot(grid_uni, true_pdf, linewidth=1.0, color="red")
ax1.legend(iters + ["mean", "true"])
ax1.set_title("Univariate densities")

# Total masses
masses = np.genfromtxt("../resources/csv/out/uf_mass.csv", delimiter='\n')
ax2 = fig.add_subplot(132)
ax2.plot(masses)
ax2.set_title("Total masses over iterations")

# Number of clusters
num_clust = np.genfromtxt("../resources/csv/out/uf_nclu.csv", delimiter='\n')
ax3 = fig.add_subplot(133)
ax3.vlines(np.arange(len(num_clust)), num_clust - 0.3, num_clust + 0.3)
ax3.set_title("Number of clusters over iterations")

fig.show()<jupyter_output><empty_output><jupyter_text>NGG hyperprior<jupyter_code># Run the executable
cmd = ["../build/run",
    "Neal2", str(rng), "0", "7000", "5000",
    "NNIG", "../resources/asciipb/nnig_ngg_prior.asciipb",
    "DP", "../resources/asciipb/dp_gamma_prior.asciipb",
    "",
    "../resources/csv/in/data_uni.csv", "../resources/csv/in/grid_uni.csv",
    "../resources/csv/out/un_dens.csv", "../resources/csv/out/un_mass.csv",
    "../resources/csv/out/un_nclu.csv", "../resources/csv/out/un_clus.csv"
]
subprocess.run(cmd, capture_output=True)
matr.shape
fig = plt.figure(figsize=(21,7))

# Densities
matr = np.genfromtxt("../resources/csv/out/un_dens.csv", delimiter=',')
ax1 = fig.add_subplot(131)
for it in iters:
    ax1.plot(grid_uni, np.exp(matr[it, :]), linewidth=0.5)
ax1.plot(grid_uni, np.exp(np.mean(matr, axis=0)), linewidth=1.0,
         linestyle='--', color="black")

ax1.plot(grid_uni, true_pdf, linewidth=1.0, color="red")
ax1.legend(iters + ["mean", "true"])
ax1.set_title("Univariate densities")

# Total masses
masses = np.genfromtxt("../resources/csv/out/un_mass.csv", delimiter='\n')
ax2 = fig.add_subplot(132)
ax2.plot(masses)
ax2.set_title("Total masses over iterations")

# Number of clusters
num_clust = np.genfromtxt("../resources/csv/out/un_nclu.csv", delimiter='\n')
ax3 = fig.add_subplot(133)
ax3.plot(num_clust)
ax3.set_title("Number of clusters over iterations")

fig.show()<jupyter_output><empty_output><jupyter_text>Multivariate tests<jupyter_code># Generate data
rng = 20201124
np.random.seed(rng)
n = 60
data_multi = np.zeros((n,2))
n2 = size=int(n/2)
data_multi[0:n2,0] = np.random.normal(loc=-3.0, scale=1.0, size=n2)
data_multi[0:n2,1] = np.random.normal(loc=-2.0, scale=1.0, size=n2)
data_multi[n2:n,0] = np.random.normal(loc=+3.0, scale=1.0, size=n2)
data_multi[n2:n,1] = np.random.normal(loc=+2.0, scale=1.0, size=n2)
np.savetxt("../resources/csv/in/data_multi.csv", data_multi, fmt='%1.5f')
# Generate grid
xx = np.arange(-7.0, +7.1, 0.5)
yy = np.arange(-6.0, +5.1, 0.5)
grid_multi = np.array(np.meshgrid(xx, yy)).T.reshape(-1, 2)
np.savetxt("../resources/csv/in/grid_multi.csv", grid_multi, fmt='%1.5f')<jupyter_output><empty_output><jupyter_text>Fixed values hyperprior<jupyter_code># Run the executable
cmd = ["../build/run",
    "N8", str(rng), "0", "1000", "100",
    "NNW", "../resources/asciipb/nnw_fixed_prior.asciipb",
    "DP", "../resources/asciipb/dp_gamma_prior.asciipb",
    "",
    "../resources/csv/in/data_multi.csv", "../resources/csv/in/grid_multi.csv",
    "../resources/csv/out/mf_dens.csv", "../resources/csv/out/mf_mass.csv",
    "../resources/csv/out/mf_nclu.csv", "../resources/csv/out/mf_clus.csv"
]
subprocess.run(cmd, capture_output=True)
fig = plt.figure(figsize=(21,7))

# Density
matr = np.genfromtxt("../resources/csv/out/mf_dens.csv", delimiter=',')
ax1 = fig.add_subplot(131, projection='3d')
ax1.scatter(grid_multi[:,0], grid_multi[:,1], np.exp(np.mean(matr, axis=1)))
ax1.set_title("Mean multivariate density")

# Total masses
masses = np.genfromtxt("../resources/csv/out/mf_mass.csv", delimiter='\n')
ax2 = fig.add_subplot(132)
ax2.plot(masses)
ax2.set_title("Total masses over iterations")

# Number of clusters
num_clust = np.genfromtxt("../resources/csv/out/mf_nclu.csv", delimiter='\n')
ax3 = fig.add_subplot(133)
ax3.plot(num_clust)
ax3.set_title("Number of clusters over iterations")

fig.show()<jupyter_output><empty_output><jupyter_text>NGIW hyperprior<jupyter_code># Run the executable
cmd = ["../build/run",
    "N8", str(rng), "0", "1000", "100",
    "NNW", "../resources/asciipb/nnw_ngiw_prior.asciipb",
    "DP", "../resources/asciipb/dp_gamma_prior.asciipb",
    "",
    "../resources/csv/in/data_multi.csv", "../resources/csv/in/grid_multi.csv",
    "../resources/csv/out/mn_dens.csv", "../resources/csv/out/mn_mass.csv",
    "../resources/csv/out/mn_nclu.csv", "../resources/csv/out/mn_clus.csv"
]
subprocess.run(cmd, capture_output=True)
fig = plt.figure(figsize=(21,7))

# Density
matr = np.genfromtxt("../resources/csv/out/mn_dens.csv", delimiter=',')
mean_dens = np.exp(np.mean(matr, axis=1)).reshape(-1, 1)
plot_data = pd.DataFrame(np.hstack([grid_multi, mean_dens]), 
                         columns=["x", "y", "z"])
Z = plot_data.pivot_table(index='x', columns='y', values='z').T.values
X_unique = np.sort(plot_data.x.unique())
Y_unique = np.sort(plot_data.y.unique())
X, Y = np.meshgrid(X_unique, Y_unique)
ax1 = fig.add_subplot(131) #, projection='3d')
ax1.contour(X, Y, Z)
ax1.set_title("Mean multivariate density")

# Total masses
masses = np.genfromtxt("../resources/csv/out/mn_mass.csv", delimiter='\n')
ax2 = fig.add_subplot(132)
ax2.plot(masses)
ax2.set_title("Total masses over iterations")

# Number of clusters
num_clust = np.genfromtxt("../resources/csv/out/mn_nclu.csv", delimiter='\n')
ax3 = fig.add_subplot(133)
ax3.vlines(np.arange(len(num_clust)), num_clust - 0.3, num_clust + 0.3)
ax3.set_title("Number of clusters over iterations")

fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20579588408231836, 'fraction_numerical': 0.03891922161556769, 'mean_word_length': 4.710631494804157, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '415056', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 3093, 'n_tokens_neox': 2977, 'n_words': 429, 'path': 'python/plot.ipynb', 'repo_name': 'ricardaxel/bayesmix', 'size': '7143'}