コード例 #1
0
def mean_u_err(ww, ff, N, method, golden_u):
    toterr = 0.0
    numseeds = 0
    for seed in seeds:
        t_u_cv_s_method = readandcompute.t_u_cv_s(ww, ff, N, method, seed)
        if t_u_cv_s_method != None:
            du = abs((t_u_cv_s_method[1] -
                      golden_u)[t_u_cv_s_method[0] > Tmax]).max()
            lw = 0.01
            if seed == 0:
                plt.plot(t_u_cv_s_method[0],
                         (t_u_cv_s_method[1] - golden_u) / N,
                         styles.plot(method),
                         label=styles.title(method),
                         linewidth=lw)
            else:
                plt.plot(t_u_cv_s_method[0],
                         (t_u_cv_s_method[1] - golden_u) / N,
                         styles.plot(method),
                         linewidth=lw)
            toterr += du
            numseeds += 1
    if numseeds > 0:
        return toterr / numseeds / N
    return None
コード例 #2
0
ファイル: plot-errors.py プロジェクト: droundy/deft
def mean_u_err(ww, ff, N, method, golden_u):
    toterr = 0.0
    numseeds = 0
    for seed in seeds:
        t_u_cv_s_method = readandcompute.T_u_cv_s_minT(ww, ff, N, method, seed)
        if t_u_cv_s_method != None:
            du = abs((t_u_cv_s_method[1]-golden_u)[t_u_cv_s_method[0] > Tmax]).max()
            lw = 0.01
            if seed == 0:
                plt.plot(t_u_cv_s_method[0], (t_u_cv_s_method[1]-golden_u)/N,
                         styles.plot(method), label=styles.title(method), linewidth=lw)
            else:
                plt.plot(t_u_cv_s_method[0], (t_u_cv_s_method[1]-golden_u)/N,
                         styles.plot(method), linewidth=lw)
            toterr += du
            numseeds += 1
    if numseeds > 0:
        return toterr/numseeds/N
    return None
コード例 #3
0
ファイル: plot-scaling.py プロジェクト: droundy/deft
    wildfilename = "data/s%03d/periodic-ww%04.2f-ff%04.2f-N%d-%s-%%s.dat" \
                   % (seed, ww, ff, N, method)

    with open(filename, 'r') as content_file:
        content = content_file.read()
    init_iters[method].append(int(initialization_iters_regex.findall(content)[0]))

    E_data = numpy.loadtxt(wildfilename % 'E', ndmin=2)
    Emins[method].append(E_data[:, 0].max())

    sample_data = numpy.loadtxt(wildfilename % 'ps', ndmin=2)
    samples[method].append(sample_data[len(sample_data[:,1])-1, 1])

  plt.figure('iters')
  plt.semilogy(all_Ns, init_iters[method], styles.color(method)+'.-',
               label=styles.title(method))
  plt.figure('emin')
  plt.plot(all_Ns, Emins[method],styles.color(method)+'.-', label=styles.title(method))

plt.figure('iters')
plt.xlabel('$N$')
plt.ylabel('Initialization iterations')
plt.legend(loc='best').get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-scaling.pdf" % (ww*100, ff*100))

plt.figure('emin')
plt.xlabel('$N$')
plt.ylabel('Emin')
plt.legend(loc='best').get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
コード例 #4
0
ff = float(sys.argv[2])
#arg ff = [0.1, 0.2, 0.3, 0.4]

N = int(sys.argv[3])
#arg N = range(5,21)+[100, 200, 1000]

methods = eval(sys.argv[4])
#arg methods = [["nw","kT0.4","kT0.5","wang_landau","simple_flat","tmmc","oetmmc"]]

seed = int(sys.argv[5])
#arg seed = [0]

# input: ["data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat" % (seed, ww, ff, N, version) for version in methods]

plt.title('Energy histogram for $\lambda=%g$, $\eta=%g$, and $N=%i$' %
          (ww, ff, N))

for version in methods:
    data = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat" %
                         (seed, ww, ff, N, version))
    energy = -data[:, 0] / N
    DS = data[:, 1]
    plt.semilogy(energy, DS, styles.dots(version), label=styles.title(version))

