

def run(M=40, N=100, D_y=6, D=8, seed=42, rotate=False, maxiter=1000, debug=False, plot=True):
    '\n    Run pattern search demo for PCA.\n    '
    if (seed is not None):
        np.random.seed(seed)
    w = np.random.normal(0, 1, size=(M, 1, D_y))
    x = np.random.normal(0, 1, size=(1, N, D_y))
    f = misc.sum_product(w, x, axes_to_sum=[(- 1)])
    y = (f + np.random.normal(0, 0.2, size=(M, N)))
    Q = pca.model(M, N, D)
    mask = random.mask(M, N, p=0.5)
    y[(~ mask)] = np.nan
    Q['Y'].observe(y, mask=mask)
    Q['X'].initialize_from_random()
    Q['W'].initialize_from_random()
    Q.update(repeat=10)
    Q.save()
    Q.update(repeat=maxiter)
    if plot:
        bpplt.pyplot.plot(np.cumsum(Q.cputime), Q.L, 'k-')
    rotate.load()
    for n in range(maxiter):
        Q.pattern_search('W', 'tau', maxiter=3, collapsed=['X', 'alpha'])
        Q.update(repeat=20)
        if Q.has_converged():
            break
    if plot:
        bpplt.pyplot.plot(np.cumsum(Q.cputime), Q.L, 'r:')
        bpplt.pyplot.xlabel('CPU time (in seconds)')
        bpplt.pyplot.ylabel('VB lower bound')
        bpplt.pyplot.legend(['VB-EM', 'Pattern search'], loc='lower right')

dataset/ETHPy150Open bayespy/bayespy/bayespy/demos/pattern_search.py run/VarMisuse@281/328 `Q`->`rotate`