Ejemplo n.º 1
0
    label_names=[
        r"$\mathbf{{Y}}_{{{0}}}$".format(i)
        for i in range(data_kwds["n_features"])
    ])
fig_data2.tight_layout()
fig_data2.subplots_adjust(hspace=0, wspace=0)
savefig(fig_data2, "data-colour")

gridsearch_max_latent_factors = 10
gridsearch_max_components = 20

# Do a grid search.

Jm = np.arange(1, 1 + gridsearch_max_latent_factors)
Km = np.arange(1, 1 + gridsearch_max_components)
J_grid, K_grid, converged, metrics = grid_search.grid_search(
    Jm, Km, Y, N_inits=5, mcfa_kwds=mcfa_kwds)
ll = metrics["ll"]
bic = metrics["bic"]
mml = metrics["message_length"]

idx = np.nanargmin(bic)
jm_b, km_b = Jm[idx % bic.shape[1]], Km[int(idx / bic.shape[1])]

idx = np.nanargmin(mml)
jm_m, km_m = Jm[idx % mml.shape[1]], Km[int(idx / mml.shape[1])]

J_true, K_true = (data_kwds["n_latent_factors"], data_kwds["n_components"])

print(f"BIC is lowest at J = {jm_b} and K = {km_b}")
print(f"MML is lowest at J = {jm_m} and K = {km_m}")
Ejemplo n.º 2
0
        X = X - np.nanmean(X, axis=0)

    # OK, let's do a rough grid to figure out where we are.

    #Js = np.arange(7, 12 + 1)
    ## At J = 7, K_best = 16
    #Ks = np.arange(16 - 3, 16 + 3 + 1)

    Js = np.array([10, 11, 12])
    Ks = np.array([14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25])

    N_inits = 5

    gJs, gKs, converged, meta = grid_search.grid_search(Js,
                                                        Ks,
                                                        X,
                                                        N_inits=N_inits,
                                                        mcfa_kwds=mcfa_kwds)
    mml = meta["message_length"]

    # Plot some contours.
    plot_filled_contours_kwds = dict(converged=converged,
                                     marker_function=np.nanargmin,
                                     N=100,
                                     cmap="Spectral_r")

    fig_mml = mpl_utils.plot_filled_contours(gJs,
                                             gKs,
                                             mml,
                                             colorbar_label=r"$\textrm{MML}$",
                                             **plot_filled_contours_kwds)