plt.xlabel('$U/N\epsilon$')
plt.ylabel('$H$')
plt.legend(loc='best').get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-N%i-E.pdf" %
            (ww * 100, ff * 100, N))
コード例 #5
0
ファイル: plot-scaling.py プロジェクト: yyfdemajia/deft
        with open(filename, 'r') as content_file:
            content = content_file.read()
        init_iters[method].append(
            int(initialization_iters_regex.findall(content)[0]))

        E_data = numpy.loadtxt(wildfilename % 'E', ndmin=2)
        Emins[method].append(E_data[:, 0].max())

        sample_data = numpy.loadtxt(wildfilename % 'ps', ndmin=2)
        samples[method].append(sample_data[len(sample_data[:, 1]) - 1, 1])

    plt.figure('iters')
    plt.semilogy(all_Ns,
                 init_iters[method],
                 styles.color(method) + '.-',
                 label=styles.title(method))
    plt.figure('emin')
    plt.plot(all_Ns,
             Emins[method],
             styles.color(method) + '.-',
             label=styles.title(method))

plt.figure('iters')
plt.xlabel('$N$')
plt.ylabel('Initialization iterations')
plt.legend(loc='best').get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-scaling.pdf" %
            (ww * 100, ff * 100))

plt.figure('emin')
コード例 #6
0
        if reference_error == None:
            continue
        print '    ', reference, reference_error
        for method in methods:
            plt.figure(2)
            method_err = mean_u_err(ww, ff, N, method, golden_u)
            if method_err != None:
                print '    ', method, method_err
                plt.figure(1)
                if method not in labels_added:
                    plt.loglog(reference_error,
                               method_err,
                               styles.dots(method),
                               markerfacecolor='none',
                               markeredgecolor=styles.color(method),
                               label=styles.title(method))
                    labels_added |= set([method])
                else:
                    plt.loglog(reference_error,
                               method_err,
                               styles.dots(method),
                               markerfacecolor='none',
                               markeredgecolor=styles.color(method))
                plt.figure(2)
        plt.figure(2)
        plt.legend(loc='best')
        plt.savefig('figs/energy-for-debugging-ww%04.2f-ff%04.2f-N%i.pdf' %
                    (ww, ff, N))

