예제 #1
0
def show_timeorder_info(Dt, mesh_sizes, errors):
    '''Performs consistency check for the given problem/method combination and
    show some information about it. Useful for debugging.
    '''
    # Compute the numerical order of convergence.
    orders = {}
    for key in errors:
        orders[key] = _compute_numerical_order_of_convergence(Dt, errors[key])

    # Print the data to the screen
    for i, mesh_size in enumerate(mesh_sizes):
        print
        print('Mesh size %d:' % mesh_size)
        print('dt = %e' % Dt[0]),
        for label, e in errors.items():
            print('   err_%s = %e' % (label, e[i][0])),
        print
        for j in range(len(Dt) - 1):
            print('                 '),
            for label, o in orders.items():
                print('   ord_%s = %e' % (label, o[i][j])),
            print
            print('dt = %e' % Dt[j+1]),
            for label, e in errors.items():
                print('   err_%s = %e' % (label, e[i][j+1])),
            print

    # Create a figure
    for label, err in errors.items():
        pp.figure()
        ax = pp.axes()
        # Plot the actual data.
        for i, mesh_size in enumerate(mesh_sizes):
            pp.loglog(Dt, err[i], '-o', label=mesh_size)
        # Compare with order curves.
        pp.autoscale(False)
        e0 = err[-1][0]
        for o in range(7):
            pp.loglog([Dt[0], Dt[-1]],
                      [e0, e0 * (Dt[-1] / Dt[0]) ** o],
                      color='0.7')
        pp.xlabel('dt')
        pp.ylabel('||%s-%s_h||' % (label, label))
        # pp.title('Method: %s' % method['name'])
        ppl.legend(ax, loc=4)
    pp.show()
    return
예제 #2
0
# Extract parameters and errors
Sbar = L.params["Sest"].value
r = np.exp([L.params["r" + str(i)].value for i in range(periodicity)])
alphaSbar = L.params["alpha"].value
errup = np.exp(
    np.log(r) +
    [2 * L.params["r" + str(i)].stderr for i in range(periodicity)])
errdn = np.exp(
    np.log(r) -
    [2 * L.params["r" + str(i)].stderr for i in range(periodicity)])

# Plot
subplot(121)
plt.axvline(x=Sbar, color=colours[1], linewidth=3)
plt.axvline(x=1 / zeta, color=colours[2], linewidth=3)
plt.loglog(Svals, l, linewidth=3)
title("Goodness of Fit")
xlabel(r"$\bar{S}$")
ylabel(r"$\chi^2$")
legend([
    r"Profile Likelihood $\bar{S}$ = " + str(int(Sbar)),
    r"Taylor Expansion $\bar{S}$ = " + str(int(1 / zeta))
])

subplot(122)
#plt.plot(rstar, linewidth=2)
plt.plot(r, linewidth=3)
plt.fill_between(range(periodicity), errup, errdn, color=colours[0], alpha=0.3)
plt.plot(rstar * zeta, linewidth=3)
xlim([0, periodicity])
title("Periodicity")
예제 #3
0
r = np.exp([L.params["r" + str(i)].value for i in range(periodicity)])
alphaSbar = L.params["alpha"].value
errup = np.exp(np.log(r) + [2*L.params["r" + str(i)].stderr for i in range(periodicity)])
errdn = np.exp(np.log(r) - [2*L.params["r" + str(i)].stderr for i in range(periodicity)])
    
    
    
    
    


# Plot
subplot(121)
plt.axvline(x=Sbar, color=colours[1], linewidth=3)
plt.axvline(x=1/zeta, color=colours[2], linewidth=3)
plt.loglog(Svals, l, linewidth=3)
title("Goodness of Fit")
xlabel(r"$\bar{S}$")
ylabel(r"$\chi^2$")
legend([r"Profile Likelihood $\bar{S}$ = " + str(int(Sbar)), r"Taylor Expansion $\bar{S}$ = " + str(int(1/zeta))])


subplot(122)
#plt.plot(rstar, linewidth=2)
plt.plot(r, linewidth=3)
plt.fill_between(range(periodicity), errup, errdn, color=colours[0], alpha=0.3)
plt.plot(rstar * zeta, linewidth=3)
xlim([0, periodicity])
title("Periodicity")
xlabel("Period")
legend(["Using Full Equation", "Using Taylor Expansion"])