Example #1
0
File: uq.py Project: hajians/UQ
    plt.legend(loc=4, borderaxespad=0.0, prop={'size': 20}, frameon=False)
    plt.tight_layout()
    plt.show(block=True)

    ### instantiate an MCMC sampler
    mcmc = MCMC(density, proposal_density, draw_from_proposal,
                initial_point_mcmc)

    # run the MCMC sample
    mcmc.run(max_iter=10000, burning=1000)
    # write the samples into a file
    #mcmc.write("samples-N3-fric0.075-wNoise.dat")

    # plotting the sampled friction coefficients
    for idx, coef in enumerate(mcmc.density_samples):
        pipe.get_lambda_average(coef)
        plt.plot(pipe.mesh, pipe.lambda_avg)

    pipe_true.get_lambda_average(true_friction)
    plt.plot(pipe_true.mesh,
             pipe_true.lambda_avg,
             '--',
             color="black",
             linewidth=5.0,
             label="True friction function")

    plt.legend(loc=1, borderaxespad=0.0, prop={'size': 20}, frameon=False)
    plt.yticks(fontsize=20)
    plt.xticks(fontsize=20)
    plt.xlabel("$x$", fontsize=24)
    plt.ylabel("$\lambda(x)$", fontsize=24)
Example #2
0
from UQuant.SemilinearSystem import SemiLinSystem

# build a pipe
pipe = SemiLinSystem(1.0, 5.0, 0.0, 1.0, 0.005, 7, 0.05)
# get the info of the pipe
pipe.info()

# check how pressure drop behaves when the friction coefficient is
# updated. Theoretically we have continuous dependence which can
# be seen also numerically.
coef = 0.0
for i in range(0, 100):
    vec_c = [0.05 + coef, 0.01, 0.0, 0.04, 0.0, 0.005, 0.005]
    pipe.run(vec_c)
    pipe.get_lambda_average(vec_c)
    pipe.get_presure_drop(time_instance=13)
    if i % 10 == 1:
        plt.plot(pipe.timeslices,
                 pipe.pressure_drop,
                 "-o",
                 label="cf = " + str(0.05 + coef))
    coef += 0.001

print ">> Computation Done"

plt.legend(loc=2, borderaxespad=0.0)
plt.xticks([round(tn, 2) for tn in pipe.timeslices])
plt.xlabel("$t_n$", fontsize=24)
plt.ylabel("$\delta p_h(t_n)$", fontsize=24)
plt.tight_layout()
Example #3
0
clusters = []
fig = plt.figure(figsize=(10, 5))

show_clusters = range(n_clusters)
n_show_clusters = len(show_clusters)

for idx, cluster in enumerate(show_clusters):

    ax = fig.add_subplot(1, n_show_clusters, idx + 1)

    plt.yticks(fontsize=18)
    plt.xticks(fontsize=18, rotation=25)
    plt.xlabel("$x$", fontsize=24)

    mean_cluster.append(df.iloc[pred == cluster, :].mean().values)
    pipe.get_lambda_average(mean_cluster[idx])
    ax.plot(pipe.mesh,
            pipe.lambda_avg,
            label="$E(\Lambda_" + str(idx + 1) + ")(x)$")

    pipe_true.get_lambda_average(true_friction)
    ax.plot(pipe_true.mesh,
            pipe_true.lambda_avg,
            "--",
            label="$\lambda_{true}(x)$")

    #ax.legend(loc="upper left", prop={'size': 16}, frameon=False)
    ax.set_aspect(aspect=6)
    ax.legend(loc='upper left', bbox_to_anchor=(0.05, 1.275), fontsize=12)

    if cluster != 0:
Example #4
0
    # df = pd.read_csv("tmp.dat", header=None)
    # initial_point_mcmc = df.iloc[-1,0:-1].values
    linestyles = ['-.', '-', '--', ':']
    counter = 0
    plt.style.use('grayscale')

    for i in range(1, len(true_friction) + 1, 2):
        tmp = true_friction[:i]
        pipe_tmp = SemiLinSystem(c_sound, t_final, x_l, x_r, dx, len(tmp),
                                 boundary_eps)

        # get the info of the pipe
        # pipe_tmp.info()

        pipe_tmp.get_lambda_average(tmp)

        #plt.plot(pipe.timeslices, pipe.pressure_drop, "o-")
        if i in [1, 9, 11, 19, 25, 41]:
            plt.plot(pipe_tmp.mesh,
                     pipe_tmp.lambda_avg,
                     linestyle=linestyles[counter % len(linestyles)],
                     label="$N=" + str(i / 2) + "$")
            counter += 1

    plt.legend(loc="best", prop={'size': 16}, frameon=False)
    plt.yticks(fontsize=20)
    plt.xticks(fontsize=20)
    plt.xlabel("$x$", fontsize=24)
    plt.ylabel("$\lambda^N(x)$", fontsize=24)
    plt.tight_layout()
Example #5
0
    plt.plot(prob, label="MCMC samples")
    plt.xlabel("$i$", fontsize=24)
    plt.ylabel("$\propto \pi_y(\lambda_{(i)})$", fontsize=24)
    plt.xticks(append(arange(0, len(prob), 7500), len(prob)),
               rotation=25,
               fontsize=18)
    plt.yticks(fontsize=20)
    plt.tight_layout()
    plt.savefig("results/samples_posterior.pgf")
    plt.show(block=False)

    # plot the mean function, true and the initial sample
    plt.figure()

    for idx in sorted_prob_idx[0:5]:
        pipe.get_lambda_average(df.loc[idx].values)
        plt.plot(pipe.mesh,
                 pipe.lambda_avg,
                 label="$\lambda_{" + str(idx) + "}$")

    # pipe.get_lambda_average(df.mean().values)
    # Mean = pipe.lambda_avg
    # plt.plot(pipe.mesh, Mean, label="$\mathrm{E}(\lambda)(x)$", linewidth=2)

    pipe.get_lambda_average(initial_point_mcmc)
    plt.plot(pipe.mesh,
             pipe.lambda_avg,
             label="$\lambda_{initial}(x)$",
             linestyle="-.",
             linewidth=2)