min_T = 0.2  # FIXME maybe shouldn't hardcode this?
コード例 #7
0
ファイル: plot-convergence.py プロジェクト: droundy/deft
    e_hist = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-conv_T%g-E.dat"
                           % (seed, ww, ff, N, method, min_T), ndmin=2)
    lnw_hist = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-conv_T%g-lnw.dat"
                             % (seed, ww, ff, N, method, min_T), ndmin=2)

    energy = -e_hist[:,0] # array of energies
    lnw = lnw_hist[e_hist[:,0].astype(int),1] # look up the lnw for each actual energy
    ln_dos = numpy.log(e_hist[:,1]) - lnw

    log10w = lnw_hist[e_hist[:,0].astype(int),1]*numpy.log10(numpy.exp(1))
    log10_dos = numpy.log10(e_hist[:,1]) - log10w
    log10_dos -= log10_dos.max()
    if log10_dos.min() < minlog:
        minlog = log10_dos.min()
    plt.figure('dos')
    plt.plot(energy, log10_dos, styles.dots(method),label=styles.title(method))

    Z = numpy.zeros(len(T_range)) # partition function
    U[method] = numpy.zeros(len(T_range)) # internal energy
    CV[method] = numpy.zeros(len(T_range)) # heat capacity
    S[method] = numpy.zeros(len(T_range)) # entropy

    Z_inf = sum(numpy.exp(ln_dos - ln_dos.max()))
    S_inf = sum(-numpy.exp(ln_dos - ln_dos.max())*(-ln_dos.max() - numpy.log(Z_inf))) / Z_inf

    for i in range(len(T_range)):
        ln_dos_boltz = ln_dos - energy/T_range[i]
        dos_boltz = numpy.exp(ln_dos_boltz - ln_dos_boltz.max())
        Z[i] = sum(dos_boltz)
        U[method][i] = sum(energy*dos_boltz)/Z[i]
        S[method][i] = sum(-dos_boltz*(-energy/T_range[i] - ln_dos_boltz.max() \
コード例 #8
0
ファイル: plot-errors.py プロジェクト: yidapa/deft
            cv_errors[method][n] += dcv
            s_errors[method][n] += ds

        u_errors[method][n] /= len(seeds)
        cv_errors[method][n] /= len(seeds)
        s_errors[method][n] /= len(seeds)

os.chdir(thesis_dir)


### scaling figures
fig_size = (6, 5)

plt.figure(figsize=fig_size)
for method in methods:
    plt.semilogy(Ns, u_errors[method], "." + styles.plot(method), label=styles.title(method))

plt.xlabel("$N$")
plt.ylabel("$\\Delta U/N\epsilon$")
plt.legend(loc="best")
plt.tight_layout(pad=0.2)
plt.savefig("figs/u-scaling.pdf")


plt.figure(figsize=fig_size)
for method in methods:
    plt.semilogy(Ns, cv_errors[method], "." + styles.plot(method), label=styles.title(method))

plt.xlabel("$N$")
plt.ylabel("$\\Delta C_V/N\epsilon$")
plt.legend(loc="best")
コード例 #9
0
    return energy, e_hist, log10w, log10_dos


for method in methods:

    wildfilename = "../data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-%%s.dat" \
                   % (seed, ww, ff, N, method)

    energy, e_hist, log10w, log10_dos = get_arrays(wildfilename)

    if method != 'wang_landau':
        plt.figure('dos-poster')
        plt.plot(energy, log10_dos, styles.dots(method),
                 markerfacecolor='none', markeredgecolor=styles.color(method),
                 label=styles.title(method))

    for ax in [ ax_dos, ax_dos_all ]:
        ax.plot(energy[log10_dos > -cap], log10_dos[log10_dos > -cap],
                styles.dots(method), markerfacecolor='none',
                markeredgecolor=styles.color(method), label=styles.title(method))

    for ax in [ ax_hist, ax_hist_all ]:
        ax.semilogy(energy, e_hist[:,1], styles.dots(method),
                    markerfacecolor='none', markeredgecolor=styles.color(method),
                    label=styles.title(method))

    for ax in [ ax_lnw, ax_lnw_all ]:
        ax.plot(energy[log10w < cap], log10w[log10w < cap], styles.dots(method),
                markerfacecolor='none', markeredgecolor=styles.color(method),
                label=styles.title(method))
コード例 #10
0
ファイル: plot-errors.py プロジェクト: droundy/deft
        golden_u = t_u_cv_s[1]
        reference_error = mean_u_err(ww, ff, N, reference, golden_u)
        if reference_error == None:
            continue
        print '    ', reference, reference_error
        for method in methods:
            plt.figure(2)
            method_err = mean_u_err(ww, ff, N, method, golden_u)
            if method_err != None:
                print '    ', method, method_err
                plt.figure(1)
                if method not in labels_added:
                    plt.loglog(reference_error, method_err, styles.dots(method),
                               markerfacecolor='none', markeredgecolor=styles.color(method),
                               label=styles.title(method))
                    labels_added |= set([method])
                else:
                    plt.loglog(reference_error, method_err, styles.dots(method),
                               markerfacecolor='none', markeredgecolor=styles.color(method))
                plt.figure(2)
        plt.figure(2)
        plt.legend(loc='best')
        plt.savefig(
            'figs/energy-for-debugging-ww%04.2f-ff%04.2f-N%i.pdf' % (ww, ff, N))

min_T = 0.2 # FIXME maybe shouldn't hardcode this?

plt.figure(1)
xmin,xmax = plt.xlim()
ymin,ymax = plt.ylim()
コード例 #11
0
ファイル: plot-histograms.py プロジェクト: yidapa/deft
ww = float(sys.argv[1])
# arg ww = [1.3, 1.5, 2.0, 3.0]

ff = float(sys.argv[2])
# arg ff = [0.1, 0.2, 0.3, 0.4]

N = int(sys.argv[3])
# arg N = range(5,21)+[100, 200, 1000]

methods = eval(sys.argv[4])
# arg methods = [["nw","kT0.4","kT0.5","wang_landau","simple_flat","tmmc","oetmmc"]]

seed = int(sys.argv[5])
# arg seed = [0]

# input: ["data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat" % (seed, ww, ff, N, version) for version in methods]

plt.title("Energy histogram for $\lambda=%g$, $\eta=%g$, and $N=%i$" % (ww, ff, N))

for version in methods:
    data = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat" % (seed, ww, ff, N, version))
    energy = -data[:, 0] / N
    DS = data[:, 1]
    plt.semilogy(energy, DS, styles.dots(version), label=styles.title(version))

plt.xlabel("$U/N\epsilon$")
plt.ylabel("$H$")
plt.legend(loc="best").get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-N%i-E.pdf" % (ww * 100, ff * 100, N))
コード例 #12
0
# input: ["data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-%s.dat" % (seed, ww, ff, N, method, data) for method in methods for data in ["E","lnw"]]

minlog = 0
for method in methods:
    e_hist = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat"
                           % (seed, ww, ff, N, method))
    lnw = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-lnw.dat"
                        % (seed, ww, ff, N, method))
    energy = -e_hist[:, 0]/N
    log10w = lnw[e_hist[:, 0].astype(int), 1]*numpy.log10(numpy.exp(1))
    log10_dos = numpy.log10(e_hist[:, 1]) - log10w
    log10_dos -= log10_dos.max()
    if log10_dos.min() < minlog:
        minlog = log10_dos.min()
    plt.figure('dos')
    plt.plot(energy, log10_dos, styles.dots(method), label=styles.title(method))

    log10w += log10w.min()
    if log10w.min() < minlog:
        minlog = log10w.min()
    plt.figure('w')
    plt.plot(energy, -log10w, styles.dots(method), label=styles.title(method))


