def make_gp(x, y, z, z_e=None):

    my_cov = RationalQuadratic()

    coords = list(zip(x, y))
    if z_e is None:
        GP = GpRegressor(coords, z, kernel=my_cov)
    else:
        GP = GpRegressor(coords, z, y_err=z_e, kernel=my_cov)

    return GP
ax.plot(q, y_c, lw=2, color='black', label='test function')
ax.plot(x, y, 'o', color='red', label='sampled data')
ax.errorbar(x, y, yerr=errs, fmt='none', ecolor='red')
ax.set_ylim([-0.5, 1.5])
ax.set_xlim([-4, 10])
ax.set_title('Generate simulated data from a test function', fontsize=12)
ax.set_ylabel('function value', fontsize=12)
ax.set_xlabel('spatial coordinate', fontsize=12)
ax.grid()
ax.legend(loc=2, fontsize=12)
plt.tight_layout()
plt.savefig('sampled_data.png')
plt.close()

# initialise the class with the data and errors
GP = GpRegressor(x, y, y_err=errs)

# call the instance to get estimates for the points in q
mu_q, sig_q = GP(q)

# now plot the regression estimate and the data together
c1 = 'red'
c2 = 'blue'
c3 = 'green'
fig = plt.figure(figsize=(9, 6))
ax = fig.add_subplot(111)
ax.plot(q, mu_q, lw=2, color=c2, label='posterior mean')
ax.fill_between(q,
                mu_q - sig_q,
                mu_q - sig_q * 2,
                color=c2,
Example #3
0

# try:
x = list(filtered_data.blanket_breeder_li6_enrichment_fraction)
y = list(filtered_data.fraction_of_breeder_in_breeder_plus_multiplier_volume)
z = list(filtered_data.tbr)
if 'tbr_std_dev' in filtered_data.keys():
    z_e = list(filtered_data.tbr_std_dev)
    labels = [str(i) + '+-' + str(j) for i, j in zip(z, z_e)]
else:
    labels = [str(i) for i in zip(z)]

coords = list(zip(x, y))

# GP = GpRegressor(coords, z, y_err=z_e)
GP = GpRegressor(coords, z)

x_gp = linspace(start=min(x), stop=max(x), num=75)
y_gp = linspace(start=min(y), stop=max(y), num=75)

coords_gp = [(i, j) for i in x_gp for j in y_gp]

gp_mu, gp_sigma = GP(coords_gp)
gp_mu_folded = np.reshape(gp_mu, (len(x_gp), len(y_gp))).T

max_tbr_coords = coords_gp[(np.where(gp_mu == max(gp_mu)))[0][0]]

traces = []
traces.append(
    make_2d_surface_trace(
        gp_mu_folded, x_gp, y_gp,
Example #4
0
ax = fig.add_subplot(111)
ax.plot(q, y_c, lw=2, color='black', label='test function')
ax.plot(x, y, 'o', color='red', label='sampled data')
ax.errorbar(x, y, yerr=errs, fmt='none', ecolor='red')
ax.set_ylim([-0.5, 1.5])
ax.set_xlim([-4, 10])
ax.set_title('Generate simulated data from a test function')
ax.set_ylabel('function value')
ax.set_xlabel('spatial coordinate')
ax.grid()
ax.legend(loc=2)
plt.tight_layout()
plt.show()

# initialise the class with the data and errors
GP = GpRegressor(x, y, y_err=errs)

# call the instance to get estimates for the points in q
mu_q, sig_q = GP(q)

# now plot the regression estimate and the data together
c1 = 'red'
c2 = 'blue'
c3 = 'green'
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(111)
ax.plot(q, mu_q, lw=2, color=c2, label='posterior mean')
ax.fill_between(q,
                mu_q - sig_q,
                mu_q - sig_q * 2,
                color=c2,
x = array(x)

# generate points q at which to evaluate the
# GP regression estimate
Nq = 200
q = linspace(-4, 10, Nq) # cover whole range, including the gap


sig = 0.1 # assumed normal error on the data points
y_c = ( 1. / (1 + exp(-q)) ) + 0.1*sin(2*q) # underlying function
y   = ( 1. / (1 + exp(-x)) ) + 0.1*sin(2*x) + sig*normal(size=len(x)) # sampled y data
errs = zeros(len(y)) + sig # y data errors


# initialise the class with the data and errors
GP = GpRegressor(x, y, y_err = errs)

# call the instance to get estimates for the points in q
mu_q, sig_q = GP(q)

# now plot the regression estimate and the data together
c1 = 'red'; c2 = 'blue'; c3 = 'green'
fig = plt.figure( figsize = (5,4) )
ax = fig.add_subplot(111)
ax.plot(q, mu_q, lw = 2, color = c2, label = 'posterior mean')
ax.fill_between(q, mu_q-sig_q, mu_q-sig_q*2, color = c2, alpha = 0.15, label = r'$\pm 2 \sigma$ interval')
ax.fill_between(q, mu_q+sig_q, mu_q+sig_q*2, color = c2, alpha = 0.15)
ax.fill_between(q, mu_q-sig_q, mu_q+sig_q, color = c2, alpha = 0.4, label = r'$\pm 1 \sigma$ interval')
# ax.plot(x, y, 'o', color = c1, label = 'data', markerfacecolor = 'none', markeredgewidth = 2)
ax.plot(x, y, 'o', color = c1, label = 'data', marker = 'D', ls = 'none', markeredgecolor = 'black')
ax.set_ylim([-0.1, 1.3])
results_df = json_normalize(data=results)
df_filtered_by_mat = results_df

# df_filtered_by_mat = results_df[results_df['fw_material']=='eurofer'&&results_df['armour_material']=='tungsten']

x = list(df_filtered_by_mat['fw_thickness'])
y = list(df_filtered_by_mat['armour_thickness'])
z = list(df_filtered_by_mat['leakage_neutron_current.value'])
z_e = list(df_filtered_by_mat['leakage_neutron_current.std_dev'])
labels = [str(i) + '+-' + str(j) for i, j in zip(z, z_e)]

if len(x) < 40:

    coords = list(zip(x, y))

    GP = GpRegressor(coords, z, y_err=z_e)

    x_gp = linspace(start=min(x), stop=max(x), num=len(x) * 0.5)
    y_gp = linspace(start=min(y), stop=max(y), num=len(y) * 0.5)

    coords_gp = [(i, j) for i in x_gp for j in y_gp]

    gp_mu, gp_sigma = GP(coords_gp)
    gp_mu_folded = np.reshape(gp_mu, (len(x_gp), len(y_gp))).T

    traces = []
    traces.append(
        make_2d_surface_trace(
            gp_mu_folded, x_gp, y_gp,
            'Neutron Leakage Current (Particle/Source Particle)'))
    traces.append(make_2d_scatter_trace(x, y, z, labels))