Exemple #1
0
def analyse_psiscaling(J2, size):
    h = load_hamiltonian('J1J2', size=size, J2=J2)

    configs, indexer = h.get_config_table()
    H, e0, v0, configs = analyse_exact(h, do_printsign=False, num_eng=1)
    rand = np.random.randn(len(v0))
    func_list = [
        lambda x: x**3, lambda x: x**5, lambda x: np.sinh(x),
        lambda x: np.cosh(x)
    ]
    labels = ['x^3', 'x^5', 'sinh(x)', 'cosh(x)']

    x = np.arange(1, len(v0) + 1)
    amp = abs(v0)
    amp = np.sort(amp)[::-1]
    plt.ion()
    #plt.plot(np.log(amp))
    plt.plot(x, amp)
    for func in func_list:
        amp2 = abs(func(rand))
        amp2 = np.sort(amp2)[::-1] / np.linalg.norm(amp2)
        plt.plot(x, amp2)
    #plt.xscale('log')
    plt.legend(['$v$'] + labels)
    pdb.set_trace()
Exemple #2
0
def show_prod(J2, size):
    h = load_hamiltonian('J1J2', size=size, J2=J2)
    H = h.get_mat()
    c0, indexer = h.get_config_table()
    e0, v0 = sps.linalg.eigsh(H, which='SA', k=1)
    v0 = v0.ravel()
    order = np.argsort(abs(v0))[::-1]
    v0 = v0[order]
    c0 = c0[order]
    amp = np.abs(v0) * 100
    nn = np.sum(c0 * np.roll(c0, 1, axis=1), axis=1)
    nnn = np.sum(c0 * np.roll(c0, 2, axis=1), axis=1)
    hndim = len(c0)
    #wlist = np.linspace(0,hndim,2000)
    #nn = dos(np.arange(hndim), wlist=wlist, weights=nn, eta=2.)*hndim
    plt.ion()
    plt.plot(np.arange(hndim), amp)
    plt.fill_between(np.arange(hndim), nn, 0, alpha=0.5, color='r')
    plt.fill_between(np.arange(hndim), nnn, 0, alpha=0.5, color='g')
    plt.legend([
        '$|\psi|$', r'$\sum_iS^z_i\times S^z_{i+1}$',
        r'$\sum_iS^z_i\times S^z_{i+2}$'
    ])
    plt.axhline(0, color='#999999')
    pdb.set_trace()
    plt.savefig('notes/img/prod_J2%sN%s.png' % (J2, size), dpi=300)
Exemple #3
0
def analyse_poly(configfile, num_iter, bench_id_list):
    config = load_config(configfile)
    # folder to store data, containing config.py
    folder = os.path.dirname(configfile)
    e0 = config['hamiltonian']['EG']
    labels = [
        'polynomial', 'legendre', 'hermite', 'chebyshev', 'laguerre',
        'hermiteE'
    ]
    legends = []

    sys.path.insert(0, folder)
    from config import modifyconfig_and_getnn
    plt.ion()
    for ib, (bench_id, label) in enumerate(zip(bench_id_list, labels)):
        rbm = modifyconfig_and_getnn(config, bench_id)

        optimizer, problem = pconfig(config, rbm)
        h, sr, rbm, vmc = problem.hamiltonian, problem.sr, problem.rbm, problem.vmc
        if ib == 0:
            H, e0, v0, configs = analyse_exact(h, do_printsign=False)

        # load data
        data = np.load(folder + '/variables-%d%d.npy' % (bench_id, num_iter))
        rbm.set_variables(data)

        # compute overlap
        vec = rbm.tovec(mag=h.mag)
        vec = vec / np.linalg.norm(vec)
        overlap = abs(vec.T.conj().dot(v0))
        print('overlap = %s' % overlap)

        # show weights in conv layers.
        for layer in rbm.layers:
            if hasattr(layer, 'kernel_dict'):
                polylayer = layer
        data = polylayer.get_variables()
        plt.plot(np.real(data))
        legends.append('%s (%.4f)' % (label, overlap))
    plt.axhline(y=0, ls='--', color='k')
    plt.legend(legends)
    pdb.set_trace()
    plt.savefig('notes/img/polyweight.png')
Exemple #4
0
def analyse_polycurve(configfile,
                      num_iter,
                      bench_id_list,
                      show_var=False,
                      token=''):
    config = load_config(configfile)
    # folder to store data, containing config.py
    folder = os.path.dirname(configfile)
    e0 = config['hamiltonian']['EG']
    legends = []

    sys.path.insert(0, folder)
    from config import modifyconfig_and_getnn
    x = np.linspace(-2, 2, 200)
    plt.ion()
    for bench_id in bench_id_list:
        rbm = modifyconfig_and_getnn(config, bench_id)

        # show weights in conv layers.
        for nit in np.atleast_1d(num_iter):
            rbm_var = np.load(folder + '/variables-%d%d.npy' % (bench_id, nit))
            rbm.set_variables(rbm_var)
            for layer in rbm.layers:
                if hasattr(layer, 'kernel_dict'):
                    polylayer = layer
                    legends.append(layer.kernel + '-%d' % nit)
            if show_var:
                data = polylayer.get_variables()
                plt.plot(data.real)
            else:
                data = polylayer.forward(x)
                plt.plot(x, data.real)
    plt.legend(legends)
    #plt.ylim(-20,20)
    pdb.set_trace()
    if show_var:
        plt.savefig('notes/img/polyvar-%s.png' % token)
    else:
        plt.savefig('notes/img/polycurve-%s.png' % token)
Exemple #5
0
def scale_ed_msr(size, J2MIN=0, J2MAX=1, NJ2=51, yscale='log'):
    from qstate.classifier.rules import marshall_sign_rule
    J2L = np.linspace(J2MIN, J2MAX, NJ2)
    e0l, el = [], []
    for i, J2 in enumerate(J2L):
        h = load_hamiltonian('J1J2', size=size, J2=J2)
        H = h.get_mat()
        e0, v0 = sps.linalg.eigsh(H, which='SA', k=1)
        v0 = v0.ravel()
        configs, config_indexer = h.get_config_table()
        marshall_signs = marshall_sign_rule(configs, size=size)
        v = abs(v0) * marshall_signs
        el.append(v.T.conj().dot(H.dot(v)))
        e0l.append(e0.item())
        print('%s' % i)
    np.savetxt('notes/data/scale_msr_%s.dat' % (size, ), list(zip(el, e0l)))
    plt.ion()
    plt.plot(J2L, np.array(el) - e0l)
    plt.xlabel(r'$J_2$')
    plt.ylabel(r'$E-E_0$')
    plt.yscale(yscale)
    pdb.set_trace()