def tentothe(n):
    if n == 0:
        return '1'
    if n == 10:
        return '10'
    if int(n) == n:
        return r'$10^{%d}$' % n
コード例 #13
0
ファイル: plot-samples.py プロジェクト: droundy/deft
seed = int(sys.argv[5])
#arg seed = [0]

# input: ["data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-ps.dat" % (seed, ww, ff, N, method) for method in methods]

plt.title('Iterations per sample for $\lambda=%g$, $\eta=%g$, and $N=%i$' % (ww, ff, N))
for method in methods:
    data_file = "data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-ps.dat" \
                % (seed, ww, ff, N, method)
    with open(data_file,'r') as file_handle:
        for line in file_handle:
            entries = line.split()
            if 'iterations:' in entries:
                iterations = int(entries[entries.index('iterations:')+1].replace(',',''))
                continue
    data = numpy.loadtxt(data_file)
    energy = -data[:,0]/N
    round_trips = data[:,1]
    energy = energy[round_trips != 0]
    round_trips = round_trips[round_trips != 0]
    if sum(round_trips) > 0:
        plt.semilogy(energy, iterations/round_trips, styles.dots(method),
                     label=styles.title(method))

plt.xlabel('$U/N\epsilon$')
plt.ylabel('Iterations per sample')
plt.legend(loc='best').get_frame().set_alpha(0.25)
plt.tight_layout(pad=0.2)
plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-N%i-sample-rate.pdf" % (ww*100, ff*100, N))

コード例 #14
0
ファイル: plot-dos.py プロジェクト: droundy/deft
# input: ["data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-%s.dat" % (seed, ww, ff, N, method, data) for method in methods for data in ["E","lnw"]]

minlog = 0
for method in methods:
    e_hist = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-E.dat"
                           % (seed, ww, ff, N, method))
    lnw = numpy.loadtxt("data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-lnw.dat"
                        % (seed, ww, ff, N, method))
    energy = -e_hist[:,0]/N
    log10w = lnw[e_hist[:,0].astype(int),1]*numpy.log10(numpy.exp(1))
    log10_dos = numpy.log10(e_hist[:,1]) - log10w
    log10_dos -= log10_dos.max()
    if log10_dos.min() < minlog:
        minlog = log10_dos.min()
    plt.figure('dos')
    plt.plot(energy, log10_dos, styles.dots(method),label=styles.title(method))

    log10w += log10w.min()
    if log10w.min() < minlog:
        minlog = log10w.min()
    plt.figure('w')
    plt.plot(energy, -log10w, styles.dots(method),label=styles.title(method))


