Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 3
0
def run_ed_msr(J2, nsite):
    from qstate.classifier.rules import marshall_sign_rule
    h = load_hamiltonian('J1J2', size=(nsite, ), J2=J2)
    H = h.get_mat()
    e0, v0 = sps.linalg.eigsh(H, which='SA', k=1)
    v0 = v0.ravel()
    marshall_signs = marshall_sign_rule(h.configs)
    plt.ion()
    scatter_vec_phase(v0[marshall_signs == 1], color='r')
    scatter_vec_phase(v0[marshall_signs == -1], color='b')
    plt.legend([r'$+$', r'$-$'])
    pdb.set_trace()
Exemplo n.º 4
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')
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def bcomp(self, task, subfolder, ids, extension='png'):
     '''
     Args:
         task ('err', 'e'): task
     '''
     idstr = ''.join(['%d' % i for i in ids])
     context = DShow(
         (5, 3.5),
         filename="notes/img/%sCMP-%s-%s.%s" %
         (task.upper(), subfolder, idstr,
          extension)) if extension is not '-' else contextlib.ExitStack()
     with context:
         legends = []
         for bench_id in ids:
             if task == 'err':
                 self.bverr(subfolder, bench_id, extension='-')
             elif task == 'e':
                 self.bve(subfolder, bench_id, extension='-')
             else:
                 raise
             legends.append('id = %d' % bench_id)
         plt.legend(legends)