import numpy as np from gmmmml import (gmm, visualize, utils) np.random.seed(101) import logging for i in range(10): j = 0 while True: print(i, j) j += 1 try: y, labels, target, kwds = utils.generate_data(N=1000, K=35, D=9, center_box=(-10, 10)) except: logging.exception("failed") if j > 3: raise continue else: break gmm_kwds = dict(threshold=1e-5, expected_improvement_fraction=1e-5, covariance_regularization=1e-2)
dirname = os.path.dirname(path_format) if not os.path.exists(dirname): os.makedirs(dirname, exist_ok=True) common_kwds = dict(dirichlet_concentration=100, isotropy=100, psi=0.1, scale=max_N/10) for i, (n, d, k) in enumerate(permutations): print(f"Generating data for N = {n}, D = {d}, K = {k}") draws = [] for m in range(M): try: X, meta = utils.generate_data(N=n, D=d, K=k, **common_kwds) except ValueError: print(f"Failed to generate data for N={n}, D={d}, K={k}") continue assert np.all(np.isfinite(X)) draws.append((X, meta)) if plot and m < 1: fig, ax = plt.subplots() ax.scatter(X.T[0], X.T[1], s=1) ax.set_title(f"N={n}; D={d}; K={k}")
Nu = np.unique((orders.T @ steps).flatten()) Du = np.logspace(np.log10(2), np.log10(max_D), 6).astype(int) N, D = np.meshgrid(Nu, Du) K = np.clip(np.round([np.random.uniform(2, 0.1 * n) for n in N]), 2, np.inf) path_format = "data/{K:05d}_{N:06d}_{D:01d}.data" dirname = os.path.dirname(path_format) if not os.path.exists(dirname): os.makedirs(dirname, exist_ok=True) common_kwds = dict(dirichlet_concentration=100, isotropy=10, psi=0.01) N, D, K = (ea.flatten().astype(int) for ea in (N, D, K)) for i, (n, d, k) in enumerate(zip(N, D, K)): print(f"Generating data for N = {n}, D = {d}, K = {k}") draws = [] for m in range(M): draws.append(utils.generate_data(N=n, D=d, K=k, **common_kwds)) kwds = dict(N=n, D=d, K=k) with open(path_format.format(**kwds), "wb") as fp: pickle.dump(draws, fp)