def tentothe(n):
    if n == 0:
        return '1'
    if n == 10:
        return '10'
    if int(n) == n:
        return r'$10^{%d}$' % n
コード例 #15
0
ファイル: plot-uhc.py プロジェクト: yyfdemajia/deft
CV = {}  # heat capacity
S = {}  # entropy

for method in set(methods + [golden]):

    u_cv_s = readandcompute.u_cv_s(ww, ff, N, method)
    if u_cv_s != None:
        U[method] = u_cv_s[0]  # internal energy
        CV[method] = u_cv_s[1]  # heat capacity
        S[method] = u_cv_s[2]  # entropy

    plt.figure('u')
    plt.plot(T_range,
             U[method] / N,
             styles.plot(method),
             label=styles.title(method))

    plt.figure('hc')
    plt.plot(T_range,
             CV[method] / N,
             styles.plot(method),
             label=styles.title(method))

    plt.figure('s')
    plt.plot(T_range,
             S[method] / N,
             styles.plot(method),
             label=styles.title(method))

for method in methods:
コード例 #16
0
ファイル: plot-uhc.py プロジェクト: rscheirer/deft
for method in [golden]+methods:

    U[method] = numpy.zeros(array_len)
    CV[method] = numpy.zeros(array_len)
    S[method] = numpy.zeros(array_len)
    for seed in seeds:
        u_cv_s = readandcompute.u_cv_s(ww, ff, N, method, seed)
        U[method] += u_cv_s[0] # internal energy
        CV[method] += u_cv_s[1] # heat capacity
        S[method] += u_cv_s[2] # entropy
    U[method] /= len(seeds)
    CV[method] /= len(seeds)
    S[method] /= len(seeds)

    plt.figure('u')
    plt.plot(T_range,U[method]/N, styles.plot(method), label=styles.title(method))

    if method != 'wang_landau':
        plt.figure('hc')
        plt.plot(T_range,CV[method]/N, styles.plot(method), label=styles.title(method))

    plt.figure('s')
    plt.plot(T_range,S[method]/N, styles.plot(method), label=styles.title(method))

methods.remove('wang_landau')

for method in methods:

    plt.figure('u_err')
    plt.plot(T_range,(U[method]-U[golden])/N, styles.plot(method),
             label=styles.title(method))
コード例 #17
0
ファイル: plot-uhc.py プロジェクト: yidapa/deft
#methods = eval(sys.argv[4])
methods = ["tmmc", "oetmmc"]
#arg methods = [["tmmc"]]

#seed = int(sys.argv[5])
#arg seed = [0]

# input: ["../data/ww%04.2f-L%04.2f-N%i-%s.dat" % (ww, L, N, data) for data in ["E","lnw"]]

for method in set(methods):

    T, U, CV, S, min_T = readandcompute.T_u_cv_s_minT('../data/ww%04.2f-L%04.2f-N%03d' % (ww, L, N))

    plt.figure('u')
    plt.plot(T,U/N,styles.plot(method),label=styles.title(method))

    plt.figure('hc')
    plt.plot(T,CV/N,styles.plot(method),label=styles.title(method))

    plt.figure('s')
    plt.plot(T,S/N,styles.plot(method),label=styles.title(method))

plt.figure('u')
plt.title('Specific internal energy for $\lambda=%g$, $L=%g$, and $N=%i$' % (ww, L, N))
plt.xlabel('$kT/\epsilon$')
plt.ylabel('$U/N\epsilon$')
plt.legend(loc='best')
plt.axvline(min_T,linewidth=1,color='k',linestyle=':')
plt.tight_layout(pad=0.2)
plt.savefig("ww%02.0f-L%02.0f-N%i-u.pdf" % (ww*100, L, N))